Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Rydkin <maks.rydkin@gmail.com>2017-09-08 12:00:31 +0300
committerMaxim Rydkin <maks.rydkin@gmail.com>2017-09-10 18:31:06 +0300
commitfa276e30292349173e98f7fe0f9a94c82345dc7a (patch)
tree223b287f7e35fcda434224f4143e738866af85ff /app/finders
parent20ff87a261ac0ea06268d2cb7223f104baf2ed35 (diff)
move `find_users` method into finder and add `load_group` method
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/autocomplete_users_finder.rb28
1 files changed, 23 insertions, 5 deletions
diff --git a/app/finders/autocomplete_users_finder.rb b/app/finders/autocomplete_users_finder.rb
index f88e94b70b7..b8f52e31926 100644
--- a/app/finders/autocomplete_users_finder.rb
+++ b/app/finders/autocomplete_users_finder.rb
@@ -1,10 +1,11 @@
class AutocompleteUsersFinder
- attr_reader :current_user, :users, :search, :skip_users, :page,
- :per_page, :author_id, :params
+ attr_reader :current_user, :project, :group, :search, :skip_users,
+ :page, :per_page, :author_id, :params
- def initialize(params:, current_user:, users: nil)
+ def initialize(params:, current_user:, project:, group:)
@current_user = current_user
- @users = users
+ @project = project
+ @group = group
@search = params[:search]
@skip_users = params[:skip_users]
@page = params[:page]
@@ -14,7 +15,7 @@ class AutocompleteUsersFinder
end
def execute
- items = users || User.none
+ items = find_users
items = items.active
items = items.reorder(:name)
items = items.search(search) if search.present?
@@ -39,4 +40,21 @@ class AutocompleteUsersFinder
items
end
+
+ private
+
+ def find_users
+ return users_from_project if project
+ return group.users if group
+ return User.all if current_user
+
+ User.none
+ end
+
+ def users_from_project
+ user_ids = project.team.users.pluck(:id)
+ user_ids << author_id if author_id.present?
+
+ User.where(id: user_ids)
+ end
end