Class: Members::CreateService

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

Direct Known Subclasses

InviteService

Constant Summary collapse

BlankInvitesError =
Class.new(StandardError)
TooManyInvitesError =
Class.new(StandardError)
MembershipLockedError =
Class.new(StandardError)
DEFAULT_INVITE_LIMIT =
100

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

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(*args) ⇒ CreateService

Returns a new instance of CreateService.


13
14
15
16
17
18
19
20
# File 'app/services/members/create_service.rb', line 13

def initialize(*args)
  super

  @errors = []
  @invites = invites_from_params
  @source = params[:source]
  @tasks_to_be_done_members = []
end

Instance Attribute Details

#membership_lockedObject (readonly)

Returns the value of attribute membership_locked.


11
12
13
# File 'app/services/members/create_service.rb', line 11

def membership_locked
  @membership_locked
end

Instance Method Details

#executeObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/members/create_service.rb', line 22

def execute
  raise Gitlab::Access::AccessDeniedError unless can?(current_user, create_member_permission(source), source)

  validate_invite_source!
  validate_invitable!

  add_members
  create_tasks_to_be_done
  enqueue_onboarding_progress_action

  publish_event!

  result
rescue BlankInvitesError, TooManyInvitesError, MembershipLockedError => e
  error(e.message)
end

#single_memberObject


39
40
41
# File 'app/services/members/create_service.rb', line 39

def single_member
  members.last
end