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
|
2020-11-24 15:15:51 +05:30
|
|
|
include IncidentManagement::UsageData
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
gates = [issue.project, issue.project.group].compact
|
|
|
|
return unless gates.any? { |gate| Feature.enabled?(:rebalance_issues, gate) }
|
|
|
|
|
|
|
|
IssueRebalancingWorker.perform_async(nil, issue.project_id)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
private
|
|
|
|
|
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: {})
|
|
|
|
issue_data = 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)
|
|
|
|
issue.project.execute_services(issue_data, hooks_scope)
|
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
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
# Applies label "incident" (creates it if missing) to incident issues.
|
|
|
|
# Please use in "after" hooks only to ensure we are not appyling
|
|
|
|
# labels prematurely.
|
|
|
|
def add_incident_label(issue)
|
|
|
|
return unless issue.incident?
|
|
|
|
|
|
|
|
label = ::IncidentManagement::CreateIncidentLabelService
|
|
|
|
.new(project, current_user)
|
|
|
|
.execute
|
|
|
|
.payload[:label]
|
|
|
|
|
|
|
|
return if issue.label_ids.include?(label.id)
|
|
|
|
|
|
|
|
issue.labels << label
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
Issues::BaseService.prepend_if_ee('EE::Issues::BaseService')
|