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/api/subscriptions.rb | |
parent | 4e9aa7e2c042030cea190a1e57dee76de0e573ea (diff) | |
download | gitlab-ce-a9fdc3118a7f9fb55b6f6b243f7bed2abe1ce48f.tar.gz |
Incorporate feedback from Robert
Diffstat (limited to 'lib/api/subscriptions.rb')
-rw-r--r-- | lib/api/subscriptions.rb | 45 |
1 files changed, 39 insertions, 6 deletions
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 |