2016-06-16 23:09:34 +05:30
|
|
|
module ToggleAwardEmoji
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
def toggle_award_emoji
|
2017-08-17 22:00:37 +05:30
|
|
|
authenticate_user!
|
2016-06-16 23:09:34 +05:30
|
|
|
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-06-16 23:09:34 +05:30
|
|
|
|
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
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def to_todoable(awardable)
|
|
|
|
case awardable
|
|
|
|
when Note
|
2017-08-17 22:00:37 +05:30
|
|
|
# we don't create todos for personal snippet comments for now
|
|
|
|
awardable.for_personal_snippet? ? nil : awardable.noteable
|
2016-09-29 09:46:39 +05:30
|
|
|
when MergeRequest, Issue
|
2016-06-16 23:09:34 +05:30
|
|
|
awardable
|
2016-09-29 09:46:39 +05:30
|
|
|
when Snippet
|
|
|
|
nil
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def awardable
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|