summaryrefslogtreecommitdiff
path: root/app/services/issues/base_service.rb
blob: 735257c47795cdea56626076b95d82a3d63a2295 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module Issues
  class BaseService < ::IssuableBaseService
    def hook_data(issue, action, old_labels: [], old_assignees: [])
      hook_data = issue.to_hook_data(current_user, old_labels: old_labels, old_assignees: old_assignees)
      hook_data[:object_attributes][:action] = action

      hook_data
    end

    def reopen_service
      Issues::ReopenService
    end

    def close_service
      Issues::CloseService
    end

    private

    def create_assignee_note(issue, old_assignees)
      SystemNoteService.change_issue_assignees(
        issue, issue.project, current_user, old_assignees)
    end

    def execute_hooks(issue, action = 'open', old_labels: [], old_assignees: [])
      issue_data  = hook_data(issue, action, old_labels: old_labels, old_assignees: old_assignees)
      hooks_scope = issue.confidential? ? :confidential_issue_hooks : :issue_hooks
      issue.project.execute_hooks(issue_data, hooks_scope)
      issue.project.execute_services(issue_data, hooks_scope)
    end

    def filter_assignee(issuable)
      return if params[:assignee_ids].blank?

      # The number of assignees is limited by one for GitLab CE
      params[:assignee_ids] = params[:assignee_ids][0, 1]

      assignee_ids = params[:assignee_ids].select { |assignee_id| assignee_can_read?(issuable, assignee_id) }

      if params[:assignee_ids].map(&:to_s) == [IssuableFinder::NONE]
        params[:assignee_ids] = []
      elsif assignee_ids.any?
        params[:assignee_ids] = assignee_ids
      else
        params.delete(:assignee_ids)
      end
    end
  end
end