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
|
2020-07-21 14:09:45 -04:00
|
|
|
access = ::Gitlab::UserAccess.new(@user, container: @subject.project)
|
2017-07-17 04:49:54 -04:00
|
|
|
|
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
|
|
|
|
|
2020-05-12 11:10:33 -04:00
|
|
|
condition(:unprotected_ref) do
|
|
|
|
if @subject.tag?
|
|
|
|
!ProtectedTag.protected?(@subject.project, @subject.ref)
|
|
|
|
else
|
|
|
|
!ProtectedBranch.protected?(@subject.project, @subject.ref)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-31 05:10:44 -04:00
|
|
|
# overridden in EE
|
|
|
|
condition(:protected_environment_access) do
|
|
|
|
false
|
|
|
|
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
|
|
|
|
|
2020-05-25 11:07:58 -04:00
|
|
|
condition(:is_web_ide_terminal, scope: :subject) do
|
|
|
|
@subject.pipeline.webide?
|
|
|
|
end
|
|
|
|
|
2020-08-31 05:10:44 -04:00
|
|
|
rule { ~protected_environment_access & (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
|
|
|
|
|
2020-05-12 11:10:33 -04:00
|
|
|
rule { can?(:admin_build) | (can?(:update_build) & owner_of_job & unprotected_ref) }.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
|
2020-05-25 11:07:58 -04:00
|
|
|
|
2020-10-13 05:08:27 -04:00
|
|
|
rule { can?(:update_build) }.enable :play_job
|
|
|
|
|
2020-05-25 11:07:58 -04:00
|
|
|
rule { is_web_ide_terminal & can?(:create_web_ide_terminal) & (admin | owner_of_job) }.policy do
|
|
|
|
enable :read_web_ide_terminal
|
|
|
|
enable :update_web_ide_terminal
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { is_web_ide_terminal & ~can?(:update_web_ide_terminal) }.policy do
|
|
|
|
prevent :create_build_terminal
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { can?(:update_web_ide_terminal) & terminal }.policy do
|
|
|
|
enable :create_build_terminal
|
|
|
|
enable :create_build_service_proxy
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { ~can?(:build_service_proxy_enabled) }.policy do
|
|
|
|
prevent :create_build_service_proxy
|
|
|
|
end
|
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')
|