37b17fa61a
Adding, destroying and toggling emoji previously lacked services and instead were performed through methods called on Awardable models. This led to inconsistencies where relevant todos would be marked as done only when emoji were awarded through our controllers, but not through the API. Todos could also be marked as done when an emoji was being removed. Behaviour changes - Awarding emoji through the API will now mark a relevant Todo as done - Toggling an emoji off (destroying it) through our controllers will no longer mark a relevant Todo as done Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/63372
32 lines
730 B
Ruby
32 lines
730 B
Ruby
# frozen_string_literal: true
|
|
|
|
module AwardEmojis
|
|
class BaseService < ::BaseService
|
|
attr_accessor :awardable, :name
|
|
|
|
def initialize(awardable, name, current_user)
|
|
@awardable = awardable
|
|
@name = normalize_name(name)
|
|
|
|
super(awardable.project, current_user)
|
|
end
|
|
|
|
private
|
|
|
|
def normalize_name(name)
|
|
Gitlab::Emoji.normalize_emoji_name(name)
|
|
end
|
|
|
|
# Provide more error state data than what BaseService allows.
|
|
# - An array of errors
|
|
# - The `AwardEmoji` if present
|
|
def error(errors, award: nil, status: nil)
|
|
errors = Array.wrap(errors)
|
|
|
|
super(errors.to_sentence.presence, status).merge({
|
|
award: award,
|
|
errors: errors
|
|
})
|
|
end
|
|
end
|
|
end
|