2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-31 08:54:38 -04:00
|
|
|
class DeployKeyPolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
with_options scope: :subject, score: 0
|
|
|
|
condition(:private_deploy_key) { @subject.private? }
|
2017-03-31 08:54:38 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:has_deploy_key) { @user.project_deploy_keys.exists?(id: @subject.id) }
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-31 08:54:38 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { anonymous }.prevent_all
|
|
|
|
|
|
|
|
rule { admin }.enable :update_deploy_key
|
|
|
|
rule { private_deploy_key & has_deploy_key }.enable :update_deploy_key
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|