Class: MergeRequests::ToggleAttentionRequestedService

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

Instance Attribute Summary collapse

Attributes inherited from BaseProjectService

#project

Attributes inherited from BaseContainerService

#container, #current_user, #params

Instance Method Summary collapse

Methods inherited from BaseService

#cancel_review_app_jobs!, #cleanup_environments, #create_note, #execute_external_hooks, #execute_hooks, #handle_assignees_change, #handle_changes, #handle_reviewers_change, #hook_data, #inspect, #merge_request_activity_counter, #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 included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BaseContainerService

#group_container?, #namespace_container?, #project_container?

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?

Constructor Details

#initialize(project:, current_user:, merge_request:, user:) ⇒ ToggleAttentionRequestedService

Returns a new instance of ToggleAttentionRequestedService.


7
8
9
10
11
12
# File 'app/services/merge_requests/toggle_attention_requested_service.rb', line 7

def initialize(project:, current_user:, merge_request:, user:)
  super(project: project, current_user: current_user)

  @merge_request = merge_request
  @user = user
end

Instance Attribute Details

#merge_requestObject

Returns the value of attribute merge_request.


5
6
7
# File 'app/services/merge_requests/toggle_attention_requested_service.rb', line 5

def merge_request
  @merge_request
end

#userObject

Returns the value of attribute user.


5
6
7
# File 'app/services/merge_requests/toggle_attention_requested_service.rb', line 5

def user
  @user
end

Instance Method Details

#executeObject


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
# File 'app/services/merge_requests/toggle_attention_requested_service.rb', line 14

def execute
  return error("Invalid permissions") unless can?(current_user, :update_merge_request, merge_request)

  if reviewer || assignee
    update_state(reviewer)
    update_state(assignee)

    user.invalidate_attention_requested_count

    if reviewer&.attention_requested? || assignee&.attention_requested?
      create_attention_request_note
      notity_user

      if current_user.id != user.id
        remove_attention_requested(merge_request)
      end
    else
      create_remove_attention_request_note
    end

    success
  else
    error("User is not a reviewer or assignee of the merge request")
  end
end