diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-02-26 19:23:19 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-26 19:23:19 +0300 |
commit | 07a227a3200ee563132ffd385c0e2a3f57ec043d (patch) | |
tree | 23d6ee461779098cb9141108bfb0658118cd040b /app/finders/labels_finder.rb | |
parent | 3d493cee077d7bf5591c311042ad03c08094effb (diff) |
Allow to find labels in ancestor groups and better group support in label service
Diffstat (limited to 'app/finders/labels_finder.rb')
-rw-r--r-- | app/finders/labels_finder.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb index f013e177c5b..5c9fce211ec 100644 --- a/app/finders/labels_finder.rb +++ b/app/finders/labels_finder.rb @@ -39,7 +39,7 @@ class LabelsFinder < UnionFinder end end elsif only_group_labels? - label_ids << Label.where(group_id: group.id) + label_ids << Label.where(group_id: group_ids) else label_ids << Label.where(group_id: projects.group_ids) label_ids << Label.where(project_id: projects.select(:id)) @@ -59,10 +59,11 @@ class LabelsFinder < UnionFinder items.where(title: title) end - def group - strong_memoize(:group) do + def group_ids + strong_memoize(:group_ids) do group = Group.find(params[:group_id]) - authorized_to_read_labels?(group) && group + groups = params[:include_ancestor_groups].present? ? group.self_and_ancestors : [group] + groups_user_can_read_labels(groups).map(&:id) end end @@ -120,4 +121,10 @@ class LabelsFinder < UnionFinder Ability.allowed?(current_user, :read_label, label_parent) end + + def groups_user_can_read_labels(groups) + DeclarativePolicy.user_scope do + groups.select { |group| authorized_to_read_labels?(group) } + end + end end |