debian-mirror-gitlab/app/services/issues/base_service.rb

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

136 lines
4.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module Issues
2015-04-26 12:48:37 +05:30
class BaseService < ::IssuableBaseService
2022-04-04 11:22:00 +05:30
extend ::Gitlab::Utils::Override
2020-11-24 15:15:51 +05:30
include IncidentManagement::UsageData
2021-12-11 22:18:48 +05:30
include IssueTypeHelpers
2020-11-24 15:15:51 +05:30
2018-03-17 18:26:18 +05:30
def hook_data(issue, action, old_associations: {})
hook_data = issue.to_hook_data(current_user, old_associations: old_associations)
hook_data[:object_attributes][:action] = action
hook_data
2014-09-02 18:07:02 +05:30
end
2017-09-10 17:25:29 +05:30
def reopen_service
Issues::ReopenService
end
def close_service
Issues::CloseService
end
2020-11-24 15:15:51 +05:30
NO_REBALANCING_NEEDED = ((RelativePositioning::MIN_POSITION * 0.9999)..(RelativePositioning::MAX_POSITION * 0.9999)).freeze
def rebalance_if_needed(issue)
return unless issue
return if issue.relative_position.nil?
return if NO_REBALANCING_NEEDED.cover?(issue.relative_position)
2022-01-26 12:08:38 +05:30
Issues::RebalancingWorker.perform_async(nil, *issue.project.self_or_root_group_ids)
2020-11-24 15:15:51 +05:30
end
2015-04-26 12:48:37 +05:30
private
2021-11-11 11:23:49 +05:30
def find_work_item_type_id(issue_type)
2022-03-02 08:16:31 +05:30
work_item_type = WorkItems::Type.default_by_type(issue_type)
work_item_type ||= WorkItems::Type.default_issue_type
2021-11-11 11:23:49 +05:30
work_item_type.id
end
2021-04-28 17:22:55 +05:30
def filter_params(issue)
2021-01-03 14:25:43 +05:30
super
2021-12-11 22:18:48 +05:30
params.delete(:issue_type) unless create_issue_type_allowed?(issue, params[:issue_type])
2021-06-08 01:23:25 +05:30
2021-01-03 14:25:43 +05:30
moved_issue = params.delete(:moved_issue)
# Setting created_at, updated_at and iid is allowed only for admins and owners or
# when moving an issue as we preserve the original issue attributes except id and iid.
params.delete(:iid) unless current_user.can?(:set_issue_iid, project)
params.delete(:created_at) unless moved_issue || current_user.can?(:set_issue_created_at, project)
params.delete(:updated_at) unless moved_issue || current_user.can?(:set_issue_updated_at, project)
2021-04-28 17:22:55 +05:30
2021-08-04 16:29:09 +05:30
# Only users with permission to handle error data can add it to issues
params.delete(:sentry_issue_attributes) unless current_user.can?(:update_sentry_issue, project)
2021-04-28 17:22:55 +05:30
issue.system_note_timestamp = params[:created_at] || params[:updated_at]
2021-01-03 14:25:43 +05:30
end
2022-04-04 11:22:00 +05:30
override :handle_move_between_ids
def handle_move_between_ids(issue)
issue.check_repositioning_allowed! if params[:move_between_ids]
super
rebalance_if_needed(issue)
end
2022-11-25 23:54:43 +05:30
def handle_escalation_status_change(issue)
return unless issue.supports_escalation?
if issue.escalation_status
::IncidentManagement::IssuableEscalationStatuses::AfterUpdateService.new(
issue,
current_user
).execute
else
::IncidentManagement::IssuableEscalationStatuses::CreateService.new(issue).execute
end
end
2022-04-04 11:22:00 +05:30
def issuable_for_positioning(id, positioning_scope)
return unless id
positioning_scope.find(id)
end
2017-08-17 22:00:37 +05:30
def create_assignee_note(issue, old_assignees)
2019-07-31 22:56:46 +05:30
SystemNoteService.change_issuable_assignees(
2017-08-17 22:00:37 +05:30
issue, issue.project, current_user, old_assignees)
2015-09-11 14:41:01 +05:30
end
2018-03-17 18:26:18 +05:30
def execute_hooks(issue, action = 'open', old_associations: {})
2021-04-29 21:17:54 +05:30
issue_data = Gitlab::Lazy.new { hook_data(issue, action, old_associations: old_associations) }
2016-09-29 09:46:39 +05:30
hooks_scope = issue.confidential? ? :confidential_issue_hooks : :issue_hooks
issue.project.execute_hooks(issue_data, hooks_scope)
2021-09-30 23:02:18 +05:30
issue.project.execute_integrations(issue_data, hooks_scope)
2023-03-17 16:20:25 +05:30
execute_incident_hooks(issue, issue_data) if issue.incident?
end
# We can remove this code after proposal in
# https://gitlab.com/gitlab-org/gitlab/-/issues/367550#proposal is updated.
def execute_incident_hooks(issue, issue_data)
issue_data[:object_kind] = 'incident'
issue_data[:event_type] = 'incident'
issue.project.execute_integrations(issue_data, :incident_hooks)
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
def update_project_counter_caches?(issue)
super || issue.confidential_changed?
end
2020-04-08 14:13:33 +05:30
def delete_milestone_closed_issue_counter_cache(milestone)
return unless milestone
Milestones::ClosedIssuesCountService.new(milestone).delete_cache
end
def delete_milestone_total_issue_counter_cache(milestone)
return unless milestone
Milestones::IssuesCountService.new(milestone).delete_cache
end
2023-03-04 22:38:38 +05:30
override :allowed_create_params
def allowed_create_params(params)
2023-03-17 16:20:25 +05:30
super(params).except(:work_item_type_id, :work_item_type)
2023-03-04 22:38:38 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
2020-01-01 13:55:28 +05:30
2021-06-08 01:23:25 +05:30
Issues::BaseService.prepend_mod_with('Issues::BaseService')