diff options
Diffstat (limited to 'app/services/issues')
-rw-r--r-- | app/services/issues/base_service.rb | 34 | ||||
-rw-r--r-- | app/services/issues/close_service.rb | 13 | ||||
-rw-r--r-- | app/services/issues/create_service.rb | 31 | ||||
-rw-r--r-- | app/services/issues/update_service.rb | 22 | ||||
-rw-r--r-- | app/services/issues/zoom_link_service.rb | 4 |
5 files changed, 60 insertions, 44 deletions
diff --git a/app/services/issues/base_service.rb b/app/services/issues/base_service.rb index 72e906e20f1..1c50bb74176 100644 --- a/app/services/issues/base_service.rb +++ b/app/services/issues/base_service.rb @@ -29,7 +29,7 @@ module Issues gates = [issue.project, issue.project.group].compact return unless gates.any? { |gate| Feature.enabled?(:rebalance_issues, gate) } - IssueRebalancingWorker.perform_async(nil, issue.project_id) + IssueRebalancingWorker.perform_async(nil, *issue.project.self_or_root_group_ids) end private @@ -38,6 +38,7 @@ module Issues super params.delete(:issue_type) unless issue_type_allowed?(issue) + filter_incident_label(issue) if params[:issue_type] moved_issue = params.delete(:moved_issue) @@ -82,6 +83,37 @@ module Issues def issue_type_allowed?(object) can?(current_user, :"create_#{params[:issue_type]}", object) 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/close_service.rb b/app/services/issues/close_service.rb index 1700d1d8586..cc4ad1a9c85 100644 --- a/app/services/issues/close_service.rb +++ b/app/services/issues/close_service.rb @@ -25,7 +25,6 @@ module Issues end if project.issues_enabled? && issue.close(current_user) - remove_on_close_labels_from(issue) event_service.close_issue(issue, current_user) create_note(issue, closed_via) if system_note @@ -52,18 +51,6 @@ module Issues private - def remove_on_close_labels_from(issue) - old_labels = issue.labels.to_a - - issue.label_links.with_remove_on_close_labels.delete_all - issue.labels.reset - - Issuable::CommonSystemNotesService.new(project: project, current_user: current_user).execute( - issue, - old_labels: old_labels - ) - end - def close_external_issue(issue, closed_via) return unless project.external_issue_tracker&.support_close_issue? diff --git a/app/services/issues/create_service.rb b/app/services/issues/create_service.rb index 1f4efeb1a8a..53f3dc39ba3 100644 --- a/app/services/issues/create_service.rb +++ b/app/services/issues/create_service.rb @@ -34,13 +34,26 @@ module Issues # Add new items to Issues::AfterCreateService if they can be performed in Sidekiq def after_create(issue) - add_incident_label(issue) user_agent_detail_service.create resolve_discussions_with_issue(issue) super end + def handle_changes(issue, options) + super + old_associations = options.fetch(:old_associations, {}) + old_assignees = old_associations.fetch(:assignees, []) + + handle_assignee_changes(issue, old_assignees) + end + + def handle_assignee_changes(issue, old_assignees) + return if issue.assignees == old_assignees + + create_assignee_note(issue, old_assignees) + end + def resolve_discussions_with_issue(issue) return if discussions_to_resolve.empty? @@ -56,22 +69,6 @@ module Issues def user_agent_detail_service UserAgentDetailService.new(@issue, request) end - - # Applies label "incident" (creates it if missing) to incident issues. - # For 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 end end diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index af5029f8364..cf2892bf413 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -20,17 +20,6 @@ module Issues super end - override :filter_params - def filter_params(issue) - super - - # filter confidential in `Issues::UpdateService` and not in `IssuableBaseService#filter_params` - # because we do allow users that cannot admin issues to set confidential flag when creating an issue - unless can_admin_issuable?(issue) - params.delete(:confidential) - end - end - def before_update(issue, skip_spam_check: false) return if skip_spam_check @@ -43,6 +32,7 @@ module Issues end def handle_changes(issue, options) + super old_associations = options.fetch(:old_associations, {}) old_labels = old_associations.fetch(:labels, []) old_mentioned_users = old_associations.fetch(:mentioned_users, []) @@ -204,6 +194,16 @@ module Issues def create_confidentiality_note(issue) 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 end end diff --git a/app/services/issues/zoom_link_service.rb b/app/services/issues/zoom_link_service.rb index ef48134dec4..1ce459aa7e6 100644 --- a/app/services/issues/zoom_link_service.rb +++ b/app/services/issues/zoom_link_service.rb @@ -47,11 +47,11 @@ module Issues attr_reader :issue def track_meeting_added_event - ::Gitlab::Tracking.event('IncidentManagement::ZoomIntegration', 'add_zoom_meeting', label: 'Issue ID', value: issue.id) + ::Gitlab::Tracking.event('IncidentManagement::ZoomIntegration', 'add_zoom_meeting', label: 'Issue ID', value: issue.id, user: current_user, project: @project, namespace: @project.namespace) end def track_meeting_removed_event - ::Gitlab::Tracking.event('IncidentManagement::ZoomIntegration', 'remove_zoom_meeting', label: 'Issue ID', value: issue.id) + ::Gitlab::Tracking.event('IncidentManagement::ZoomIntegration', 'remove_zoom_meeting', label: 'Issue ID', value: issue.id, user: current_user, project: @project, namespace: @project.namespace) end def add_zoom_meeting(link) |