summaryrefslogtreecommitdiff
path: root/lib/api/award_emoji.rb
diff options
context:
space:
mode:
authorZ.J. van de Weg <zegerjan@gitlab.com>2016-09-07 14:48:43 +0200
committerFatih Acet <acetfatih@gmail.com>2016-09-19 19:53:09 +0300
commite8dd0d54cb1e82d142978224a4e062a705cae2cf (patch)
treefada10ed9931976930db159f0c385d186a718f6d /lib/api/award_emoji.rb
parent412ff80b7b1381485a306df240aab020e9b90801 (diff)
downloadgitlab-ce-e8dd0d54cb1e82d142978224a4e062a705cae2cf.tar.gz
Fix tests for Snippets toggling awards
Also incorporate feedback
Diffstat (limited to 'lib/api/award_emoji.rb')
-rw-r--r--lib/api/award_emoji.rb23
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/api/award_emoji.rb b/lib/api/award_emoji.rb
index ecce75cd413..2461a783ea8 100644
--- a/lib/api/award_emoji.rb
+++ b/lib/api/award_emoji.rb
@@ -1,12 +1,12 @@
module API
class AwardEmoji < Grape::API
before { authenticate! }
- AWARDABLES = [Issue, MergeRequest, Snippet]
+ AWARDABLES = %w[issue merge_request snippet]
resource :projects do
AWARDABLES.each do |awardable_type|
- awardable_string = awardable_type.to_s.underscore.pluralize
- awardable_id_string = "#{awardable_type.to_s.underscore}_id"
+ awardable_string = awardable_type.pluralize
+ awardable_id_string = "#{awardable_type}_id"
[ ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji",
":id/#{awardable_string}/:#{awardable_id_string}/notes/:note_id/award_emoji"
@@ -87,7 +87,7 @@ module API
helpers do
def can_read_awardable?
- can?(current_user, ability_name(awardable), awardable)
+ can?(current_user, read_ability(awardable), awardable)
end
def can_award_awardable?
@@ -98,8 +98,7 @@ module API
@awardable ||=
begin
if params.include?(:note_id)
- note_id = params[:note_id]
- params.delete(:note_id)
+ note_id = params.delete(:note_id)
awardable.notes.find(note_id)
elsif params.include?(:issue_id)
@@ -112,16 +111,12 @@ module API
end
end
- def ability_name(awardable)
+ def read_ability(awardable)
case awardable
when Note
- ability_name(awardable.noteable)
- when Snippet
- :read_project_snippet
- when MergeRequest
- :read_merge_request
- when Issue
- :read_issue
+ read_ability(awardable.noteable)
+ else
+ :"read_#{awardable.class.to_s.underscore}"
end
end
end