44# Table name: signup_rounds
55#
66# id :bigint not null, primary key
7+ # automation_action :text
78# executed_at :datetime
89# maximum_event_signups :text not null
910# ranked_choice_order :text
2324# rubocop:enable Layout/LineLength, Lint/RedundantCopDisableDirective
2425
2526class SignupRound < ApplicationRecord
27+ AUTOMATION_ACTIONS = Types ::SignupRoundAutomationAction . values . values . map ( &:value ) . freeze
2628 RANKED_CHOICE_ORDERS = Types ::RankedChoiceOrder . values . values . map ( &:value ) . freeze
2729
2830 belongs_to :convention
2931 has_many :ranked_choice_decisions , dependent : :restrict_with_exception
3032
33+ validates :automation_action , inclusion : { in : AUTOMATION_ACTIONS , allow_nil : true }
3134 validates :ranked_choice_order , inclusion : { in : RANKED_CHOICE_ORDERS , allow_nil : true }
3235 validates :start , { uniqueness : { scope : :convention_id } }
36+ validate :automation_action_must_be_allowed
3337
3438 scope :due_at , -> ( time ) { where ( "executed_at IS NULL AND (start IS NULL OR start <= ?)" , time ) }
3539 scope :currently_due , -> { due_at ( Time . zone . now ) }
@@ -42,7 +46,7 @@ def self.execute_currently_due_rounds!
4246
4347 def execute!
4448 transaction do
45- if convention . signup_automation_mode == "ranked_choice"
49+ if convention . signup_automation_mode == "ranked_choice" && automation_action == "execute_ranked_choice"
4650 ExecuteRankedChoiceSignupRoundService . new ( signup_round : self , whodunit : nil ) . call!
4751 end
4852
@@ -69,4 +73,15 @@ def serpentine_ranked_choice_order?
6973 false
7074 end
7175 end
76+
77+ private
78+
79+ def automation_action_must_be_allowed
80+ return unless automation_action
81+
82+ return unless automation_action == "execute_ranked_choice" && convention . signup_automation_mode != "ranked_choice"
83+ errors . add :base ,
84+ "The execute_ranked_choice action is only allowed in conventions that use the ranked_choice signup \
85+ automation mode."
86+ end
7287end
0 commit comments