summaryrefslogtreecommitdiff
path: root/app/policies/ci/runner_policy.rb
blob: de76b7b2b5b676fa2fc70b09dd5b744d7f3df067 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

module Ci
  class RunnerPolicy < BasePolicy
    with_options scope: :subject, score: 0
    condition(:locked, scope: :subject) { @subject.locked? }

    # rubocop: disable CodeReuse/ActiveRecord
    condition(:owned_runner) { @user.ci_owned_runners.exists?(@subject.id) }
    # rubocop: enable CodeReuse/ActiveRecord

    rule { anonymous }.prevent_all

    rule { admin | owned_runner }.policy do
      enable :assign_runner
      enable :read_runner
      enable :update_runner
      enable :delete_runner
    end

    rule { ~admin & locked }.prevent :assign_runner
  end
end