Class: WorkItems::CreateService

Inherits:
Issues::CreateService show all
Includes:
Services::ReturnServiceResponses, WidgetableService
Defined in:
app/services/work_items/create_service.rb

Constant Summary

Constants included from RateLimitedService

RateLimitedService::RateLimitedNotSetupError

Constants inherited from Issues::BaseService

Issues::BaseService::NO_REBALANCING_NEEDED

Constants included from Gitlab::Utils::UsageData

Gitlab::Utils::UsageData::DISTRIBUTED_HLL_FALLBACK, Gitlab::Utils::UsageData::FALLBACK, Gitlab::Utils::UsageData::HISTOGRAM_FALLBACK, Gitlab::Utils::UsageData::MAX_BUCKET_SIZE

Instance Attribute Summary

Attributes included from Issues::ResolveDiscussions

#discussion_to_resolve_id, #merge_request_to_resolve_discussions_of_iid

Attributes inherited from BaseProjectService

#project

Attributes inherited from BaseContainerService

#container, #current_user, #params

Instance Method Summary collapse

Methods included from WidgetableService

#execute_widgets, #widget_service, #widget_service_class

Methods included from Services::ReturnServiceResponses

#error, #success

Methods inherited from Issues::CreateService

#after_create, #before_create, #external_author, #handle_assignee_changes, #handle_changes, #resolve_discussions_with_issue

Methods included from Issues::ResolveDiscussions

#discussions_to_resolve, #filter_resolve_discussion_params, #merge_request_to_resolve_discussions_of

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from RateLimitedService

#execute_without_rate_limiting

Methods inherited from Issues::BaseService

#close_service, #hook_data, #rebalance_if_needed, #reopen_service

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from Issues::IssueTypeHelpers

#create_issue_type_allowed?

Methods included from IncidentManagement::UsageData

#track_incident_action

Methods included from Gitlab::Utils::UsageData

#add, #add_metric, #alt_usage_data, #average, #count, #distinct_count, #epics_deepest_relationship_level, #estimate_batch_distinct_count, #histogram, #jira_integration_data, #maximum_id, #measure_duration, #minimum_id, #redis_usage_data, #sum, #track_usage_event, #with_duration, #with_finished_at, #with_prometheus_client

Methods inherited from BaseContainerService

#group_container?, #namespace_container?, #project_container?

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(project:, current_user: nil, params: {}, spam_params:, widget_params: {}) ⇒ CreateService

Returns a new instance of CreateService.


8
9
10
11
12
13
14
15
16
17
# File 'app/services/work_items/create_service.rb', line 8

def initialize(project:, current_user: nil, params: {}, spam_params:, widget_params: {})
  super(
    project: project,
    current_user: current_user,
    params: params,
    spam_params: spam_params,
    build_service: ::WorkItems::BuildService.new(project: project, current_user: current_user, params: params)
  )
  @widget_params = widget_params
end

Instance Method Details

#executeObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/work_items/create_service.rb', line 19

def execute
  unless @current_user.can?(:create_work_item, @project)
    return error(_('Operation not allowed'), :forbidden)
  end

  work_item = super

  if work_item.valid?
    success(payload(work_item))
  else
    error(work_item.errors.full_messages, :unprocessable_entity, pass_back: payload(work_item))
  end
rescue ::WorkItems::Widgets::BaseService::WidgetError => e
  error(e.message, :unprocessable_entity)
end

#transaction_create(work_item) ⇒ Object


35
36
37
38
39
# File 'app/services/work_items/create_service.rb', line 35

def transaction_create(work_item)
  super

  execute_widgets(work_item: work_item, callback: :after_create_in_transaction, widget_params: @widget_params)
end