2018-07-24 10:00:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-21 10:16:39 +00:00
|
|
|
module Ci
|
2017-04-12 10:19:39 +00:00
|
|
|
class PipelinePolicy < BasePolicy
|
2017-07-03 21:20:44 +00:00
|
|
|
delegate { @subject.project }
|
2017-07-03 21:01:05 +00:00
|
|
|
|
2017-12-08 07:49:55 +00:00
|
|
|
condition(:protected_ref) { ref_protected?(@user, @subject.project, @subject.tag?, @subject.ref) }
|
2017-07-18 13:56:28 +00:00
|
|
|
|
2018-05-23 01:54:57 +00:00
|
|
|
condition(:branch_allows_collaboration) do
|
|
|
|
@subject.project.branch_allows_collaboration?(@user, @subject.ref)
|
2018-05-15 08:18:22 +00:00
|
|
|
end
|
|
|
|
|
2019-01-28 12:12:30 +00:00
|
|
|
condition(:external_pipeline, scope: :subject, score: 0) do
|
|
|
|
@subject.external?
|
|
|
|
end
|
|
|
|
|
2019-04-09 14:53:44 +00:00
|
|
|
condition(:triggerer_of_pipeline) do
|
|
|
|
@subject.triggered_by?(@user)
|
|
|
|
end
|
|
|
|
|
2019-01-28 12:12:30 +00:00
|
|
|
# Disallow users without permissions from accessing internal pipelines
|
|
|
|
rule { ~can?(:read_build) & ~external_pipeline }.policy do
|
|
|
|
prevent :read_pipeline
|
|
|
|
end
|
|
|
|
|
2017-12-08 07:49:55 +00:00
|
|
|
rule { protected_ref }.prevent :update_pipeline
|
|
|
|
|
2018-05-23 01:54:57 +00:00
|
|
|
rule { can?(:public_access) & branch_allows_collaboration }.policy do
|
2018-05-15 08:18:22 +00:00
|
|
|
enable :update_pipeline
|
|
|
|
end
|
|
|
|
|
2018-11-13 16:17:01 +00:00
|
|
|
rule { can?(:owner_access) }.policy do
|
|
|
|
enable :destroy_pipeline
|
|
|
|
end
|
|
|
|
|
2019-04-09 14:53:44 +00:00
|
|
|
rule { can?(:admin_pipeline) }.policy do
|
|
|
|
enable :read_pipeline_variable
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { can?(:update_pipeline) & triggerer_of_pipeline }.policy do
|
|
|
|
enable :read_pipeline_variable
|
|
|
|
end
|
|
|
|
|
2017-12-08 07:49:55 +00:00
|
|
|
def ref_protected?(user, project, tag, ref)
|
2020-07-21 18:09:45 +00:00
|
|
|
access = ::Gitlab::UserAccess.new(user, container: project)
|
2017-12-08 07:49:55 +00:00
|
|
|
|
|
|
|
if tag
|
|
|
|
!access.can_create_tag?(ref)
|
2017-07-18 13:56:28 +00:00
|
|
|
else
|
2017-12-08 07:49:55 +00:00
|
|
|
!access.can_update_branch?(ref)
|
2017-07-18 13:56:28 +00:00
|
|
|
end
|
2017-07-03 21:01:05 +00:00
|
|
|
end
|
2016-10-21 10:16:39 +00:00
|
|
|
end
|
|
|
|
end
|