diff options
author | Jacopo <beschi.jacopo@gmail.com> | 2018-10-29 10:50:18 +0100 |
---|---|---|
committer | Jacopo <beschi.jacopo@gmail.com> | 2018-11-23 16:11:52 +0100 |
commit | c068ac67b3e40fdc039c80372306f9cc3360d594 (patch) | |
tree | d707871f8b7f5deb7f62d7630f317e94946eb1cc /app | |
parent | f0630090aaea98daef3582bc95efe3a43736a10f (diff) | |
download | gitlab-ce-c068ac67b3e40fdc039c80372306f9cc3360d594.tar.gz |
Filter by `None`/`Any` for labels in issues/mrs API
By using the parameters `?labels=None|Any` the user can filter
issues/mrs from the API that has `none/any` label.
Affected endpoints are:
- /api/issues
- /api/projects/:id/issues
- /api/groups/:id/issues
- /api/merge_requests
- /api/projects/:id/merge_requests
- /api/groups/:id/merge_requests
Diffstat (limited to 'app')
-rw-r--r-- | app/finders/issuable_finder.rb | 11 | ||||
-rw-r--r-- | app/models/concerns/issuable.rb | 1 | ||||
-rw-r--r-- | app/models/label.rb | 9 |
3 files changed, 13 insertions, 8 deletions
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index fdc630cbf72..e04e3a2a7e0 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -210,7 +210,14 @@ class IssuableFinder end def filter_by_no_label? - labels? && params[:label_name].include?(Label::None.title) + downcased = label_names.map(&:downcase) + + # Label::NONE is deprecated and should be removed in 12.0 + downcased.include?(FILTER_NONE) || downcased.include?(Label::NONE) + end + + def filter_by_any_label? + label_names.map(&:downcase).include?(FILTER_ANY) end def labels @@ -465,6 +472,8 @@ class IssuableFinder items = if filter_by_no_label? items.without_label + elsif filter_by_any_label? + items.any_label else items.with_label(label_names, params[:sort]) end diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 69c5affe142..5080fe03cc8 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -90,6 +90,7 @@ module Issuable scope :order_milestone_due_asc, -> { left_joins_milestones.reorder('milestones.due_date IS NULL, milestones.id IS NULL, milestones.due_date ASC') } scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) } + scope :any_label, -> { joins(:label_links).group(:id) } scope :join_project, -> { joins(:project) } scope :inc_notes_with_associations, -> { includes(notes: [:project, :author, :award_emoji]) } scope :references_project, -> { references(:project) } diff --git a/app/models/label.rb b/app/models/label.rb index 165e4a8f3e5..5d2d1afd1d9 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -9,15 +9,10 @@ class Label < ActiveRecord::Base include Sortable include FromUnion - # Represents a "No Label" state used for filtering Issues and Merge - # Requests that have no label assigned. - LabelStruct = Struct.new(:title, :name) - None = LabelStruct.new('No Label', 'No Label') - Any = LabelStruct.new('Any Label', '') - cache_markdown_field :description, pipeline: :single_line - DEFAULT_COLOR = '#428BCA'.freeze + DEFAULT_COLOR = '#428BCA' + NONE = 'no label' default_value_for :color, DEFAULT_COLOR |