gitlab-org--gitlab-foss/app/policies/ci/pipeline_policy.rb
2018-05-15 08:18:22 +00:00

27 lines
728 B
Ruby

module Ci
class PipelinePolicy < BasePolicy
delegate { @subject.project }
condition(:protected_ref) { ref_protected?(@user, @subject.project, @subject.tag?, @subject.ref) }
condition(:branch_allows_maintainer_push) do
@subject.project.branch_allows_maintainer_push?(@user, @subject.ref)
end
rule { protected_ref }.prevent :update_pipeline
rule { can?(:public_access) & branch_allows_maintainer_push }.policy do
enable :update_pipeline
end
def ref_protected?(user, project, tag, ref)
access = ::Gitlab::UserAccess.new(user, project: project)
if tag
!access.can_create_tag?(ref)
else
!access.can_update_branch?(ref)
end
end
end
end