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

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

51 lines
1.3 KiB
Ruby
Raw Normal View History

2022-01-26 12:08:38 +05:30
# frozen_string_literal: true
module MergeRequests
class RemoveAttentionRequestedService < MergeRequests::BaseService
2022-07-16 23:28:13 +05:30
attr_accessor :merge_request, :user
2022-01-26 12:08:38 +05:30
2022-07-16 23:28:13 +05:30
def initialize(project:, current_user:, merge_request:, user:)
2022-01-26 12:08:38 +05:30
super(project: project, current_user: current_user)
@merge_request = merge_request
2022-07-16 23:28:13 +05:30
@user = user
2022-01-26 12:08:38 +05:30
end
def execute
return error("Invalid permissions") unless can?(current_user, :update_merge_request, merge_request)
if reviewer || assignee
2022-07-16 23:28:13 +05:30
return success if reviewer&.reviewed? || assignee&.reviewed?
2022-01-26 12:08:38 +05:30
update_state(reviewer)
update_state(assignee)
2022-07-16 23:28:13 +05:30
user.invalidate_attention_requested_count
create_remove_attention_request_note
2022-05-07 20:08:51 +05:30
2022-01-26 12:08:38 +05:30
success
else
error("User is not a reviewer or assignee of the merge request")
end
end
private
def assignee
2022-07-16 23:28:13 +05:30
@assignee ||= merge_request.find_assignee(user)
2022-01-26 12:08:38 +05:30
end
def reviewer
2022-07-16 23:28:13 +05:30
@reviewer ||= merge_request.find_reviewer(user)
2022-01-26 12:08:38 +05:30
end
def update_state(reviewer_or_assignee)
reviewer_or_assignee&.update(state: :reviewed)
end
2022-07-16 23:28:13 +05:30
def create_remove_attention_request_note
SystemNoteService.remove_attention_request(merge_request, merge_request.project, current_user, user)
end
2022-01-26 12:08:38 +05:30
end
end