close_service.rb 1.5 KB
Newer Older
1
module Issues
D
Dmitriy Zaporozhets 已提交
2
  class CloseService < Issues::BaseService
3
    # Closes the supplied issue if the current user is able to do so.
4
    def execute(issue, commit: nil, notifications: true, system_note: true)
5 6
      return issue unless can?(current_user, :update_issue, issue)

7 8 9 10 11 12 13 14 15 16 17 18
      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)
19
      if project.jira_tracker? && project.jira_service.active && issue.is_a?(ExternalIssue)
20
        project.jira_service.close_issue(commit, issue)
21
        todo_service.close_issue(issue, current_user)
D
Drew Blessing 已提交
22 23 24
        return issue
      end

25
      if project.issues_enabled? && issue.close
26
        event_service.close_issue(issue, current_user)
27 28
        create_note(issue, commit) if system_note
        notification_service.close_issue(issue, current_user) if notifications
29
        todo_service.close_issue(issue, current_user)
30
        execute_hooks(issue, 'close')
31
        invalidate_cache_counts(issue, users: issue.assignees)
32 33 34 35 36 37 38 39
      end

      issue
    end

    private

    def create_note(issue, current_commit)
40
      SystemNoteService.change_status(issue, issue.project, current_user, issue.state, current_commit)
41 42 43
    end
  end
end