diff options
Diffstat (limited to 'app/services/work_items')
-rw-r--r-- | app/services/work_items/create_service.rb | 12 | ||||
-rw-r--r-- | app/services/work_items/update_service.rb | 21 | ||||
-rw-r--r-- | app/services/work_items/widgets/base_service.rb | 5 | ||||
-rw-r--r-- | app/services/work_items/widgets/labels_service/update_service.rb | 15 |
4 files changed, 45 insertions, 8 deletions
diff --git a/app/services/work_items/create_service.rb b/app/services/work_items/create_service.rb index c2ceb701a2f..ebda043e873 100644 --- a/app/services/work_items/create_service.rb +++ b/app/services/work_items/create_service.rb @@ -2,7 +2,6 @@ module WorkItems class CreateService < Issues::CreateService - include ::Services::ReturnServiceResponses include WidgetableService def initialize(project:, current_user: nil, params: {}, spam_params:, widget_params: {}) @@ -17,11 +16,10 @@ module WorkItems end def execute - unless @current_user.can?(:create_work_item, @project) - return error(_('Operation not allowed'), :forbidden) - end + result = super + return result if result.error? - work_item = super + work_item = result[:issue] if work_item.valid? success(payload(work_item)) @@ -43,6 +41,10 @@ module WorkItems private + def authorization_action + :create_work_item + end + def payload(work_item) { work_item: work_item } end diff --git a/app/services/work_items/update_service.rb b/app/services/work_items/update_service.rb index 2deb8c82741..1351445f6f3 100644 --- a/app/services/work_items/update_service.rb +++ b/app/services/work_items/update_service.rb @@ -26,6 +26,17 @@ module WorkItems private + def prepare_update_params(work_item) + execute_widgets( + work_item: work_item, + callback: :prepare_update_params, + widget_params: @widget_params, + service_params: params + ) + + super + end + def before_update(work_item, skip_spam_check: false) execute_widgets(work_item: work_item, callback: :before_update_callback, widget_params: @widget_params) @@ -38,7 +49,7 @@ module WorkItems super end - def after_update(work_item) + def after_update(work_item, old_associations) super GraphqlTriggers.issuable_title_updated(work_item) if work_item.previous_changes.key?(:title) @@ -47,5 +58,13 @@ module WorkItems def payload(work_item) { work_item: work_item } end + + def handle_label_changes(issuable, old_labels) + return false unless super + + Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter.track_work_item_labels_changed_action( + author: current_user + ) + end end end diff --git a/app/services/work_items/widgets/base_service.rb b/app/services/work_items/widgets/base_service.rb index 37ed2bf4b05..1ff03a09f9f 100644 --- a/app/services/work_items/widgets/base_service.rb +++ b/app/services/work_items/widgets/base_service.rb @@ -5,12 +5,13 @@ module WorkItems class BaseService < ::BaseService WidgetError = Class.new(StandardError) - attr_reader :widget, :work_item, :current_user + attr_reader :widget, :work_item, :current_user, :service_params - def initialize(widget:, current_user:) + def initialize(widget:, current_user:, service_params: {}) @widget = widget @work_item = widget.work_item @current_user = current_user + @service_params = service_params end private diff --git a/app/services/work_items/widgets/labels_service/update_service.rb b/app/services/work_items/widgets/labels_service/update_service.rb new file mode 100644 index 00000000000..f00ea5c95ca --- /dev/null +++ b/app/services/work_items/widgets/labels_service/update_service.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module WorkItems + module Widgets + module LabelsService + class UpdateService < WorkItems::Widgets::BaseService + def prepare_update_params(params: {}) + return if params.blank? + + service_params.merge!(params.slice(:add_label_ids, :remove_label_ids)) + end + end + end + end +end |