diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2019-01-06 18:56:02 +0100 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2019-01-31 13:49:51 +0100 |
commit | a9fdc3118a7f9fb55b6f6b243f7bed2abe1ce48f (patch) | |
tree | 92dace891ba5dd38a0d979c8146bd61d32d71fe9 /lib | |
parent | 4e9aa7e2c042030cea190a1e57dee76de0e573ea (diff) | |
download | gitlab-ce-a9fdc3118a7f9fb55b6f6b243f7bed2abe1ce48f.tar.gz |
Incorporate feedback from Robert
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 7 | ||||
-rw-r--r-- | lib/api/group_labels.rb | 4 | ||||
-rw-r--r-- | lib/api/helpers.rb | 6 | ||||
-rw-r--r-- | lib/api/subscriptions.rb | 45 |
4 files changed, 49 insertions, 13 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 25052a29c31..e361b419f16 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1006,7 +1006,7 @@ module API expose :id, :name, :color, :description end - class GroupLabel < LabelBasic + class Label < LabelBasic expose :open_issues_count do |label, options| label.open_issues_count(options[:current_user]) end @@ -1024,7 +1024,10 @@ module API end end - class ProjectLabel < GroupLabel + class GroupLabel < Label + end + + class ProjectLabel < Label expose :priority do |label, options| label.priority(options[:project]) end diff --git a/lib/api/group_labels.rb b/lib/api/group_labels.rb index 85fd470c10d..559e6a25f35 100644 --- a/lib/api/group_labels.rb +++ b/lib/api/group_labels.rb @@ -57,7 +57,7 @@ module API delete ':id/labels' do authorize! :admin_label, user_group - label = find_label(user_group, params[:name], false) + label = find_label(user_group, params[:name], include_ancestor_groups: false) destroy_conditionally!(label) end @@ -76,7 +76,7 @@ module API put ':id/labels' do authorize! :admin_label, user_group - label = find_label(user_group, params[:name], false) + label = find_label(user_group, params[:name], include_ancestor_groups: false) label = ::Labels::UpdateService.new(declared_params(include_missing: false)).execute(label) render_validation_error!(label) unless label.valid? diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index afe0437c555..f769a5f78c0 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -84,7 +84,7 @@ module API page || not_found!('Wiki Page') end - def available_labels_for(label_parent, include_ancestor_groups = true) + def available_labels_for(label_parent, include_ancestor_groups: true) search_params = { include_ancestor_groups: include_ancestor_groups } if label_parent.is_a?(Project) @@ -170,8 +170,8 @@ module API end end - def find_label(parent, id, include_ancestor_groups = true) - labels = available_labels_for(parent, include_ancestor_groups) + def find_label(parent, id, include_ancestor_groups: true) + labels = available_labels_for(parent, include_ancestor_groups: include_ancestor_groups) label = labels.find_by_id(id) || labels.find_by_title(id) label || not_found!('Label') diff --git a/lib/api/subscriptions.rb b/lib/api/subscriptions.rb index b15875027ee..10d747e231e 100644 --- a/lib/api/subscriptions.rb +++ b/lib/api/subscriptions.rb @@ -5,10 +5,30 @@ module API before { authenticate! } subscribables = [ - { type: 'merge_requests', entity: Entities::MergeRequest, source: Project, finder: ->(id) { find_merge_request_with_access(id, :update_merge_request) }, parent_resource: -> { user_project } }, - { type: 'issues', entity: Entities::Issue, source: Project, finder: ->(id) { find_project_issue(id) }, parent_resource: -> { user_project } }, - { type: 'labels', entity: Entities::ProjectLabel, source: Project, finder: ->(id) { find_label(user_project, id) }, parent_resource: -> { user_project } }, - { type: 'labels', entity: Entities::GroupLabel, source: Group, finder: ->(id) { find_label(user_group, id) }, parent_resource: -> { nil } } + { + type: 'merge_requests', + entity: Entities::MergeRequest, + source: Project, + finder: ->(id) { find_merge_request_with_access(id, :update_merge_request) } + }, + { + type: 'issues', + entity: Entities::Issue, + source: Project, + finder: ->(id) { find_project_issue(id) } + }, + { + type: 'labels', + entity: Entities::ProjectLabel, + source: Project, + finder: ->(id) { find_label(user_project, id) } + }, + { + type: 'labels', + entity: Entities::GroupLabel, + source: Group, + finder: ->(id) { find_label(user_group, id) } + } ] subscribables.each do |subscribable| @@ -23,7 +43,7 @@ module API success subscribable[:entity] end post ":id/#{subscribable[:type]}/:subscribable_id/subscribe" do - parent = instance_exec(&subscribable[:parent_resource]) + parent = parent_resource(source_type) resource = instance_exec(params[:subscribable_id], &subscribable[:finder]) if resource.subscribed?(current_user, parent) @@ -38,7 +58,7 @@ module API success subscribable[:entity] end post ":id/#{subscribable[:type]}/:subscribable_id/unsubscribe" do - parent = instance_exec(&subscribable[:parent_resource]) + parent = parent_resource(source_type) resource = instance_exec(params[:subscribable_id], &subscribable[:finder]) if !resource.subscribed?(current_user, parent) @@ -50,5 +70,18 @@ module API end end end + + private + + helpers do + def parent_resource(source_type) + case source_type + when 'project' + user_project + else + nil + end + end + end end end |