Class: AwardEmojis::DestroyService

Inherits:
BaseService show all
Defined in:
app/services/award_emojis/destroy_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#awardable, #name

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from AwardEmojis::BaseService

Instance Method Details

#executeObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/award_emojis/destroy_service.rb', line 5

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