2016-03-16 22:44:33 +00:00
|
|
|
module Groups
|
|
|
|
class CreateService < Groups::BaseService
|
2016-03-17 22:42:46 +00:00
|
|
|
def initialize(user, params = {})
|
|
|
|
@current_user, @params = user, params.dup
|
2017-02-20 12:41:50 +00:00
|
|
|
@chat_team = @params.delete(:create_chat_team)
|
2016-03-16 22:44:33 +00:00
|
|
|
end
|
|
|
|
|
2016-03-17 22:42:46 +00:00
|
|
|
def execute
|
2016-03-18 12:28:16 +00:00
|
|
|
@group = Group.new(params)
|
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level])
|
|
|
|
deny_visibility_level(@group)
|
|
|
|
return @group
|
|
|
|
end
|
2016-03-18 12:28:16 +00:00
|
|
|
|
2016-12-29 17:18:05 +00: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 09:56:19 +00:00
|
|
|
|
2016-12-29 17:18:05 +00:00
|
|
|
return @group
|
2016-12-26 09:56:19 +00:00
|
|
|
end
|
|
|
|
|
2016-03-21 23:09:20 +00:00
|
|
|
@group.name ||= @group.path.dup
|
2017-02-02 14:04:02 +00:00
|
|
|
|
2017-02-20 12:41:50 +00:00
|
|
|
if create_chat_team?
|
2017-03-06 13:06:33 +00:00
|
|
|
response = Mattermost::CreateTeamService.new(@group, current_user).execute
|
2017-02-20 12:41:50 +00:00
|
|
|
return @group if @group.errors.any?
|
2017-03-06 13:06:33 +00:00
|
|
|
|
|
|
|
@group.build_chat_team(name: response['name'], team_id: response['id'])
|
2017-02-02 14:04:02 +00:00
|
|
|
end
|
|
|
|
|
2017-02-20 12:41:50 +00:00
|
|
|
@group.save
|
|
|
|
@group.add_owner(current_user)
|
2016-03-17 22:42:46 +00:00
|
|
|
@group
|
2016-03-16 22:44:33 +00:00
|
|
|
end
|
2017-03-01 19:34:29 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_chat_team?
|
|
|
|
Gitlab.config.mattermost.enabled && @chat_team && group.chat_team.nil?
|
|
|
|
end
|
2016-03-16 22:44:33 +00:00
|
|
|
end
|
|
|
|
end
|