37b17fa61a
Adding, destroying and toggling emoji previously lacked services and instead were performed through methods called on Awardable models. This led to inconsistencies where relevant todos would be marked as done only when emoji were awarded through our controllers, but not through the API. Todos could also be marked as done when an emoji was being removed. Behaviour changes - Awarding emoji through the API will now mark a relevant Todo as done - Toggling an emoji off (destroying it) through our controllers will no longer mark a relevant Todo as done Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/63372
21 lines
616 B
Ruby
21 lines
616 B
Ruby
# frozen_string_literal: true
|
|
|
|
module AwardEmojis
|
|
class DestroyService < AwardEmojis::BaseService
|
|
def execute
|
|
unless awardable.user_can_award?(current_user)
|
|
return error('User cannot destroy emoji on the awardable', status: :forbidden)
|
|
end
|
|
|
|
awards = AwardEmojisFinder.new(awardable, name: name, awarded_by: current_user).execute
|
|
|
|
if awards.empty?
|
|
return error("User has not awarded emoji of type #{name} on the awardable", status: :forbidden)
|
|
end
|
|
|
|
award = awards.destroy_all.first # rubocop: disable DestroyAll
|
|
|
|
success(award: award)
|
|
end
|
|
end
|
|
end
|