2016-04-16 15:09:08 -04:00
|
|
|
module ToggleAwardEmoji
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
def toggle_award_emoji
|
2016-11-28 07:03:31 -05:00
|
|
|
authenticate_user!
|
2016-04-16 15:09:08 -04:00
|
|
|
name = params.require(:name)
|
2016-05-17 13:28:17 -04:00
|
|
|
|
2016-08-30 15:57:47 -04:00
|
|
|
if awardable.user_can_award?(current_user, name)
|
|
|
|
awardable.toggle_award_emoji(name, current_user)
|
2016-09-04 04:51:12 -04:00
|
|
|
|
2016-06-03 05:44:04 -04:00
|
|
|
todoable = to_todoable(awardable)
|
|
|
|
TodoService.new.new_award_emoji(todoable, current_user) if todoable
|
2016-08-17 07:21:06 -04:00
|
|
|
|
2016-08-30 15:57:47 -04:00
|
|
|
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
|
2017-04-27 06:41:26 -04:00
|
|
|
# we don't create todos for personal snippet comments for now
|
|
|
|
awardable.for_personal_snippet? ? nil : 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
|