11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/bulk_imports/groups/loaders/group_loader.rb', line 11
def load(context, data)
path = data['path']
current_user = context.current_user
destination_namespace = context.entity.destination_namespace
raise(GroupCreationError, 'Path is missing') unless path.present?
raise(GroupCreationError, 'Destination is not a group') if user_namespace_destination?(destination_namespace)
raise(GroupCreationError, 'User not allowed to create group') unless user_can_create_group?(current_user, data)
raise(GroupCreationError, 'Group exists') if group_exists?(destination_namespace, path)
unless two_factor_requirements_met?(current_user, data)
raise(GroupCreationError, 'User requires Two-Factor Authentication')
end
group = ::Groups::CreateService.new(current_user, data).execute
raise(GroupCreationError, group.errors.full_messages.to_sentence) if group.errors.any?
context.entity.update!(group: group)
group
end
|