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-08-23 22:33:56 +0300
committerMaxim Rydkin <maks.rydkin@gmail.com>2017-09-10 18:31:05 +0300
commitfbbb985a03d0b51e28a3df5a3c3f21a81540405f (patch)
tree4eeb1f2e52ae82c5917ab1cf340a493200e5e50d /app/finders
parent5d952f756bcf0355fc5d86d819dfc6913c0ae351 (diff)
extract finder and add first test
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/yet_another_users_finder.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/finders/yet_another_users_finder.rb b/app/finders/yet_another_users_finder.rb
new file mode 100644
index 00000000000..5f7f3913160
--- /dev/null
+++ b/app/finders/yet_another_users_finder.rb
@@ -0,0 +1,42 @@
+class YetAnotherUsersFinder
+ attr_reader :current_user, :users, :search, :skip_users, :page,
+ :per_page, :author_id, :params
+
+ def initialize(params:, current_user:, users: nil)
+ @current_user = current_user
+ @users = users
+ @search = params[:search]
+ @skip_users = params[:skip_users]
+ @page = params[:page]
+ @per_page = params[:per_page]
+ @author_id = params[:author_id]
+ @params = params
+ end
+
+ def execute
+ items = users || User.none
+ items = items.active
+ items = items.reorder(:name)
+ items = items.search(search) if search.present?
+ items = items.where.not(id: skip_users) if skip_users.present?
+ items = items.page(page).per(per_page)
+
+ if params[:todo_filter].present? && current_user
+ items = items.todo_authors(current_user.id, params[:todo_state_filter])
+ end
+
+ if search.blank?
+ # Include current user if available to filter by "Me"
+ if params[:current_user].present? && current_user
+ items = [current_user, *items].uniq
+ end
+
+ if author_id.present? && current_user
+ author = User.find_by_id(author_id)
+ items = [author, *items].uniq if author
+ end
+ end
+
+ items
+ end
+end