Class: AwardEmojis::AddService

Inherits:
BaseService show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/award_emojis/add_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

#execute_hooks, #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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/award_emojis/add_service.rb', line 7

def execute
  unless awardable.user_can_award?(current_user)
    return error('User cannot add emoji reactions to awardable', status: :forbidden)
  end

  unless awardable.emoji_awardable?
    return error('Awardable cannot add emoji reactions', status: :unprocessable_entity)
  end

  award = awardable.award_emoji.create(name: name, user: current_user)

  if award.persisted?
    after_create(award)
    success(award: award)
  else
    error(award.errors.full_messages, award: award)
  end
end