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