2016-06-02 11:05:42 +05:30
|
|
|
module Groups
|
|
|
|
class CreateService < Groups::BaseService
|
|
|
|
def initialize(user, params = {})
|
|
|
|
@current_user, @params = user, params.dup
|
2017-08-17 22:00:37 +05:30
|
|
|
@chat_team = @params.delete(:create_chat_team)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
@group = Group.new(params)
|
|
|
|
|
|
|
|
unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level])
|
|
|
|
deny_visibility_level(@group)
|
|
|
|
return @group
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
@group.name ||= @group.path.dup
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
if create_chat_team?
|
|
|
|
response = Mattermost::CreateTeamService.new(@group, current_user).execute
|
|
|
|
return @group if @group.errors.any?
|
|
|
|
|
|
|
|
@group.build_chat_team(name: response['name'], team_id: response['id'])
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
@group.save
|
|
|
|
@group.add_owner(current_user)
|
|
|
|
@group
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_chat_team?
|
|
|
|
Gitlab.config.mattermost.enabled && @chat_team && group.chat_team.nil?
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|