diff options
author | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-06-30 10:56:56 +0200 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-09-19 19:47:43 +0300 |
commit | 7475f9d175482254b9b3097226b95a14c5325cff (patch) | |
tree | ed80e029ec1927227b503a33f98c6148cff4b773 /lib | |
parent | 25004cbc32432d989a05532925c5c4c591cca1b5 (diff) | |
download | gitlab-ce-7475f9d175482254b9b3097226b95a14c5325cff.tar.gz |
API support for Award Emoji on Snippets
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/award_emoji.rb | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/api/award_emoji.rb b/lib/api/award_emoji.rb index 2898e8222fa..ecce75cd413 100644 --- a/lib/api/award_emoji.rb +++ b/lib/api/award_emoji.rb @@ -87,9 +87,7 @@ module API helpers do def can_read_awardable? - ability = "read_#{awardable.class.to_s.underscore}".to_sym - - can?(current_user, ability, awardable) + can?(current_user, ability_name(awardable), awardable) end def can_award_awardable? @@ -100,18 +98,30 @@ module API @awardable ||= begin if params.include?(:note_id) - noteable.notes.find(params[:note_id]) + note_id = params[:note_id] + params.delete(:note_id) + + awardable.notes.find(note_id) + elsif params.include?(:issue_id) + user_project.issues.find(params[:issue_id]) + elsif params.include?(:merge_request_id) + user_project.merge_requests.find(params[:merge_request_id]) else - noteable + user_project.snippets.find(params[:snippet_id]) end end end - def noteable - if params.include?(:issue_id) - user_project.issues.find(params[:issue_id]) - else - user_project.merge_requests.find(params[:merge_request_id]) + def ability_name(awardable) + case awardable + when Note + ability_name(awardable.noteable) + when Snippet + :read_project_snippet + when MergeRequest + :read_merge_request + when Issue + :read_issue end end end |