diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-02-28 22:58:36 +0100 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2018-03-02 08:50:00 +0100 |
commit | 911fd7c252dd6c43b9771b2833460f1605dc99a2 (patch) | |
tree | 0425fde7869d0fc9c6d1d74decd6e4c685f95930 | |
parent | f29dbaf55cc0c8a4b80c153454a2f7e22fd7a827 (diff) | |
download | gitlab-ce-911fd7c252dd6c43b9771b2833460f1605dc99a2.tar.gz |
Support additional LabelsFinder parameters for group labels
In some situations (listing labels for epics) we want to
list only group ancestor labels, this is already supported
in LabelsFinder we just need to enable additional parameters.
Also `set_issuables_index` method now loads project labels only if
@project is set (which is not used for epic group labels).
-rw-r--r-- | app/controllers/concerns/issuable_collections.rb | 2 | ||||
-rw-r--r-- | app/controllers/groups/labels_controller.rb | 8 | ||||
-rw-r--r-- | spec/controllers/groups/labels_controller_spec.rb | 29 |
3 files changed, 37 insertions, 2 deletions
diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index f7ba305a59f..4114ca6bf7c 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -17,7 +17,7 @@ module IssuableCollections set_pagination return if redirect_out_of_range(@total_pages) - if params[:label_name].present? + if params[:label_name].present? && @project labels_params = { project_id: @project.id, title: params[:label_name] } @labels = LabelsFinder.new(current_user, labels_params).execute end diff --git a/app/controllers/groups/labels_controller.rb b/app/controllers/groups/labels_controller.rb index f3a9e591c3e..2e4cec830bb 100644 --- a/app/controllers/groups/labels_controller.rb +++ b/app/controllers/groups/labels_controller.rb @@ -14,7 +14,13 @@ class Groups::LabelsController < Groups::ApplicationController end format.json do - available_labels = LabelsFinder.new(current_user, group_id: @group.id).execute + available_labels = LabelsFinder.new( + current_user, + group_id: @group.id, + only_group_labels: params[:only_group_labels], + include_ancestor_groups: params[:include_ancestor_groups] + ).execute + render json: LabelSerializer.new.represent_appearance(available_labels) end end diff --git a/spec/controllers/groups/labels_controller_spec.rb b/spec/controllers/groups/labels_controller_spec.rb index da54aa9054c..3269f47f327 100644 --- a/spec/controllers/groups/labels_controller_spec.rb +++ b/spec/controllers/groups/labels_controller_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Groups::LabelsController do let(:group) { create(:group) } let(:user) { create(:user) } + let(:project) { create(:project, namespace: group) } before do group.add_owner(user) @@ -10,6 +11,34 @@ describe Groups::LabelsController do sign_in(user) end + describe 'GET #index' do + let!(:label_1) { create(:label, project: project, title: 'label_1') } + let!(:group_label_1) { create(:group_label, group: group, title: 'group_label_1') } + + it 'returns group and project labels by default' do + get :index, group_id: group, format: :json + + label_ids = json_response.map {|label| label['title']} + expect(label_ids).to match_array([label_1.title, group_label_1.title]) + end + + context 'with ancestor group', :nested_groups do + let(:subgroup) { create(:group, parent: group) } + let!(:subgroup_label_1) { create(:group_label, group: subgroup, title: 'subgroup_label_1') } + + before do + subgroup.add_owner(user) + end + + it 'returns ancestor group labels', :nested_groups do + get :index, group_id: subgroup, include_ancestor_groups: true, only_group_labels: true, format: :json + + label_ids = json_response.map {|label| label['title']} + expect(label_ids).to match_array([group_label_1.title, subgroup_label_1.title]) + end + end + end + describe 'POST #toggle_subscription' do it 'allows user to toggle subscription on group labels' do label = create(:group_label, group: group) |