gitlab-org--gitlab-foss/app/controllers/concerns/toggle_award_emoji.rb

37 lines
693 B
Ruby
Raw Normal View History

2016-04-16 15:09:08 -04:00
module ToggleAwardEmoji
extend ActiveSupport::Concern
def toggle_award_emoji
authenticate_user!
2016-04-16 15:09:08 -04:00
name = params.require(:name)
2016-05-17 13:28:17 -04:00
if awardable.user_can_award?(current_user, name)
awardable.toggle_award_emoji(name, current_user)
2016-06-03 05:44:04 -04:00
todoable = to_todoable(awardable)
TodoService.new.new_award_emoji(todoable, current_user) if todoable
render json: { ok: true }
else
render json: { ok: false }
end
2016-04-16 15:09:08 -04:00
end
private
2016-05-25 15:07:36 -04:00
def to_todoable(awardable)
case awardable
when Note
awardable.noteable
2016-06-03 05:44:04 -04:00
when MergeRequest, Issue
2016-05-25 15:07:36 -04:00
awardable
2016-06-03 05:44:04 -04:00
when Snippet
nil
2016-05-25 15:07:36 -04:00
end
end
2016-04-16 15:09:08 -04:00
def awardable
raise NotImplementedError
end
end