Class: Projects::GroupLinks::CreateService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/projects/group_links/create_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

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 BaseService

Instance Method Details

#execute(group) ⇒ Object


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

def execute(group)
  return error('Not Found', 404) unless group && can?(current_user, :read_namespace, group)

  link = project.project_group_links.new(
    group: group,
    group_access: params[:link_group_access],
    expires_at: params[:expires_at]
  )

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