2014-09-02 18:07:02 +05:30
|
|
|
module Projects
|
|
|
|
class ForkService < BaseService
|
|
|
|
def execute
|
2015-09-11 14:41:01 +05:30
|
|
|
new_params = {
|
|
|
|
forked_from_project_id: @project.id,
|
2016-06-16 23:09:34 +05:30
|
|
|
visibility_level: allowed_visibility_level,
|
2015-09-11 14:41:01 +05:30
|
|
|
description: @project.description,
|
|
|
|
name: @project.name,
|
|
|
|
path: @project.path,
|
2015-12-23 02:04:40 +05:30
|
|
|
shared_runners_enabled: @project.shared_runners_enabled,
|
2015-09-11 14:41:01 +05:30
|
|
|
namespace_id: @params[:namespace].try(:id) || current_user.namespace.id
|
2015-04-26 12:48:37 +05:30
|
|
|
}
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
if @project.avatar.present? && @project.avatar.image?
|
|
|
|
new_params[:avatar] = @project.avatar
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
new_project = CreateService.new(current_user, new_params).execute
|
2016-09-29 09:46:39 +05:30
|
|
|
builds_access_level = @project.project_feature.builds_access_level
|
|
|
|
new_project.project_feature.update_attributes(builds_access_level: builds_access_level)
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
new_project
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def allowed_visibility_level
|
|
|
|
project_level = @project.visibility_level
|
|
|
|
|
|
|
|
if Gitlab::VisibilityLevel.non_restricted_level?(project_level)
|
|
|
|
project_level
|
|
|
|
else
|
|
|
|
Gitlab::VisibilityLevel.highest_allowed_level
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|