2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-07 18:35:56 -04:00
|
|
|
module Ci
|
|
|
|
class PipelineSchedulePolicy < PipelinePolicy
|
2017-06-26 05:25:08 -04:00
|
|
|
alias_method :pipeline_schedule, :subject
|
|
|
|
|
2017-12-06 02:23:59 -05:00
|
|
|
condition(:protected_ref) do
|
2017-12-08 02:49:55 -05:00
|
|
|
ref_protected?(@user, @subject.project, @subject.project.repository.tag_exists?(@subject.ref), @subject.ref)
|
2017-12-06 02:23:59 -05:00
|
|
|
end
|
|
|
|
|
2017-07-07 06:09:35 -04:00
|
|
|
condition(:owner_of_schedule) do
|
2018-04-02 14:38:47 -04:00
|
|
|
pipeline_schedule.owned_by?(@user)
|
2017-06-28 08:42:13 -04:00
|
|
|
end
|
2017-06-27 03:16:15 -04:00
|
|
|
|
2018-04-02 14:38:47 -04:00
|
|
|
rule { can?(:create_pipeline) }.enable :play_pipeline_schedule
|
2017-12-06 02:23:59 -05:00
|
|
|
|
2018-04-02 14:38:47 -04:00
|
|
|
rule { can?(:admin_pipeline) | (can?(:update_build) & owner_of_schedule) }.policy do
|
2017-07-07 06:09:35 -04:00
|
|
|
enable :admin_pipeline_schedule
|
2020-11-02 16:09:10 -05:00
|
|
|
enable :read_pipeline_schedule_variables
|
2017-06-28 08:42:13 -04:00
|
|
|
end
|
2017-12-06 02:23:59 -05:00
|
|
|
|
2022-05-02 20:08:25 -04:00
|
|
|
rule { admin | (owner_of_schedule & can?(:update_build)) }.policy do
|
|
|
|
enable :update_pipeline_schedule
|
|
|
|
end
|
|
|
|
|
2018-04-02 14:38:47 -04:00
|
|
|
rule { can?(:admin_pipeline_schedule) & ~owner_of_schedule }.policy do
|
2017-07-20 06:54:36 -04:00
|
|
|
enable :take_ownership_pipeline_schedule
|
|
|
|
end
|
|
|
|
|
2017-12-06 02:23:59 -05:00
|
|
|
rule { protected_ref }.prevent :play_pipeline_schedule
|
2017-05-07 18:35:56 -04:00
|
|
|
end
|
|
|
|
end
|