summaryrefslogtreecommitdiff
path: root/app/finders
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-10-04 13:41:48 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-10-04 13:41:48 +0000
commit7876a7397d6ebcef35cbf2a9f92c5a50e492369c (patch)
tree4b83be10dedd78de9e9496354b091481235167b3 /app/finders
parenteac20b74a7e92c34a42fe0658b745521cf2e862f (diff)
parent9d476b11426ca757114e85343f548ab3ed15beeb (diff)
downloadgitlab-ce-7876a7397d6ebcef35cbf2a9f92c5a50e492369c.tar.gz
Merge branch 'dz-labels-subscribe-filter' into 'master'
Add subscribe filter to labels page See merge request gitlab-org/gitlab-ce!21965
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/group_labels_finder.rb16
-rw-r--r--app/finders/labels_finder.rb13
2 files changed, 27 insertions, 2 deletions
diff --git a/app/finders/group_labels_finder.rb b/app/finders/group_labels_finder.rb
index 903023033ed..a668a0f0fae 100644
--- a/app/finders/group_labels_finder.rb
+++ b/app/finders/group_labels_finder.rb
@@ -1,17 +1,29 @@
# frozen_string_literal: true
class GroupLabelsFinder
- attr_reader :group, :params
+ attr_reader :current_user, :group, :params
- def initialize(group, params = {})
+ def initialize(current_user, group, params = {})
+ @current_user = current_user
@group = group
@params = params
end
def execute
group.labels
+ .optionally_subscribed_by(subscriber_id)
.optionally_search(params[:search])
.order_by(params[:sort])
.page(params[:page])
end
+
+ private
+
+ def subscriber_id
+ current_user&.id if subscribed?
+ end
+
+ def subscribed?
+ params[:subscribed] == 'true'
+ end
end
diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb
index 08fc2968e77..82e0b2ed9e1 100644
--- a/app/finders/labels_finder.rb
+++ b/app/finders/labels_finder.rb
@@ -17,6 +17,7 @@ class LabelsFinder < UnionFinder
@skip_authorization = skip_authorization
items = find_union(label_ids, Label) || Label.none
items = with_title(items)
+ items = by_subscription(items)
items = by_search(items)
sort(items)
end
@@ -84,6 +85,18 @@ class LabelsFinder < UnionFinder
labels.search(params[:search])
end
+ def by_subscription(labels)
+ labels.optionally_subscribed_by(subscriber_id)
+ end
+
+ def subscriber_id
+ current_user&.id if subscribed?
+ end
+
+ def subscribed?
+ params[:subscribed] == 'true'
+ end
+
# Gets redacted array of group ids
# which can include the ancestors and descendants of the requested group.
def group_ids_for(group)