2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-18 12:52:35 -04:00
|
|
|
module Ci
|
|
|
|
class RunnerPolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
with_options scope: :subject, score: 0
|
|
|
|
condition(:locked, scope: :subject) { @subject.locked? }
|
2016-08-18 12:52:35 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-05-10 08:42:55 -04:00
|
|
|
condition(:owned_runner) { @user.ci_owned_runners.exists?(@subject.id) }
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-08-18 12:52:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { anonymous }.prevent_all
|
2018-05-16 03:56:28 -04:00
|
|
|
|
|
|
|
rule { admin | owned_runner }.policy do
|
|
|
|
enable :assign_runner
|
|
|
|
enable :read_runner
|
|
|
|
enable :update_runner
|
|
|
|
enable :delete_runner
|
|
|
|
end
|
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { ~admin & locked }.prevent :assign_runner
|
2016-08-18 12:52:35 -04:00
|
|
|
end
|
|
|
|
end
|