debian-mirror-gitlab/app/services/award_emojis/destroy_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
775 B
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# 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
2020-06-23 00:09:42 +05:30
award = awards.destroy_all.first # rubocop: disable Cop/DestroyAll
2020-04-22 19:07:51 +05:30
after_destroy(award)
2019-12-04 20:38:33 +05:30
success(award: award)
end
2020-04-22 19:07:51 +05:30
private
def after_destroy(award)
end
2019-12-04 20:38:33 +05:30
end
end
2020-04-22 19:07:51 +05:30
2021-06-08 01:23:25 +05:30
AwardEmojis::DestroyService.prepend_mod_with('AwardEmojis::DestroyService')