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

award_emoji.rb « callbacks « work_items « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6344813d4b9d0da9a78935ff1144a8cb0fc33daa (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
# frozen_string_literal: true

module WorkItems
  module Callbacks
    class AwardEmoji < Base
      def before_update
        return unless params.present? && params.key?(:name) && params.key?(:action)
        return unless has_permission?(:award_emoji)

        execute_emoji_service(params[:action], params[:name])
      end

      private

      def execute_emoji_service(action, name)
        class_name = {
          add: ::AwardEmojis::AddService,
          remove: ::AwardEmojis::DestroyService
        }

        raise_error(invalid_action_error(action)) unless class_name.key?(action)

        result = class_name[action].new(work_item, name, current_user).execute

        raise_error(result[:message]) if result[:status] == :error
      end

      def invalid_action_error(key)
        format(_("%{key} is not a valid action."), key: key)
      end
    end
  end
end