summaryrefslogtreecommitdiff
path: root/app/policies/ci/pipeline_policy.rb
blob: 4e689a9efd502cad88bdc7d33bcde26afb922cd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Ci
  class PipelinePolicy < BasePolicy
    delegate { @subject.project }

    condition(:protected_ref) do
      access = ::Gitlab::UserAccess.new(@user, project: @subject.project)

      if @subject.tag?
        !access.can_create_tag?(@subject.ref)
      else
        !access.can_update_branch?(@subject.ref)
      end
    end

    rule { protected_ref }.prevent :update_pipeline
  end
end