gitlab-org--gitlab-foss/app/policies/ci/build_policy.rb

34 lines
866 B
Ruby
Raw Normal View History

2016-08-16 15:05:44 -04:00
module Ci
class BuildPolicy < CommitStatusPolicy
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
condition(:owner_of_job) do
@subject.triggered_by?(@user)
2017-11-06 08:20:44 -05:00
end
condition(:branch_allows_maintainer_push) do
@subject.project.branch_allows_maintainer_push?(@user, @subject.ref)
end
rule { protected_ref }.policy do
prevent :update_build
prevent :erase_build
end
rule { can?(:admin_build) | (can?(:update_build) & owner_of_job) }.enable :erase_build
rule { can?(:public_access) & branch_allows_maintainer_push }.policy do
enable :update_build
enable :update_commit_status
end
2016-08-16 15:05:44 -04:00
end
end