@@ -57,9 +57,12 @@ def update # rubocop:disable Metrics/AbcSize
5757 success = false
5858 Workflow . transaction do
5959 success = true
60+ base_params = permitted_status_params
61+ indeterminate = permitted_indeterminate_params
6062 @roles . each do |role |
63+ role_params = indeterminate . empty? ? base_params : role_specific_params ( base_params , indeterminate , role )
6164 result = Workflows ::BulkUpdateService . new ( role :, type : @type , tab : @tab )
62- . call ( permitted_status_params )
65+ . call ( role_params )
6366 success = false unless result . success?
6467 end
6568 raise ActiveRecord ::Rollback unless success
@@ -200,10 +203,40 @@ def workflows_for_form
200203 end
201204
202205 def permitted_status_params
203- return { } if params [ "status" ] . blank?
206+ status_params ( "status" )
207+ end
208+
209+ def permitted_indeterminate_params
210+ status_params ( "indeterminate_status" )
211+ end
204212
205- params [ "status" ]
213+ def status_params ( key )
214+ return { } if params [ key ] . blank?
215+
216+ params [ key ]
206217 . to_unsafe_h
207- . select { |key , value | /\A \d +\z / . match? ( key ) && value . keys . all? { /\A \d +\z / . match? ( it ) } }
218+ . select { |k , value | /\A \d +\z / . match? ( k ) && value . keys . all? { /\A \d +\z / . match? ( it ) } }
219+ end
220+
221+ def role_specific_params ( base_params , indeterminate , role )
222+ params = base_params . deep_dup
223+ indeterminate . each do |old_id , new_ids |
224+ new_ids . each_key do |new_id |
225+ # Restore from DB so that it isn't overwritten by indeterminate state (unchecked)
226+ had_transition = Workflow . exists? (
227+ role_id : role . id ,
228+ type_id : @type . id ,
229+ old_status_id : old_id . to_i ,
230+ new_status_id : new_id . to_i ,
231+ author : @tab == "author" ,
232+ assignee : @tab == "assignee"
233+ )
234+ if had_transition
235+ params [ old_id ] ||= { }
236+ params [ old_id ] [ new_id ] = "1"
237+ end
238+ end
239+ end
240+ params
208241 end
209242end
0 commit comments