Class: Issues::CloseService

Inherits:
BaseService show all
Defined in:
app/services/issues/close_service.rb

Constant Summary

Constants inherited from BaseService

BaseService::NO_REBALANCING_NEEDED

Constants included from Gitlab::Utils::UsageData

Gitlab::Utils::UsageData::FALLBACK

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#close_service, #hook_data, #rebalance_if_needed, #reopen_service

Methods included from IncidentManagement::UsageData

#track_event, #track_incident_action

Methods included from Gitlab::Utils::UsageData

#alt_usage_data, #count, #distinct_count, #measure_duration, #redis_usage_data, #track_usage_event, #with_finished_at, #with_prometheus_client

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Instance Method Details

#close_issue(issue, closed_via: nil, notifications: true, system_note: true) ⇒ Object

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.


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
# File 'app/services/issues/close_service.rb', line 20

def close_issue(issue, closed_via: nil, notifications: true, system_note: true)
  if issue.is_a?(ExternalIssue)
    close_external_issue(issue, closed_via)

    return issue
  end

  if project.issues_enabled? && issue.close
    issue.update(closed_by: current_user)
    event_service.close_issue(issue, current_user)
    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
    todo_service.close_issue(issue, current_user)
    resolve_alert(issue)
    execute_hooks(issue, 'close')
    invalidate_cache_counts(issue, users: issue.assignees)
    issue.update_project_counter_caches
    track_incident_action(current_user, issue, :incident_closed)

    store_first_mentioned_in_commit_at(issue, closed_via) if closed_via.is_a?(MergeRequest)

    delete_milestone_closed_issue_counter_cache(issue.milestone)
  end

  issue
end

#execute(issue, commit: nil, notifications: true, system_note: true) ⇒ Object

Closes the supplied issue if the current user is able to do so.


6
7
8
9
10
11
12
13
# File 'app/services/issues/close_service.rb', line 6

def execute(issue, commit: nil, notifications: true, system_note: true)
  return issue unless can?(current_user, :update_issue, issue) || issue.is_a?(ExternalIssue)

  close_issue(issue,
              closed_via: commit,
              notifications: notifications,
              system_note: system_note)
end