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

51 lines
1.8 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 CloseService < Issues::BaseService
2017-08-17 22:00:37 +05:30
# Closes the supplied issue if the current user is able to do so.
2016-06-02 11:05:42 +05:30
def execute(issue, commit: nil, notifications: true, system_note: true)
2019-12-21 20:55:43 +05:30
return issue unless can?(current_user, :update_issue, issue) || issue.is_a?(ExternalIssue)
2016-09-13 17:45:13 +05:30
2017-08-17 22:00:37 +05:30
close_issue(issue,
2019-09-04 21:01:54 +05:30
closed_via: commit,
2017-08-17 22:00:37 +05:30
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.
2019-09-04 21:01:54 +05:30
def close_issue(issue, closed_via: nil, notifications: true, system_note: true)
2019-12-21 20:55:43 +05:30
if project.jira_tracker_active? && issue.is_a?(ExternalIssue)
2019-09-04 21:01:54 +05:30
project.jira_service.close_issue(closed_via, issue)
2016-04-02 18:10:28 +05:30
todo_service.close_issue(issue, current_user)
2015-12-23 02:04:40 +05:30
return issue
end
2017-09-10 17:25:29 +05:30
if project.issues_enabled? && issue.close
2018-05-09 12:01:36 +05:30
issue.update(closed_by: current_user)
2014-09-02 18:07:02 +05:30
event_service.close_issue(issue, current_user)
2019-09-04 21:01:54 +05:30
create_note(issue, closed_via) if system_note
closed_via = _("commit %{commit_id}") % { commit_id: closed_via.id } if closed_via.is_a?(Commit)
notification_service.async.close_issue(issue, current_user, closed_via: closed_via) if notifications
2016-04-02 18:10:28 +05:30
todo_service.close_issue(issue, current_user)
2014-09-02 18:07:02 +05:30
execute_hooks(issue, 'close')
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
2014-09-02 18:07:02 +05:30
end
issue
end
private
def create_note(issue, current_commit)
2015-09-11 14:41:01 +05:30
SystemNoteService.change_status(issue, issue.project, current_user, issue.state, current_commit)
2014-09-02 18:07:02 +05:30
end
end
end