diff options
Diffstat (limited to 'app/services/work_items/callbacks/award_emoji.rb')
-rw-r--r-- | app/services/work_items/callbacks/award_emoji.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/services/work_items/callbacks/award_emoji.rb b/app/services/work_items/callbacks/award_emoji.rb new file mode 100644 index 00000000000..6344813d4b9 --- /dev/null +++ b/app/services/work_items/callbacks/award_emoji.rb @@ -0,0 +1,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 |