2016-03-16 18:44:33 -04:00
|
|
|
module Groups
|
|
|
|
class CreateService < Groups::BaseService
|
2016-03-17 18:42:46 -04:00
|
|
|
def initialize(user, params = {})
|
|
|
|
@current_user, @params = user, params.dup
|
2016-03-16 18:44:33 -04:00
|
|
|
end
|
|
|
|
|
2016-03-17 18:42:46 -04:00
|
|
|
def execute
|
2016-03-18 08:28:16 -04:00
|
|
|
@group = Group.new(params)
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level])
|
|
|
|
deny_visibility_level(@group)
|
|
|
|
return @group
|
|
|
|
end
|
2016-03-18 08:28:16 -04:00
|
|
|
|
2016-12-29 12:18:05 -05:00
|
|
|
if @group.parent && !can?(current_user, :admin_group, @group.parent)
|
|
|
|
@group.parent = nil
|
|
|
|
@group.errors.add(:parent_id, 'manage access required to create subgroup')
|
2016-12-26 04:56:19 -05:00
|
|
|
|
2016-12-29 12:18:05 -05:00
|
|
|
return @group
|
2016-12-26 04:56:19 -05:00
|
|
|
end
|
|
|
|
|
2016-03-21 19:09:20 -04:00
|
|
|
@group.name ||= @group.path.dup
|
2016-03-17 18:42:46 -04:00
|
|
|
@group.save
|
2016-03-18 08:28:16 -04:00
|
|
|
@group.add_owner(current_user)
|
2016-03-17 18:42:46 -04:00
|
|
|
@group
|
2016-03-16 18:44:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|