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
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-10-26 13:42:41 +0300
committerSean McGivern <sean@mcgivern.me.uk>2018-10-26 13:42:41 +0300
commit8325a1fc9f0b2c9cea9073d4377f2b3b35771e8b (patch)
tree9ea5433076dd1576d867babbe33e7f648a087b58 /app
parentc10c553e1db344f0cd65454373c63af0a5cb58f0 (diff)
parente0f0c29b0cfe3c0c97191eeb96eae1299f3983d1 (diff)
Merge branch '52384-api-filter-assignee-none-any' into 'master'
Resolve "Filter by `None`/`Any` for assignee_id in issues/mrs API" Closes #52384 See merge request gitlab-org/gitlab-ce!22598
Diffstat (limited to 'app')
-rw-r--r--app/finders/issuable_finder.rb35
-rw-r--r--app/finders/issues_finder.rb8
2 files changed, 28 insertions, 15 deletions
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb
index 8abfe0c4c17..eb3d2498830 100644
--- a/app/finders/issuable_finder.rb
+++ b/app/finders/issuable_finder.rb
@@ -14,7 +14,7 @@
# project_id: integer
# milestone_title: string
# author_id: integer
-# assignee_id: integer
+# assignee_id: integer or 'None' or 'Any'
# search: string
# label_name: string
# sort: string
@@ -34,6 +34,11 @@ class IssuableFinder
requires_cross_project_access unless: -> { project? }
+ # This is used as a common filter for None / Any
+ FILTER_NONE = 'none'.freeze
+ FILTER_ANY = 'any'.freeze
+
+ # This is accepted as a deprecated filter and is also used in unassigning users
NONE = '0'.freeze
attr_accessor :current_user, :params
@@ -236,16 +241,20 @@ class IssuableFinder
# rubocop: enable CodeReuse/ActiveRecord
def assignee_id?
- params[:assignee_id].present? && params[:assignee_id].to_s != NONE
+ params[:assignee_id].present?
end
def assignee_username?
- params[:assignee_username].present? && params[:assignee_username].to_s != NONE
+ params[:assignee_username].present?
end
- def no_assignee?
+ def filter_by_no_assignee?
# Assignee_id takes precedence over assignee_username
- params[:assignee_id].to_s == NONE || params[:assignee_username].to_s == NONE
+ [NONE, FILTER_NONE].include?(params[:assignee_id].to_s.downcase) || params[:assignee_username].to_s == NONE
+ end
+
+ def filter_by_any_assignee?
+ params[:assignee_id].to_s.downcase == FILTER_ANY
end
# rubocop: disable CodeReuse/ActiveRecord
@@ -399,15 +408,17 @@ class IssuableFinder
# rubocop: disable CodeReuse/ActiveRecord
def by_assignee(items)
- if assignee
- items = items.where(assignee_id: assignee.id)
- elsif no_assignee?
- items = items.where(assignee_id: nil)
+ if filter_by_no_assignee?
+ items.where(assignee_id: nil)
+ elsif filter_by_any_assignee?
+ items.where('assignee_id IS NOT NULL')
+ elsif assignee
+ items.where(assignee_id: assignee.id)
elsif assignee_id? || assignee_username? # assignee not found
- items = items.none
+ items.none
+ else
+ items
end
-
- items
end
# rubocop: enable CodeReuse/ActiveRecord
diff --git a/app/finders/issues_finder.rb b/app/finders/issues_finder.rb
index abdc47b9866..cee57a83df4 100644
--- a/app/finders/issues_finder.rb
+++ b/app/finders/issues_finder.rb
@@ -137,10 +137,12 @@ class IssuesFinder < IssuableFinder
# rubocop: disable CodeReuse/ActiveRecord
def by_assignee(items)
- if assignee
- items.assigned_to(assignee)
- elsif no_assignee?
+ if filter_by_no_assignee?
items.unassigned
+ elsif filter_by_any_assignee?
+ items.assigned
+ elsif assignee
+ items.assigned_to(assignee)
elsif assignee_id? || assignee_username? # assignee not found
items.none
else