2016-10-21 06:16:39 -04:00
|
|
|
module Ci
|
2017-04-12 06:19:39 -04:00
|
|
|
class PipelinePolicy < BasePolicy
|
2017-07-03 17:20:44 -04:00
|
|
|
delegate { @subject.project }
|
2017-07-03 17:01:05 -04:00
|
|
|
|
2017-12-08 02:49:55 -05:00
|
|
|
condition(:protected_ref) { ref_protected?(@user, @subject.project, @subject.tag?, @subject.ref) }
|
2017-07-18 09:56:28 -04:00
|
|
|
|
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-12-08 02:49:55 -05:00
|
|
|
rule { protected_ref }.prevent :update_pipeline
|
|
|
|
|
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_pipeline
|
|
|
|
end
|
|
|
|
|
2017-12-08 02:49:55 -05:00
|
|
|
def ref_protected?(user, project, tag, ref)
|
|
|
|
access = ::Gitlab::UserAccess.new(user, project: project)
|
|
|
|
|
|
|
|
if tag
|
|
|
|
!access.can_create_tag?(ref)
|
2017-07-18 09:56:28 -04:00
|
|
|
else
|
2017-12-08 02:49:55 -05:00
|
|
|
!access.can_update_branch?(ref)
|
2017-07-18 09:56:28 -04:00
|
|
|
end
|
2017-07-03 17:01:05 -04:00
|
|
|
end
|
2016-10-21 06:16:39 -04:00
|
|
|
end
|
|
|
|
end
|