gitlab-org--gitlab-foss/app/controllers/concerns/toggle_award_emoji.rb
Rémy Coutable beedd40ef7
Ensure user is authenticated to create a new snippet
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-11-28 16:57:49 +01:00

36 lines
693 B
Ruby

module ToggleAwardEmoji
extend ActiveSupport::Concern
def toggle_award_emoji
authenticate_user!
name = params.require(:name)
if awardable.user_can_award?(current_user, name)
awardable.toggle_award_emoji(name, current_user)
todoable = to_todoable(awardable)
TodoService.new.new_award_emoji(todoable, current_user) if todoable
render json: { ok: true }
else
render json: { ok: false }
end
end
private
def to_todoable(awardable)
case awardable
when Note
awardable.noteable
when MergeRequest, Issue
awardable
when Snippet
nil
end
end
def awardable
raise NotImplementedError
end
end