debian-mirror-gitlab/app/services/work_items/update_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.4 KiB
Ruby
Raw Normal View History

2022-04-04 11:22:00 +05:30
# frozen_string_literal: true
module WorkItems
class UpdateService < ::Issues::UpdateService
2022-08-13 15:12:31 +05:30
include WidgetableService
2022-07-23 23:45:48 +05:30
def initialize(project:, current_user: nil, params: {}, spam_params: nil, widget_params: {})
2022-08-13 15:12:31 +05:30
params[:widget_params] = true if widget_params.present?
2022-07-23 23:45:48 +05:30
super(project: project, current_user: current_user, params: params, spam_params: nil)
@widget_params = widget_params
end
2022-08-13 15:12:31 +05:30
def execute(work_item)
updated_work_item = super
if updated_work_item.valid?
success(payload(work_item))
else
error(updated_work_item.errors.full_messages, :unprocessable_entity, pass_back: payload(updated_work_item))
end
rescue ::WorkItems::Widgets::BaseService::WidgetError => e
error(e.message, :unprocessable_entity)
end
2022-04-04 11:22:00 +05:30
private
2022-08-27 11:52:29 +05:30
def before_update(work_item, skip_spam_check: false)
execute_widgets(work_item: work_item, callback: :before_update_callback, widget_params: @widget_params)
2022-08-13 15:12:31 +05:30
super
end
def transaction_update(work_item, opts = {})
execute_widgets(work_item: work_item, callback: :before_update_in_transaction, widget_params: @widget_params)
2022-07-23 23:45:48 +05:30
2022-04-04 11:22:00 +05:30
super
2022-07-23 23:45:48 +05:30
end
def after_update(work_item)
super
GraphqlTriggers.issuable_title_updated(work_item) if work_item.previous_changes.key?(:title)
end
2022-04-04 11:22:00 +05:30
2022-08-13 15:12:31 +05:30
def payload(work_item)
{ work_item: work_item }
2022-04-04 11:22:00 +05:30
end
end
end