debian-mirror-gitlab/app/services/merge_requests/remove_approval_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.5 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module MergeRequests
class RemoveApprovalService < MergeRequests::BaseService
# rubocop: disable CodeReuse/ActiveRecord
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)
2021-03-11 19:13:27 +05:30
merge_request_activity_counter.track_unapprove_mr_action(user: current_user)
2023-01-13 00:05:48 +05:30
trigger_merge_request_merge_status_updated(merge_request)
trigger_merge_request_reviewers_updated(merge_request)
2023-03-04 22:38:38 +05:30
trigger_merge_request_approval_state_updated(merge_request)
2020-07-28 23:09:34 +05:30
end
success
end
# rubocop: enable CodeReuse/ActiveRecord
private
def reset_approvals_cache(merge_request)
merge_request.approvals.reset
end
def trigger_approval_hooks(merge_request)
yield
2022-07-16 23:28:13 +05:30
notification_service.async.unapprove_mr(merge_request, current_user)
2020-07-28 23:09:34 +05:30
execute_hooks(merge_request, 'unapproved')
end
def create_note(merge_request)
SystemNoteService.unapprove_mr(merge_request, current_user)
end
end
end
2021-06-08 01:23:25 +05:30
MergeRequests::RemoveApprovalService.prepend_mod_with('MergeRequests::RemoveApprovalService')