debian-mirror-gitlab/app/controllers/concerns/toggle_award_emoji.rb

40 lines
758 B
Ruby
Raw Normal View History

module ToggleAwardEmoji
extend ActiveSupport::Concern
included do
before_action :authenticate_user!, only: [:toggle_award_emoji]
end
def toggle_award_emoji
name = params.require(:name)
2016-09-29 09:46:39 +05:30
if awardable.user_can_award?(current_user, name)
awardable.toggle_award_emoji(name, current_user)
2016-09-29 09:46:39 +05:30
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
2016-09-29 09:46:39 +05:30
when MergeRequest, Issue
awardable
2016-09-29 09:46:39 +05:30
when Snippet
nil
end
end
def awardable
raise NotImplementedError
end
end