@@ -11,19 +11,67 @@ class Proposal < ApplicationRecord
1111 rejected : 'rejected' ,
1212 withdrawn : 'withdrawn' ,
1313 not_accepted : 'not accepted'
14- } , default : :submitted
14+ } , default : :submitted do
15+ event :soft_accept do
16+ transition :submitted => :soft_accepted
17+ end
1518
16- SOFT_STATES = [ :soft_accepted , :soft_waitlisted , :soft_rejected , :submitted ] . freeze
17- FINAL_STATES = [ :accepted , :waitlisted , :rejected , :withdrawn , :not_accepted ] . freeze
19+ event :soft_waitlist do
20+ transition :submitted => :soft_waitlisted
21+ end
22+
23+ event :soft_reject do
24+ transition :submitted => :soft_rejected
25+ end
1826
19- SOFT_TO_FINAL = {
20- soft_accepted : :accepted ,
21- soft_rejected : :rejected ,
22- soft_waitlisted : :waitlisted ,
23- submitted : :rejected
24- } . with_indifferent_access . freeze
27+ event :withdraw do
28+ transition all - [ :withdrawn ] => :withdrawn
29+
30+ after do
31+ reviewers . each do |reviewer |
32+ Notification . create_for ( reviewer , proposal : self , message : "Proposal, #{ title } , withdrawn" )
33+ end
34+ end
35+ end
36+
37+ event :promote do
38+ transition :waitlisted => :accepted
39+ end
2540
26- BECOMES_PROGRAM_SESSION = [ :accepted , :waitlisted ] . freeze
41+ event :decline do
42+ transition [ :accepted , :waitlisted ] => :withdrawn
43+
44+ before do
45+ self . confirmed_at = Time . current
46+ end
47+
48+ after do
49+ program_session . update ( state : :declined )
50+ end
51+ end
52+
53+ event :finalize do
54+ transition :soft_accepted => :accepted
55+ transition :soft_rejected => :rejected
56+ transition :soft_waitlisted => :waitlisted
57+ transition :submitted => :rejected
58+
59+ after do
60+ ProgramSession . create_from_proposal ( self ) if becomes_program_session?
61+ end
62+ end
63+
64+ event :reset do
65+ transition [ :soft_accepted , :soft_waitlisted , :soft_rejected ] => :submitted
66+ end
67+
68+ event :hard_reset do
69+ transition [ :accepted , :waitlisted , :rejected ] => :submitted
70+ end
71+ end
72+
73+ SOFT_STATES = [ :soft_accepted , :soft_waitlisted , :soft_rejected , :submitted ] . freeze
74+ FINAL_STATES = [ :accepted , :waitlisted , :rejected , :withdrawn , :not_accepted ] . freeze
2775
2876 has_many :public_comments , dependent : :destroy
2977 has_many :internal_comments , dependent : :destroy
@@ -124,46 +172,11 @@ def custom_fields
124172 proposal_data [ :custom_fields ] || { }
125173 end
126174
127- def update_state ( new_state )
128- update ( state : new_state )
129- end
130-
131- def finalize
132- transaction do
133- update_state ( SOFT_TO_FINAL [ state ] ) if SOFT_TO_FINAL . key? ( state )
134- if becomes_program_session?
135- ps = ProgramSession . create_from_proposal ( self )
136- ps . persisted?
137- else
138- true
139- end
140- end
141- rescue ActiveRecord ::RecordInvalid
142- false
143- end
144-
145- def withdraw
146- withdrawn!
147- reviewers . each do |reviewer |
148- Notification . create_for ( reviewer , proposal : self ,
149- message : "Proposal, #{ title } , withdrawn" )
150- end
151- end
152-
153175 def confirm
154176 update ( confirmed_at : Time . current )
155177 program_session . confirm if program_session . present?
156178 end
157179
158- def promote
159- accepted! if waitlisted?
160- end
161-
162- def decline
163- update ( state : :withdrawn , confirmed_at : Time . current )
164- program_session . update ( state : :declined )
165- end
166-
167180 # draft? is an alias for submitted?
168181 def draft?
169182 submitted?
@@ -174,7 +187,7 @@ def finalized?
174187 end
175188
176189 def becomes_program_session?
177- BECOMES_PROGRAM_SESSION . include? ( state . to_sym )
190+ accepted? || waitlisted?
178191 end
179192
180193 def confirmed?
@@ -272,7 +285,7 @@ def changeset_fields
272285 private
273286
274287 def state_must_be_final_for_confirmation
275- errors . add ( :state , "'#{ state } ' not a confirmable state." ) unless FINAL_STATES . include? ( state . to_sym )
288+ errors . add ( :state , "'#{ state } ' not a confirmable state." ) unless finalized?
276289 end
277290
278291 def abstract_length
0 commit comments