Class: Members::UpdateService

Inherits:
BaseService show all
Defined in:
app/services/members/update_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#after_execute, #initialize

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?

Constructor Details

This class inherits a constructor from Members::BaseService

Instance Method Details

#execute(member, permission: :update) ⇒ Object

returns the updated member


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

def execute(member, permission: :update)
  raise Gitlab::Access::AccessDeniedError unless can?(current_user, action_member_permission(permission, member), member)

  old_access_level = member.human_access
  old_expiry = member.expires_at

  if member.update(params)
    after_execute(action: permission, old_access_level: old_access_level, old_expiry: old_expiry, member: member)

    # Deletes only confidential issues todos for guests
    enqueue_delete_todos(member) if downgrading_to_guest?
  end

  if member.errors.any?
    error(member.errors.full_messages.to_sentence, pass_back: { member: member })
  else
    success(member: member)
  end
end