Commit 99f99575 authored by Douwe Maan's avatar Douwe Maan

Use `group_member` instead of `users_group` or `membership`.

parent 60df262c
......@@ -18,10 +18,10 @@ class Groups::GroupMembersController < Groups::ApplicationController
end
def destroy
@users_group = @group.group_members.find(params[:id])
@group_member = @group.group_members.find(params[:id])
if can?(current_user, :destroy, @users_group) # May fail if last owner.
@users_group.destroy
if can?(current_user, :destroy_group_member, @group_member) # May fail if last owner.
@group_member.destroy
respond_to do |format|
format.html { redirect_to members_group_path(@group), notice: 'User was successfully removed from group.' }
format.js { render nothing: true }
......
......@@ -14,9 +14,9 @@ class Profiles::NotificationsController < ApplicationController
@saved = if type == 'global'
current_user.update_attributes(user_params)
elsif type == 'group'
users_group = current_user.group_members.find(params[:notification_id])
users_group.notification_level = params[:notification_level]
users_group.save
group_member = current_user.group_members.find(params[:notification_id])
group_member.notification_level = params[:notification_level]
group_member.save
else
project_member = current_user.project_members.find(params[:notification_id])
project_member.notification_level = params[:notification_level]
......
module Emails
module Groups
def group_access_granted_email(user_group_id)
@membership = GroupMember.find(user_group_id)
@group = @membership.group
def group_access_granted_email(group_member_id)
@group_member = GroupMember.find(group_member_id)
@group = @group_member.group
@target_url = group_url(@group)
mail(to: @membership.user.email,
mail(to: @group_member.user.email,
subject: subject("Access to group was granted"))
end
end
......
......@@ -14,7 +14,7 @@ class Ability
when "MergeRequest" then merge_request_abilities(user, subject)
when "Group" then group_abilities(user, subject)
when "Namespace" then namespace_abilities(user, subject)
when "GroupMember" then users_group_abilities(user, subject)
when "GroupMember" then group_member_abilities(user, subject)
else []
end.concat(global_abilities(user))
end
......@@ -248,17 +248,17 @@ class Ability
end
end
def users_group_abilities(user, subject)
def group_member_abilities(user, subject)
rules = []
target_user = subject.user
group = subject.group
can_manage = group_abilities(user, group).include?(:manage_group)
if can_manage && (user != target_user)
rules << :modify
rules << :destroy
rules << :modify_group_member
rules << :destroy_group_member
end
if !group.last_owner?(user) && (can_manage || (user == target_user))
rules << :destroy
rules << :destroy_group_member
end
rules
end
......
......@@ -194,11 +194,11 @@ class NotificationService
project_members = project_member_notification(project)
users_with_project_level_global = project_member_notification(project, Notification::N_GLOBAL)
users_with_group_level_global = users_group_notification(project, Notification::N_GLOBAL)
users_with_group_level_global = group_member_notification(project, Notification::N_GLOBAL)
users = users_with_global_level_watch([users_with_project_level_global, users_with_group_level_global].flatten.uniq)
users_with_project_setting = select_project_member_setting(project, users_with_project_level_global, users)
users_with_group_setting = select_users_group_setting(project, project_members, users_with_group_level_global, users)
users_with_group_setting = select_group_member_setting(project, project_members, users_with_group_level_global, users)
User.where(id: users_with_project_setting.concat(users_with_group_setting).uniq).to_a
end
......@@ -213,7 +213,7 @@ class NotificationService
end
end
def users_group_notification(project, notification_level)
def group_member_notification(project, notification_level)
if project.group
project.group.group_members.where(notification_level: notification_level).pluck(:user_id)
else
......@@ -243,8 +243,8 @@ class NotificationService
end
# Build a list of users based on group notification settings
def select_users_group_setting(project, project_members, global_setting, users_global_level_watch)
uids = users_group_notification(project, Notification::N_WATCH)
def select_group_member_setting(project, project_members, global_setting, users_global_level_watch)
uids = group_member_notification(project, Notification::N_WATCH)
# Group setting is watch, add to users list if user is not project member
users = []
......
......@@ -174,15 +174,15 @@
.panel.panel-default
.panel-heading Groups:
%ul.well-list
- @user.group_members.each do |user_group|
- group = user_group.group
- @user.group_members.each do |group_member|
- group = group_member.group
%li.group_member
%span{class: ("list-item-name" unless user_group.owner?)}
%span{class: ("list-item-name" unless group_member.owner?)}
%strong= link_to group.name, admin_group_path(group)
.pull-right
%span.light= user_group.human_access
- unless user_group.owner?
= link_to group_group_member_path(group, user_group), data: { confirm: remove_user_from_group_message(group, @user) }, method: :delete, remote: true, class: "btn-xs btn btn-remove", title: 'Remove user from group' do
%span.light= group_member.human_access
- unless group_member.owner?
= link_to group_group_member_path(group, group_member), data: { confirm: remove_user_from_group_message(group, @user) }, method: :delete, remote: true, class: "btn-xs btn btn-remove", title: 'Remove user from group' do
%i.fa.fa-times.fa-inverse
- else
.nothing-here-block This user has no groups.
......@@ -207,21 +207,21 @@
.panel-heading Joined projects (#{@joined_projects.count})
%ul.well-list
- @joined_projects.sort_by(&:name_with_namespace).each do |project|
- tm = project.team.find_tm(@user.id)
- member = project.team.find_member(@user.id)
%li.project_member
.list-item-name
= link_to admin_namespace_project_path(project.namespace, project), class: dom_class(project) do
= project.name_with_namespace
- if tm
- if member
.pull-right
- if tm.owner?
- if member.owner?
%span.light Owner
- else
%span.light= tm.human_access
%span.light= member.human_access
- if tm.respond_to? :project
= link_to namespace_project_team_member_path(project.namespace, project, @user), data: { confirm: remove_from_project_team_message(project, @user) }, remote: true, method: :delete, class: "btn-xs btn btn-remove", title: 'Remove user from project' do
- if member.respond_to? :project
= link_to namespace_project_project_member_path(project.namespace, project, @user), data: { confirm: remove_from_project_team_message(project, @user) }, remote: true, method: :delete, class: "btn-xs btn btn-remove", title: 'Remove user from project' do
%i.fa.fa-times
#ssh-keys.tab-pane
= render 'profiles/keys/key_table', admin: true
......@@ -11,10 +11,10 @@
.panel.panel-default
.panel-heading
%strong Groups
(#{@user_groups.count})
(#{@group_members.count})
%ul.well-list
- @user_groups.each do |user_group|
- group = user_group.group
- @group_members.each do |group_member|
- group = group_member.group
%li
.pull-right
- if can?(current_user, :manage_group, group)
......@@ -22,7 +22,7 @@
%i.fa.fa-cogs
Settings
- if can?(current_user, :destroy, user_group)
- if can?(current_user, :destroy_group_member, group_member)
= link_to leave_dashboard_group_path(group), data: { confirm: leave_group_message(group.name) }, method: :delete, class: "btn-sm btn btn-grouped", title: 'Remove user from group' do
%i.fa.fa-sign-out
Leave
......@@ -32,9 +32,9 @@
%strong= group.name
as
%strong #{user_group.human_access}
%strong #{group_member.human_access}
%div.light
#{pluralize(group.projects.count, "project")}, #{pluralize(group.users.count, "user")}
= paginate @user_groups
= paginate @group_members
......@@ -16,11 +16,11 @@
%span.pull-right
%strong= member.human_access
- if show_controls
- if can?(current_user, :modify, member)
- if can?(current_user, :modify_group_member, member)
= button_tag class: "btn-xs btn js-toggle-button",
title: 'Edit access level', type: 'button' do
%i.fa.fa-pencil-square-o
- if can?(current_user, :destroy, member)
- if can?(current_user, :destroy_group_member, member)
- if current_user == member.user
= link_to leave_dashboard_group_path(@group), data: { confirm: leave_group_message(@group.name)}, method: :delete, class: "btn-xs btn btn-remove", title: 'Remove user from group' do
%i.fa.fa-minus.fa-inverse
......
%p
= "You have been granted #{@membership.human_access} access to group"
= "You have been granted #{@group_member.human_access} access to group"
= link_to group_url(@group) do
= @group.name
You have been granted <%= @membership.human_access %> access to group <%= @group.name %>
You have been granted <%= @group_member.human_access %> access to group <%= @group.name %>
<%= url_for(group_url(@group)) %>
......@@ -62,9 +62,9 @@
By default, all projects and groups will use the notification level set above.
%h4 Groups:
%ul.bordered-list
- @group_members.each do |users_group|
- notification = Notification.new(users_group)
= render 'settings', type: 'group', membership: users_group, notification: notification
- @group_members.each do |group_member|
- notification = Notification.new(group_member)
= render 'settings', type: 'group', membership: group_member, notification: notification
.col-md-6
%p
......
......@@ -53,14 +53,14 @@ module API
authorize! :manage_group, group
required_attributes! [:access_level]
team_member = group.group_members.find_by(user_id: params[:user_id])
not_found!('User can not be found') if team_member.nil?
group_member = group.group_members.find_by(user_id: params[:user_id])
not_found!('User can not be found') if group_member.nil?
if team_member.update_attributes(access_level: params[:access_level])
@member = team_member.user
if group_member.update_attributes(access_level: params[:access_level])
@member = group_member.user
present @member, with: Entities::GroupMember, group: group
else
handle_member_errors team_member.errors
handle_member_errors group_member.errors
end
end
......
......@@ -28,18 +28,18 @@ describe GroupMember do
describe "#after_update" do
before do
@membership = create :group_member
@membership.stub(notification_service: double('NotificationService').as_null_object)
@group_member = create :group_member
@group_member.stub(notification_service: double('NotificationService').as_null_object)
end
it "should send email to user" do
expect(@membership).to receive(:notification_service)
@membership.update_attribute(:access_level, GroupMember::MASTER)
expect(@group_member).to receive(:notification_service)
@group_member.update_attribute(:access_level, GroupMember::MASTER)
end
it "does not send an email when the access level has not changed" do
expect(@membership).not_to receive(:notification_service)
@membership.update_attribute(:access_level, GroupMember::OWNER)
expect(@group_member).not_to receive(:notification_service)
@group_member.update_attribute(:access_level, GroupMember::OWNER)
end
end
end
......
......@@ -69,9 +69,9 @@ describe NotificationService do
user_project = note.project.project_members.find_by_user_id(@u_watcher.id)
user_project.notification_level = Notification::N_PARTICIPATING
user_project.save
user_group = note.project.group.group_members.find_by_user_id(@u_watcher.id)
user_group.notification_level = Notification::N_GLOBAL
user_group.save
group_member = note.project.group.group_members.find_by_user_id(@u_watcher.id)
group_member.notification_level = Notification::N_GLOBAL
group_member.save
end
it do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment