summaryrefslogtreecommitdiff
path: root/app/services/issues/reopen_service.rb
blob: 0ffe33dd317b699b304bd3c1d165a48121b7fd5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module Issues
  class ReopenService < Issues::BaseService
    def execute(issue)
      return issue unless can?(current_user, :reopen_issue, issue)

      if issue.reopen
        event_service.reopen_issue(issue, current_user)
        create_note(issue, 'reopened')
        notification_service.async.reopen_issue(issue, current_user)
        execute_hooks(issue, 'reopen')
        invalidate_cache_counts(issue, users: issue.assignees)
        issue.update_project_counter_caches
        delete_milestone_closed_issue_counter_cache(issue.milestone)
      end

      issue
    end

    private

    def create_note(issue, state = issue.state)
      SystemNoteService.change_status(issue, issue.project, current_user, state, nil)
    end
  end
end