2014-04-02 12:38:24 +00:00
|
|
|
module Issues
|
2014-04-02 16:55:23 +00:00
|
|
|
class CloseService < Issues::BaseService
|
2016-10-07 13:20:57 +00:00
|
|
|
# Closes the supplied issue if the current user is able to do so.
|
2016-03-17 08:54:16 +00:00
|
|
|
def execute(issue, commit: nil, notifications: true, system_note: true)
|
2016-08-09 15:51:40 +00:00
|
|
|
return issue unless can?(current_user, :update_issue, issue)
|
|
|
|
|
2016-10-07 13:20:57 +00:00
|
|
|
close_issue(issue,
|
|
|
|
commit: commit,
|
|
|
|
notifications: notifications,
|
|
|
|
system_note: system_note)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Closes the supplied issue without checking if the user is authorized to
|
|
|
|
# do so.
|
|
|
|
#
|
|
|
|
# The code calling this method is responsible for ensuring that a user is
|
|
|
|
# allowed to close the given issue.
|
|
|
|
def close_issue(issue, commit: nil, notifications: true, system_note: true)
|
2017-07-10 07:38:42 +00:00
|
|
|
if project.jira_tracker? && project.jira_service.active && issue.is_a?(ExternalIssue)
|
2016-12-01 08:45:06 +00:00
|
|
|
project.jira_service.close_issue(commit, issue)
|
2016-02-20 13:59:59 +00:00
|
|
|
todo_service.close_issue(issue, current_user)
|
2015-12-17 22:08:14 +00:00
|
|
|
return issue
|
|
|
|
end
|
|
|
|
|
2017-07-10 07:38:42 +00:00
|
|
|
if project.issues_enabled? && issue.close
|
2018-02-09 18:23:55 +00:00
|
|
|
issue.update(closed_by: current_user)
|
2014-04-02 12:38:24 +00:00
|
|
|
event_service.close_issue(issue, current_user)
|
2016-03-15 09:14:39 +00:00
|
|
|
create_note(issue, commit) if system_note
|
|
|
|
notification_service.close_issue(issue, current_user) if notifications
|
2016-02-20 13:59:59 +00:00
|
|
|
todo_service.close_issue(issue, current_user)
|
2014-05-23 13:16:03 +00:00
|
|
|
execute_hooks(issue, 'close')
|
2017-07-11 16:12:33 +00:00
|
|
|
invalidate_cache_counts(issue, users: issue.assignees)
|
2017-09-19 11:55:56 +00:00
|
|
|
issue.update_project_counter_caches
|
2014-04-02 12:38:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
issue
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_note(issue, current_commit)
|
2015-05-09 22:18:50 +00:00
|
|
|
SystemNoteService.change_status(issue, issue.project, current_user, issue.state, current_commit)
|
2014-04-02 12:38:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|