Class: MergeRequests::RemoveApprovalService

Inherits:
BaseService show all
Defined in:
app/services/merge_requests/remove_approval_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#cancel_review_app_jobs!, #cleanup_environments, #execute_hooks, #hook_data, #inspect, #source_project, #target_project

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from AssignsMergeParams

#assign_allowed_merge_params, included

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

#execute(merge_request) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/merge_requests/remove_approval_service.rb', line 6

def execute(merge_request)
  return unless merge_request.approved_by?(current_user)

  # paranoid protection against running wrong deletes
  return unless merge_request.id && current_user.id

  approval = merge_request.approvals.where(user: current_user)

  trigger_approval_hooks(merge_request) do
    next unless approval.destroy_all # rubocop: disable Cop/DestroyAll

    reset_approvals_cache(merge_request)
    create_note(merge_request)
  end

  success
end