gitlab-org--gitlab-foss/app/services/groups/create_service.rb
Dmitriy Zaporozhets 283e868ef5
Refactor nested group related code
* Simplify code around group parent access check
* Rename 'Nested groups' to 'Subgroups' tab at group#show page

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-12-29 19:18:05 +02:00

28 lines
709 B
Ruby

module Groups
class CreateService < Groups::BaseService
def initialize(user, params = {})
@current_user, @params = user, params.dup
end
def execute
@group = Group.new(params)
unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level])
deny_visibility_level(@group)
return @group
end
if @group.parent && !can?(current_user, :admin_group, @group.parent)
@group.parent = nil
@group.errors.add(:parent_id, 'manage access required to create subgroup')
return @group
end
@group.name ||= @group.path.dup
@group.save
@group.add_owner(current_user)
@group
end
end
end