2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-02 06:54:41 -04:00
|
|
|
module Issues
|
2014-10-07 10:09:28 -04:00
|
|
|
class BaseService < ::IssuableBaseService
|
2022-02-09 13:16:19 -05:00
|
|
|
extend ::Gitlab::Utils::Override
|
2020-09-10 17:08:28 -04:00
|
|
|
include IncidentManagement::UsageData
|
2021-11-08 10:13:35 -05:00
|
|
|
include IssueTypeHelpers
|
2020-09-10 17:08:28 -04:00
|
|
|
|
2017-11-21 12:13:07 -05:00
|
|
|
def hook_data(issue, action, old_associations: {})
|
|
|
|
hook_data = issue.to_hook_data(current_user, old_associations: old_associations)
|
2017-09-15 13:08:27 -04:00
|
|
|
hook_data[:object_attributes][:action] = action
|
|
|
|
|
|
|
|
hook_data
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
2017-07-20 10:42:33 -04:00
|
|
|
def reopen_service
|
|
|
|
Issues::ReopenService
|
|
|
|
end
|
|
|
|
|
|
|
|
def close_service
|
|
|
|
Issues::CloseService
|
|
|
|
end
|
|
|
|
|
2020-08-26 20:10:33 -04:00
|
|
|
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)
|
|
|
|
|
|
|
|
gates = [issue.project, issue.project.group].compact
|
|
|
|
return unless gates.any? { |gate| Feature.enabled?(:rebalance_issues, gate) }
|
|
|
|
|
2021-12-02 16:10:16 -05:00
|
|
|
Issues::RebalancingWorker.perform_async(nil, *issue.project.self_or_root_group_ids)
|
2020-08-26 20:10:33 -04:00
|
|
|
end
|
|
|
|
|
2020-09-04 11:08:46 -04:00
|
|
|
private
|
|
|
|
|
2021-09-10 11:11:12 -04:00
|
|
|
def find_work_item_type_id(issue_type)
|
2021-12-22 07:16:22 -05:00
|
|
|
work_item_type = WorkItems::Type.default_by_type(issue_type)
|
|
|
|
work_item_type ||= WorkItems::Type.default_issue_type
|
2021-09-10 11:11:12 -04:00
|
|
|
|
|
|
|
work_item_type.id
|
|
|
|
end
|
|
|
|
|
2021-04-28 11:09:35 -04:00
|
|
|
def filter_params(issue)
|
2020-10-14 08:08:58 -04:00
|
|
|
super
|
|
|
|
|
2021-11-08 10:13:35 -05:00
|
|
|
params.delete(:issue_type) unless create_issue_type_allowed?(issue, params[:issue_type])
|
2021-05-14 08:10:58 -04:00
|
|
|
|
2020-10-14 08:08:58 -04:00
|
|
|
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 11:09:35 -04:00
|
|
|
|
2021-08-03 17:09:39 -04:00
|
|
|
# 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 11:09:35 -04:00
|
|
|
issue.system_note_timestamp = params[:created_at] || params[:updated_at]
|
2020-10-14 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
2022-02-09 13:16:19 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
def issuable_for_positioning(id, positioning_scope)
|
|
|
|
return unless id
|
|
|
|
|
2022-02-16 07:13:53 -05:00
|
|
|
positioning_scope.find(id)
|
2022-02-09 13:16:19 -05:00
|
|
|
end
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
def create_assignee_note(issue, old_assignees)
|
2019-04-07 14:35:16 -04:00
|
|
|
SystemNoteService.change_issuable_assignees(
|
2017-05-04 08:11:15 -04:00
|
|
|
issue, issue.project, current_user, old_assignees)
|
|
|
|
end
|
|
|
|
|
2017-11-21 12:13:07 -05:00
|
|
|
def execute_hooks(issue, action = 'open', old_associations: {})
|
2021-04-08 14:09:32 -04:00
|
|
|
issue_data = Gitlab::Lazy.new { hook_data(issue, action, old_associations: old_associations) }
|
2016-08-30 18:11:46 -04:00
|
|
|
hooks_scope = issue.confidential? ? :confidential_issue_hooks : :issue_hooks
|
|
|
|
issue.project.execute_hooks(issue_data, hooks_scope)
|
2021-06-30 02:07:17 -04:00
|
|
|
issue.project.execute_integrations(issue_data, hooks_scope)
|
2014-04-02 06:54:41 -04:00
|
|
|
end
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2017-11-09 14:34:21 -05:00
|
|
|
def update_project_counter_caches?(issue)
|
|
|
|
super || issue.confidential_changed?
|
|
|
|
end
|
2020-03-04 19:07:49 -05:00
|
|
|
|
|
|
|
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
|
2014-04-02 06:54:41 -04:00
|
|
|
end
|
|
|
|
end
|
2019-11-29 04:06:31 -05:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Issues::BaseService.prepend_mod_with('Issues::BaseService')
|