Welcome to mirror list, hosted at ThFree Co, Russian Federation.

destroy_service.rb « award_emojis « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7146d69bf0c8a3066e4591bca51ecb108abc85b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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

      award = awards.destroy_all.first # rubocop: disable Cop/DestroyAll
      after_destroy(award)

      success(award: award)
    end

    private

    def after_destroy(award)
      execute_hooks(award, 'revoke')
    end
  end
end

AwardEmojis::DestroyService.prepend_mod_with('AwardEmojis::DestroyService')