2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 15:05:44 -04:00
|
|
|
module Ci
|
|
|
|
class BuildPolicy < CommitStatusPolicy
|
2017-07-18 10:13:57 -04:00
|
|
|
condition(:protected_ref) do
|
2017-07-17 04:49:54 -04:00
|
|
|
access = ::Gitlab::UserAccess.new(@user, project: @subject.project)
|
|
|
|
|
2017-07-18 04:31:29 -04:00
|
|
|
if @subject.tag?
|
2017-07-17 04:49:54 -04:00
|
|
|
!access.can_create_tag?(@subject.ref)
|
2017-07-18 04:31:29 -04:00
|
|
|
else
|
2017-07-18 09:56:28 -04:00
|
|
|
!access.can_update_branch?(@subject.ref)
|
2017-07-18 04:31:29 -04:00
|
|
|
end
|
2017-04-12 05:26:18 -04:00
|
|
|
end
|
|
|
|
|
2017-11-06 12:47:05 -05:00
|
|
|
condition(:owner_of_job) do
|
2018-04-02 14:38:47 -04:00
|
|
|
@subject.triggered_by?(@user)
|
2017-11-06 08:20:44 -05:00
|
|
|
end
|
|
|
|
|
2018-05-22 21:54:57 -04:00
|
|
|
condition(:branch_allows_collaboration) do
|
|
|
|
@subject.project.branch_allows_collaboration?(@user, @subject.ref)
|
2018-05-15 04:18:22 -04:00
|
|
|
end
|
|
|
|
|
2018-10-23 06:58:41 -04:00
|
|
|
condition(:archived, scope: :subject) do
|
|
|
|
@subject.archived?
|
|
|
|
end
|
|
|
|
|
2018-07-05 09:55:10 -04:00
|
|
|
condition(:terminal, scope: :subject) do
|
|
|
|
@subject.has_terminal?
|
|
|
|
end
|
|
|
|
|
2018-10-23 06:58:41 -04:00
|
|
|
rule { protected_ref | archived }.policy do
|
2017-11-06 12:47:05 -05:00
|
|
|
prevent :update_build
|
2018-10-23 06:58:41 -04:00
|
|
|
prevent :update_commit_status
|
2017-11-06 12:47:05 -05:00
|
|
|
prevent :erase_build
|
|
|
|
end
|
|
|
|
|
2018-04-02 14:38:47 -04:00
|
|
|
rule { can?(:admin_build) | (can?(:update_build) & owner_of_job) }.enable :erase_build
|
2018-05-15 04:18:22 -04:00
|
|
|
|
2018-05-22 21:54:57 -04:00
|
|
|
rule { can?(:public_access) & branch_allows_collaboration }.policy do
|
2018-05-15 04:18:22 -04:00
|
|
|
enable :update_build
|
|
|
|
enable :update_commit_status
|
|
|
|
end
|
2018-07-05 09:55:10 -04:00
|
|
|
|
|
|
|
rule { can?(:update_build) & terminal }.enable :create_build_terminal
|
2016-08-16 15:05:44 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Ci::BuildPolicy.prepend_if_ee('EE::Ci::BuildPolicy')
|