diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-31 12:08:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-31 12:08:33 +0000 |
commit | 1808454313ed75c92e1384466e8c83bfbc8ae25e (patch) | |
tree | 5c006c158fd796dc6d21e9bd771542f2fb0c24e2 /app/finders | |
parent | fd3a95f07ae9cd78fecffcfa5de4494f933a7808 (diff) | |
download | gitlab-ce-1808454313ed75c92e1384466e8c83bfbc8ae25e.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/members_finder.rb | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/app/finders/members_finder.rb b/app/finders/members_finder.rb index a919ff5bf8a..0617f34dc8c 100644 --- a/app/finders/members_finder.rb +++ b/app/finders/members_finder.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true class MembersFinder - attr_reader :project, :current_user, :group + # Params can be any of the following: + # sort: string + # search: string def initialize(project, current_user) @project = project @@ -9,28 +11,39 @@ class MembersFinder @group = project.group end - def execute(include_relations: [:inherited, :direct]) + def execute(include_relations: [:inherited, :direct], params: {}) + members = find_members(include_relations, params) + + filter_members(members, params) + end + + def can?(*args) + Ability.allowed?(*args) + end + + private + + attr_reader :project, :current_user, :group + + def find_members(include_relations, params) project_members = project.project_members project_members = project_members.non_invite unless can?(current_user, :admin_project, project) 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) - else - project_members - end - end + return project_members unless union_members.any? - def can?(*args) - Ability.allowed?(*args) + distinct_union_of_members(union_members) end - private + def filter_members(members, params) + members = members.search(params[:search]) if params[:search].present? + members = members.sort_by_attribute(params[:sort]) if params[:sort].present? + members + end def group_union_members(include_relations) [].tap do |members| |