diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-13 18:08:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-13 18:08:02 +0300 |
commit | 4eeb6b0d16021ab4a730eec4610eff2606421147 (patch) | |
tree | 488db828fe58f1e80dc5415970e4c929db7e4c4b /app | |
parent | 8cc5f2790908ba9bb8eecba2b78a3c5a88c77b90 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/concerns/membership_actions.rb | 11 | ||||
-rw-r--r-- | app/controllers/groups/group_members_controller.rb | 9 | ||||
-rw-r--r-- | app/controllers/projects/project_members_controller.rb | 2 | ||||
-rw-r--r-- | app/finders/group_members_finder.rb | 10 | ||||
-rw-r--r-- | app/finders/members_finder.rb | 20 | ||||
-rw-r--r-- | app/views/shared/members/_sort_dropdown.html.haml | 10 |
6 files changed, 47 insertions, 15 deletions
diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb index 0b2756c0c6a..993f091b0e6 100644 --- a/app/controllers/concerns/membership_actions.rb +++ b/app/controllers/concerns/membership_actions.rb @@ -144,4 +144,15 @@ module MembershipActions end end end + + def requested_relations + case params[:with_inherited_permissions].presence + when 'exclude' + [:direct] + when 'only' + [:inherited] + else + [:inherited, :direct] + end + end end diff --git a/app/controllers/groups/group_members_controller.rb b/app/controllers/groups/group_members_controller.rb index 1b1416a72d7..dcdf9aced1a 100644 --- a/app/controllers/groups/group_members_controller.rb +++ b/app/controllers/groups/group_members_controller.rb @@ -24,8 +24,7 @@ class Groups::GroupMembersController < Groups::ApplicationController @sort = params[:sort].presence || sort_value_name @project = @group.projects.find(params[:project_id]) if params[:project_id] - - @members = GroupMembersFinder.new(@group).execute + @members = find_members if can_manage_members @invited_members = @members.invite @@ -52,6 +51,12 @@ class Groups::GroupMembersController < Groups::ApplicationController # MembershipActions concern alias_method :membershipable, :group + + private + + def find_members + GroupMembersFinder.new(@group).execute(include_relations: requested_relations) + end end Groups::GroupMembersController.prepend_if_ee('EE::Groups::GroupMembersController') diff --git a/app/controllers/projects/project_members_controller.rb b/app/controllers/projects/project_members_controller.rb index b01d48ca3d3..7bd084458d1 100644 --- a/app/controllers/projects/project_members_controller.rb +++ b/app/controllers/projects/project_members_controller.rb @@ -17,7 +17,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController @skip_groups << @project.namespace_id unless @project.personal? @skip_groups += @project.group.ancestors.pluck(:id) if @project.group - @project_members = MembersFinder.new(@project, current_user).execute + @project_members = MembersFinder.new(@project, current_user).execute(include_relations: requested_relations) if params[:search].present? @project_members = @project_members.joins(:user).merge(User.search(params[:search])) diff --git a/app/finders/group_members_finder.rb b/app/finders/group_members_finder.rb index 165d9adae31..d8739c350e4 100644 --- a/app/finders/group_members_finder.rb +++ b/app/finders/group_members_finder.rb @@ -6,15 +6,15 @@ class GroupMembersFinder < UnionFinder end # rubocop: disable CodeReuse/ActiveRecord - def execute(include_descendants: false) + def execute(include_relations: [:inherited, :direct]) group_members = @group.members relations = [] - return group_members unless @group.parent || include_descendants + return group_members if include_relations == [:direct] - relations << group_members + relations << group_members if include_relations.include?(:direct) - if @group.parent + if include_relations.include?(:inherited) && @group.parent parents_members = GroupMember.non_request .where(source_id: @group.ancestors.select(:id)) .where.not(user_id: @group.users.select(:id)) @@ -22,7 +22,7 @@ class GroupMembersFinder < UnionFinder relations << parents_members end - if include_descendants + if include_relations.include?(:descendants) descendant_members = GroupMember.non_request .where(source_id: @group.descendants.select(:id)) .where.not(user_id: @group.users.select(:id)) diff --git a/app/finders/members_finder.rb b/app/finders/members_finder.rb index e8c7f9622a9..a919ff5bf8a 100644 --- a/app/finders/members_finder.rb +++ b/app/finders/members_finder.rb @@ -9,14 +9,18 @@ class MembersFinder @group = project.group end - def execute(include_descendants: false, include_invited_groups_members: false) + def execute(include_relations: [:inherited, :direct]) project_members = project.project_members project_members = project_members.non_invite unless can?(current_user, :admin_project, project) - union_members = group_union_members(include_descendants, include_invited_groups_members) + return project_members if include_relations == [:direct] + + union_members = group_union_members(include_relations) + + union_members << project_members if include_relations.include?(:direct) if union_members.any? - distinct_union_of_members(union_members << project_members) + distinct_union_of_members(union_members) else project_members end @@ -28,15 +32,17 @@ class MembersFinder private - def group_union_members(include_descendants, include_invited_groups_members) + def group_union_members(include_relations) [].tap do |members| - members << direct_group_members(include_descendants) if group - members << project_invited_groups_members if include_invited_groups_members + members << direct_group_members(include_relations.include?(:descendants)) if group + members << project_invited_groups_members if include_relations.include?(:invited_groups_members) end end def direct_group_members(include_descendants) - GroupMembersFinder.new(group).execute(include_descendants: include_descendants).non_invite # rubocop: disable CodeReuse/Finder + requested_relations = [:inherited, :direct] + requested_relations << :descendants if include_descendants + GroupMembersFinder.new(group).execute(include_relations: requested_relations).non_invite # rubocop: disable CodeReuse/Finder end def project_invited_groups_members diff --git a/app/views/shared/members/_sort_dropdown.html.haml b/app/views/shared/members/_sort_dropdown.html.haml index 5f3d49adff7..50a55565c3c 100644 --- a/app/views/shared/members/_sort_dropdown.html.haml +++ b/app/views/shared/members/_sort_dropdown.html.haml @@ -8,3 +8,13 @@ %li = link_to filter_group_project_member_path(sort: value), class: ("is-active" if @sort == value) do = title + %li.divider + %li{ data: { 'qa-selector': 'filter-members-with-inherited-permissions' } } + = link_to filter_group_project_member_path(with_inherited_permissions: nil), class: ("is-active" unless params[:with_inherited_permissions].present?) do + = _("Show all members") + %li{ data: { 'qa-selector': 'filter-members-with-inherited-permissions' } } + = link_to filter_group_project_member_path(with_inherited_permissions: 'exclude'), class: ("is-active" if params[:with_inherited_permissions] == 'exclude') do + = _("Show only direct members") + %li{ data: { 'qa-selector': 'filter-members-with-inherited-permissions' } } + = link_to filter_group_project_member_path(with_inherited_permissions: 'only'), class: ("is-active" if params[:with_inherited_permissions] == 'only') do + = _("Show only inherited members") |