diff options
Diffstat (limited to 'app/services/issues')
-rw-r--r-- | app/services/issues/base_service.rb | 36 | ||||
-rw-r--r-- | app/services/issues/build_service.rb | 24 | ||||
-rw-r--r-- | app/services/issues/create_service.rb | 5 | ||||
-rw-r--r-- | app/services/issues/set_crm_contacts_service.rb | 2 | ||||
-rw-r--r-- | app/services/issues/update_service.rb | 21 |
5 files changed, 35 insertions, 53 deletions
diff --git a/app/services/issues/base_service.rb b/app/services/issues/base_service.rb index 577f7dd1e3a..37d667d4be8 100644 --- a/app/services/issues/base_service.rb +++ b/app/services/issues/base_service.rb @@ -36,8 +36,8 @@ module Issues private def find_work_item_type_id(issue_type) - work_item_type = WorkItem::Type.default_by_type(issue_type) - work_item_type ||= WorkItem::Type.default_issue_type + work_item_type = WorkItems::Type.default_by_type(issue_type) + work_item_type ||= WorkItems::Type.default_issue_type work_item_type.id end @@ -46,7 +46,6 @@ module Issues super params.delete(:issue_type) unless create_issue_type_allowed?(issue, params[:issue_type]) - filter_incident_label(issue) if params[:issue_type] moved_issue = params.delete(:moved_issue) @@ -89,37 +88,6 @@ module Issues Milestones::IssuesCountService.new(milestone).delete_cache end - - # @param issue [Issue] - def filter_incident_label(issue) - return unless add_incident_label?(issue) || remove_incident_label?(issue) - - label = ::IncidentManagement::CreateIncidentLabelService - .new(project, current_user) - .execute - .payload[:label] - - # These(add_label_ids, remove_label_ids) are being added ahead of time - # to be consumed by #process_label_ids, this allows system notes - # to be applied correctly alongside the label updates. - if add_incident_label?(issue) - params[:add_label_ids] ||= [] - params[:add_label_ids] << label.id - else - params[:remove_label_ids] ||= [] - params[:remove_label_ids] << label.id - end - end - - # @param issue [Issue] - def add_incident_label?(issue) - issue.incident? - end - - # @param _issue [Issue, nil] - def remove_incident_label?(_issue) - false - end end end diff --git a/app/services/issues/build_service.rb b/app/services/issues/build_service.rb index 8fd844c4886..1ebf9bb6ba2 100644 --- a/app/services/issues/build_service.rb +++ b/app/services/issues/build_service.rb @@ -7,7 +7,7 @@ module Issues def execute filter_resolve_discussion_params - @issue = project.issues.new(issue_params).tap do |issue| + @issue = model_klass.new(issue_params.merge(project: project)).tap do |issue| ensure_milestone_available(issue) end end @@ -62,16 +62,25 @@ module Issues def issue_params @issue_params ||= build_issue_params - # If :issue_type is nil then params[:issue_type] was either nil - # or not permitted. Either way, the :issue_type will default - # to the column default of `issue`. And that means we need to - # ensure the work_item_type_id is set - @issue_params[:work_item_type_id] = get_work_item_type_id(@issue_params[:issue_type]) + if @issue_params[:work_item_type].present? + @issue_params[:issue_type] = @issue_params[:work_item_type].base_type + else + # If :issue_type is nil then params[:issue_type] was either nil + # or not permitted. Either way, the :issue_type will default + # to the column default of `issue`. And that means we need to + # ensure the work_item_type_id is set + @issue_params[:work_item_type_id] = get_work_item_type_id(@issue_params[:issue_type]) + end + @issue_params end private + def model_klass + ::Issue + end + def allowed_issue_params allowed_params = [ :title, @@ -79,8 +88,11 @@ module Issues :confidential ] + params[:work_item_type] = WorkItems::Type.find_by(id: params[:work_item_type_id]) if params[:work_item_type_id].present? # rubocop: disable CodeReuse/ActiveRecord + allowed_params << :milestone_id if can?(current_user, :admin_issue, project) allowed_params << :issue_type if create_issue_type_allowed?(project, params[:issue_type]) + allowed_params << :work_item_type if create_issue_type_allowed?(project, params[:work_item_type]&.base_type) params.slice(*allowed_params) end diff --git a/app/services/issues/create_service.rb b/app/services/issues/create_service.rb index 79b59eee5e1..e29bcf4a453 100644 --- a/app/services/issues/create_service.rb +++ b/app/services/issues/create_service.rb @@ -12,13 +12,14 @@ module Issues # spam_checking is likely to be necessary. However, if there is not a request available in scope # in the caller (for example, an issue created via email) and the required arguments to the # SpamParams constructor are not otherwise available, spam_params: must be explicitly passed as nil. - def initialize(project:, current_user: nil, params: {}, spam_params:) + def initialize(project:, current_user: nil, params: {}, spam_params:, build_service: nil) super(project: project, current_user: current_user, params: params) @spam_params = spam_params + @build_service = build_service || BuildService.new(project: project, current_user: current_user, params: params) end def execute(skip_system_notes: false) - @issue = BuildService.new(project: project, current_user: current_user, params: params).execute + @issue = @build_service.execute filter_resolve_discussion_params diff --git a/app/services/issues/set_crm_contacts_service.rb b/app/services/issues/set_crm_contacts_service.rb index c435ab81b4d..947d46f0809 100644 --- a/app/services/issues/set_crm_contacts_service.rb +++ b/app/services/issues/set_crm_contacts_service.rb @@ -48,7 +48,7 @@ module Issues end def add_by_email - contact_ids = ::CustomerRelations::Contact.find_ids_by_emails(project_group.id, params[:add_emails]) + contact_ids = ::CustomerRelations::Contact.find_ids_by_emails(project_group, params[:add_emails]) add_by_id(contact_ids) end diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index 824a609dfb9..aecb22453b7 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -53,6 +53,7 @@ module Issues old_mentioned_users = old_associations.fetch(:mentioned_users, []) old_assignees = old_associations.fetch(:assignees, []) old_severity = old_associations[:severity] + old_escalation_status = old_associations[:escalation_status] if has_changes?(issue, old_labels: old_labels, old_assignees: old_assignees) todo_service.resolve_todos_for_target(issue, current_user) @@ -69,6 +70,7 @@ module Issues handle_milestone_change(issue) handle_added_mentions(issue, old_mentioned_users) handle_severity_change(issue, old_severity) + handle_escalation_status_change(issue, old_escalation_status) handle_issue_type_change(issue) end @@ -208,6 +210,13 @@ module Issues ::IncidentManagement::AddSeveritySystemNoteWorker.perform_async(issue.id, current_user.id) end + def handle_escalation_status_change(issue, old_escalation_status) + return unless old_escalation_status.present? + return if issue.escalation_status&.slice(:status, :policy_id) == old_escalation_status + + ::IncidentManagement::IssuableEscalationStatuses::AfterUpdateService.new(issue, current_user).execute + end + # rubocop: disable CodeReuse/ActiveRecord def issuable_for_positioning(id, board_group_id = nil) return unless id @@ -227,16 +236,6 @@ module Issues SystemNoteService.change_issue_confidentiality(issue, issue.project, current_user) end - override :add_incident_label? - def add_incident_label?(issue) - issue.issue_type != params[:issue_type] && !issue.incident? - end - - override :remove_incident_label? - def remove_incident_label?(issue) - issue.issue_type != params[:issue_type] && issue.incident? - end - def handle_issue_type_change(issue) return unless issue.previous_changes.include?('issue_type') @@ -245,6 +244,8 @@ module Issues def do_handle_issue_type_change(issue) SystemNoteService.change_issue_type(issue, current_user) + + ::IncidentManagement::IssuableEscalationStatuses::CreateService.new(issue).execute if issue.supports_escalation? end end end |