Commit 9fc10b1b authored by Michael Kozono's avatar Michael Kozono

Dry up method for code climate

parent c2c6c4c6
module UpdateVisibilityLevel
def visibility_level_allowed?(target, new_visibility)
# check that user is allowed to set specified visibility_level
if new_visibility && new_visibility.to_i != target.visibility_level
unless can?(current_user, :change_visibility_level, target) &&
Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
deny_visibility_level(target, new_visibility)
return false
end
end
true
end
end
module Groups
class UpdateService < Groups::BaseService
include UpdateVisibilityLevel
def execute
reject_parent_id!
# check that user is allowed to set specified visibility_level
new_visibility = params[:visibility_level]
if new_visibility && new_visibility.to_i != group.visibility_level
unless can?(current_user, :change_visibility_level, group) &&
Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
deny_visibility_level(group, new_visibility)
return false
end
end
return false unless visibility_level_allowed?(group, params[:visibility_level])
return false unless valid_share_with_group_lock_change?
......
module Projects
class UpdateService < BaseService
include UpdateVisibilityLevel
def execute
unless visibility_level_allowed?
unless visibility_level_allowed?(project, params[:visibility_level])
return error('New visibility level not allowed!')
end
......@@ -28,22 +30,6 @@ module Projects
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]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment