Commit 9626d17d authored by Justin Farmiloe's avatar Justin Farmiloe Committed by Stan Hu

Improve deploy key script code following review

parent 74f9a987
...@@ -321,23 +321,23 @@ DeployKeysProject.with_write_access.find_each do |deploy_key_mapping| ...@@ -321,23 +321,23 @@ DeployKeysProject.with_write_access.find_each do |deploy_key_mapping|
access_checker = Gitlab::DeployKeyAccess.new(deploy_key, container: project) access_checker = Gitlab::DeployKeyAccess.new(deploy_key, container: project)
# Can_push_for_ref? tests if deploy_key can push to specified (possibly protected) branch - change branch name below as required # can_push_for_ref? tests if deploy_key can push to default branch, which is likely to be protected
# can_push = access_checker.can_do_action?(:push_code)
branch = project.repository.root_ref #default branch can_push_to_default = access_checker.can_push_for_ref?(project.repository.root_ref)
#branch = 'b1'
next if access_checker.allowed? && can_push && can_push_to_default
next if access_checker.allowed? && access_checker.can_do_action?(:push_code) && access_checker.can_push_for_ref?(branch)
if user.nil? || user.id == ghost_user_id if user.nil? || user.id == ghost_user_id
user.username = 'none' username = 'none'
user.state = '-' state = '-'
else
username = user.username
user_state = user.state
end end
puts "Deploy key: #{deploy_key.id}, Project: #{project.full_path}, Can push?: " + (access_checker.can_do_action?(:push_code) ? 'YES' : 'NO') + puts "Deploy key: #{deploy_key.id}, Project: #{project.full_path}, Can push?: " + (can_push ? 'YES' : 'NO') +
", Can push to branch #{branch}?: " + (access_checker.can_push_for_ref?(project.repository.root_ref) ? 'YES' : 'NO') + ", Can push to default branch #{project.repository.root_ref}?: " + (can_push_to_default ? 'YES' : 'NO') +
", User: #{user.username}, User state: #{user.state}" ", User: #{username}, User state: #{user_state}"
end end
``` ```
......
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