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

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

59 lines
2.1 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
class ReopenService < Issues::BaseService
2023-04-23 21:23:45 +05:30
# TODO: this is to be removed once we get to rename the IssuableBaseService project param to container
def initialize(container:, current_user: nil, params: {})
super(project: container, current_user: current_user, params: params)
end
2021-11-18 22:05:49 +05:30
def execute(issue, skip_authorization: false)
return issue unless can_reopen?(issue, skip_authorization: skip_authorization)
2016-09-13 17:45:13 +05:30
2022-10-11 01:57:18 +05:30
if issue.reopen
2014-09-02 18:07:02 +05:30
event_service.reopen_issue(issue, current_user)
2017-09-10 17:25:29 +05:30
create_note(issue, 'reopened')
2018-10-15 14:42:47 +05:30
notification_service.async.reopen_issue(issue, current_user)
2021-10-27 15:23:28 +05:30
perform_incident_management_actions(issue)
2014-09-02 18:07:02 +05:30
execute_hooks(issue, 'reopen')
2017-09-10 17:25:29 +05:30
invalidate_cache_counts(issue, users: issue.assignees)
2018-03-17 18:26:18 +05:30
issue.update_project_counter_caches
2020-04-08 14:13:33 +05:30
delete_milestone_closed_issue_counter_cache(issue.milestone)
2020-11-24 15:15:51 +05:30
track_incident_action(current_user, issue, :incident_reopened)
2014-09-02 18:07:02 +05:30
end
issue
end
private
2023-04-23 21:23:45 +05:30
# overriding this because IssuableBaseService#constructor_container_arg returns { project: value }
# Issues::ReopenService constructor signature is different now, it takes container instead of project also
# IssuableBaseService#change_state dynamically picks one of the `Issues::ReopenService`, `Epics::ReopenService` or
# MergeRequests::ReopenService, so we need this method to return { }container: value } for Issues::ReopenService
def self.constructor_container_arg(value)
{ container: value }
end
2021-11-18 22:05:49 +05:30
def can_reopen?(issue, skip_authorization: false)
skip_authorization || can?(current_user, :reopen_issue, issue)
end
2021-10-27 15:23:28 +05:30
def perform_incident_management_actions(issue)
2022-08-13 15:12:31 +05:30
return unless issue.incident?
create_timeline_event(issue)
2021-10-27 15:23:28 +05:30
end
2017-09-10 17:25:29 +05:30
def create_note(issue, state = issue.state)
SystemNoteService.change_status(issue, issue.project, current_user, state, nil)
2014-09-02 18:07:02 +05:30
end
2022-08-13 15:12:31 +05:30
def create_timeline_event(issue)
IncidentManagement::TimelineEvents::CreateService.reopen_incident(issue, current_user)
end
2014-09-02 18:07:02 +05:30
end
end
2021-10-27 15:23:28 +05:30
Issues::ReopenService.prepend_mod_with('Issues::ReopenService')