Class: AuthorizedProjectUpdate::ProjectCreateService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/authorized_project_update/project_create_service.rb

Constant Summary collapse

BATCH_SIZE =
1000

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params

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(project) ⇒ ProjectCreateService

Returns a new instance of ProjectCreateService.


7
8
9
# File 'app/services/authorized_project_update/project_create_service.rb', line 7

def initialize(project)
  @project = project
end

Instance Method Details

#executeObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/authorized_project_update/project_create_service.rb', line 11

def execute
  group = project.group

  unless group
    return ServiceResponse.error(message: 'Project does not have a group')
  end

  group.members_from_self_and_ancestors_with_effective_access_level
       .each_batch(of: BATCH_SIZE, column: :user_id) do |members|
    attributes = members.map do |member|
      { user_id: member.user_id, project_id: project.id, access_level: member.access_level }
    end

    ProjectAuthorization.insert_all(attributes) unless attributes.empty?
  end

  ServiceResponse.success
end