debian-mirror-gitlab/app/policies/ci/pipeline_schedule_policy.rb

29 lines
823 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Ci
class PipelineSchedulePolicy < PipelinePolicy
2017-09-10 17:25:29 +05:30
alias_method :pipeline_schedule, :subject
2018-03-17 18:26:18 +05:30
condition(:protected_ref) do
ref_protected?(@user, @subject.project, @subject.project.repository.tag_exists?(@subject.ref), @subject.ref)
end
2017-09-10 17:25:29 +05:30
condition(:owner_of_schedule) do
2018-05-09 12:01:36 +05:30
pipeline_schedule.owned_by?(@user)
2017-09-10 17:25:29 +05:30
end
2018-05-09 12:01:36 +05:30
rule { can?(:create_pipeline) }.enable :play_pipeline_schedule
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
rule { can?(:admin_pipeline) | (can?(:update_build) & owner_of_schedule) }.policy do
2017-09-10 17:25:29 +05:30
enable :update_pipeline_schedule
enable :admin_pipeline_schedule
end
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
rule { can?(:admin_pipeline_schedule) & ~owner_of_schedule }.policy do
2018-03-17 18:26:18 +05:30
enable :take_ownership_pipeline_schedule
end
rule { protected_ref }.prevent :play_pipeline_schedule
2017-08-17 22:00:37 +05:30
end
end