2013-01-17 10:35:57 -05:00
|
|
|
module Projects
|
2015-03-07 14:47:06 -05:00
|
|
|
class UpdateService < BaseService
|
2017-09-02 02:59:24 -04:00
|
|
|
include UpdateVisibilityLevel
|
|
|
|
|
2014-06-26 07:30:07 -04:00
|
|
|
def execute
|
2017-09-05 20:10:30 -04:00
|
|
|
unless valid_visibility_level_change?(project, params[:visibility_level])
|
2017-07-13 09:32:31 -04:00
|
|
|
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-08-07 21:10:55 -04:00
|
|
|
return error("Could not set the default branch") unless 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-09-12 17:07:11 -04:00
|
|
|
model_errors = project.errors.full_messages.to_sentence
|
|
|
|
error_message = model_errors.presence || 'Project could not be updated!'
|
|
|
|
|
|
|
|
error(error_message)
|
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
|
|
|
|
|
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
|