blob: 065ef9dc7088a86f78b72b1700a3f6c3224b5ec4 (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# frozen_string_literal: true
module AwardEmojis
class AddService < AwardEmojis::BaseService
include Gitlab::Utils::StrongMemoize
def execute
unless awardable.user_can_award?(current_user)
return error('User cannot award emoji to awardable', status: :forbidden)
end
unless awardable.emoji_awardable?
return error('Awardable cannot be awarded emoji', 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
private
def after_create(award)
TodoService.new.new_award_emoji(todoable, current_user) if todoable
execute_hooks(award, 'award')
end
def todoable
strong_memoize(:todoable) do
case awardable
when Note
# We don't create todos for personal snippet comments for now
awardable.noteable unless awardable.for_personal_snippet?
when MergeRequest, Issue
awardable
else
# No todos for all other awardables
nil
end
end
end
end
end
AwardEmojis::AddService.prepend_mod_with('AwardEmojis::AddService')
|