debian-mirror-gitlab/app/services/projects/update_service.rb

68 lines
1.8 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module Projects
class UpdateService < BaseService
def execute
2017-09-10 17:25:29 +05:30
unless visibility_level_allowed?
return error('New visibility level not allowed!')
end
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
if renaming_project_with_container_registry_tags?
return error('Cannot rename project because it contains container registry tags!')
end
2016-08-24 12:49:21 +05:30
2017-09-10 17:25:29 +05:30
if changing_default_branch?
project.change_head(params[:default_branch])
2014-09-02 18:07:02 +05:30
end
2017-09-10 17:25:29 +05:30
project.assign_attributes(params.except(:default_branch))
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
if project.renamed? && !project.can_create_repository?
return error('Cannot rename project because there is already a repository with that new name on disk')
2014-09-02 18:07:02 +05:30
end
2017-09-10 17:25:29 +05:30
if project.save
2014-09-02 18:07:02 +05:30
if project.previous_changes.include?('path')
project.rename_repo
2017-08-17 22:00:37 +05:30
else
system_hook_service.execute_hooks_for(project, :update)
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
success
else
2017-09-10 17:25:29 +05:30
error('Project could not be updated!')
2014-09-02 18:07:02 +05:30
end
end
2017-09-10 17:25:29 +05:30
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
def renaming_project_with_container_registry_tags?
new_path = params[:path]
new_path && new_path != project.path &&
project.has_container_registry_tags?
end
def changing_default_branch?
new_branch = params[:default_branch]
project.repository.exists? &&
new_branch && new_branch != project.default_branch
end
2014-09-02 18:07:02 +05:30
end
end