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

36 lines
672 B
Ruby
Raw Normal View History

2016-04-16 15:09:08 -04:00
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-05-17 13:28:17 -04:00
if awardable.user_can_award?(current_user, name)
awardable.toggle_award_emoji(name, current_user)
TodoService.new.new_award_emoji(to_todoable(awardable), current_user)
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
else
awardable
end
end
2016-04-16 15:09:08 -04:00
def awardable
raise NotImplementedError
end
end