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
|
2013-11-06 10:13:21 -05:00
|
|
|
# check that user is allowed to set specified visibility_level
|
2015-03-07 13:23:43 -05:00
|
|
|
new_visibility = params[:visibility_level]
|
2016-07-25 23:27:46 -04:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
if new_visibility && new_visibility.to_i != project.visibility_level
|
|
|
|
unless can?(current_user, :change_visibility_level, project) &&
|
2016-12-15 17:14:20 -05:00
|
|
|
Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
|
2016-07-06 09:26:59 -04:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
deny_visibility_level(project, new_visibility)
|
2017-01-15 01:58:05 -05:00
|
|
|
return error('Visibility level unallowed')
|
2015-03-07 13:23:43 -05:00
|
|
|
end
|
2015-11-03 12:23:48 -05:00
|
|
|
end
|
|
|
|
|
2014-06-26 16:24:17 -04:00
|
|
|
new_branch = params[:default_branch]
|
2013-11-06 11:45:39 -05:00
|
|
|
|
2013-12-23 06:19:13 -05:00
|
|
|
if project.repository.exists? && new_branch && new_branch != project.default_branch
|
2013-12-16 12:34:56 -05:00
|
|
|
project.change_head(new_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
|
|
|
|
error('Project could not be updated')
|
2014-06-17 14:53:26 -04:00
|
|
|
end
|
2013-01-17 10:35:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|