Class: Groups::GroupLinks::CreateService

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

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #group, #params

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#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 Groups::BaseService

Instance Method Details

#execute(shared_group) ⇒ Object


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

def execute(shared_group)
  unless group && shared_group &&
         can?(current_user, :admin_group_member, shared_group) &&
         can?(current_user, :read_group, group)
    return error('Not Found', 404)
  end

  link = GroupGroupLink.new(
    shared_group: shared_group,
    shared_with_group: group,
    group_access: params[:shared_group_access],
    expires_at: params[:expires_at]
  )

  if link.save
    group.refresh_members_authorized_projects
    success(link: link)
  else
    error(link.errors.full_messages.to_sentence, 409)
  end
end