2013-01-17 10:35:57 -05:00
|
|
|
module Projects
|
2015-03-07 14:47:06 -05:00
|
|
|
class UpdateService < BaseService
|
2014-06-26 07:30:07 -04:00
|
|
|
def execute
|
2017-07-13 09:32:31 -04:00
|
|
|
unless visibility_level_allowed?
|
|
|
|
return error('New visibility level not allowed!')
|
2015-11-03 12:23:48 -05:00
|
|
|
end
|
|
|
|
|
2017-07-24 06:47:33 -04:00
|
|
|
if renaming_project_with_container_registry_tags?
|
2017-07-13 09:32:31 -04:00
|
|
|
return error('Cannot rename project because it contains container registry tags!')
|
|
|
|
end
|
2013-11-06 11:45:39 -05:00
|
|
|
|
2017-07-13 09:32:31 -04:00
|
|
|
if changing_default_branch?
|
2017-07-14 05:21:52 -04:00
|
|
|
project.change_head(params[:default_branch])
|
2013-11-06 11:45:39 -05:00
|
|
|
end
|
|
|
|
|
2014-06-26 16:24:17 -04:00
|
|
|
if project.update_attributes(params.except(:default_branch))
|
2014-06-17 14:53:26 -04:00
|
|
|
if project.previous_changes.include?('path')
|
|
|
|
project.rename_repo
|
2016-08-08 09:31:35 -04:00
|
|
|
else
|
|
|
|
system_hook_service.execute_hooks_for(project, :update)
|
2014-06-17 14:53:26 -04:00
|
|
|
end
|
2017-01-15 01:58:05 -05:00
|
|
|
|
|
|
|
success
|
|
|
|
else
|
2017-07-13 09:32:31 -04:00
|
|
|
error('Project could not be updated!')
|
2014-06-17 14:53:26 -04:00
|
|
|
end
|
2013-01-17 10:35:57 -05:00
|
|
|
end
|
2017-07-13 09:32:31 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def visibility_level_allowed?
|
|
|
|
# check that user is allowed to set specified visibility_level
|
|
|
|
new_visibility = params[:visibility_level]
|
|
|
|
|
|
|
|
if new_visibility && new_visibility.to_i != project.visibility_level
|
|
|
|
unless can?(current_user, :change_visibility_level, project) &&
|
|
|
|
Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
|
|
|
|
|
|
|
|
deny_visibility_level(project, new_visibility)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2017-07-24 06:47:33 -04:00
|
|
|
def renaming_project_with_container_registry_tags?
|
|
|
|
new_path = params[:path]
|
|
|
|
|
|
|
|
new_path && new_path != project.path &&
|
|
|
|
project.has_container_registry_tags?
|
|
|
|
end
|
|
|
|
|
2017-07-13 09:32:31 -04:00
|
|
|
def changing_default_branch?
|
|
|
|
new_branch = params[:default_branch]
|
|
|
|
|
|
|
|
project.repository.exists? &&
|
|
|
|
new_branch && new_branch != project.default_branch
|
|
|
|
end
|
2013-01-17 10:35:57 -05:00
|
|
|
end
|
|
|
|
end
|