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
|
|
|
|
|
2017-11-06 12:47:05 -05:00
|
|
|
rule { protected_ref }.policy do
|
|
|
|
prevent :update_build
|
|
|
|
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
|
2016-08-16 15:05:44 -04:00
|
|
|
end
|
|
|
|
end
|