Skip to content

Commit

Permalink
Use a dup of params and don't mutate the original [#4396]
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaiid committed Jun 22, 2024
1 parent cb798c8 commit e80c9ae
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/services/organization_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ class << self
def update(organization, params)
return false unless valid?(organization, params)

if params.has_key?("partner_form_fields")
params["partner_form_fields"].delete_if { |field| field == "" }
org_params = params.dup

if org_params.has_key?("partner_form_fields")
org_params["partner_form_fields"] = org_params["partner_form_fields"].reject(&:blank?)
end

if Flipper.enabled?(:enable_packs) && params[:request_unit_names]
if Flipper.enabled?(:enable_packs) && org_params[:request_unit_names]
# Find or create units for the organization
request_unit_ids = params[:request_unit_names].reject(&:blank?).map do |request_unit_name|
request_unit_ids = org_params[:request_unit_names].reject(&:blank?).map do |request_unit_name|
Unit.find_or_create_by(organization: organization, name: request_unit_name).id
end
params.delete(:request_unit_names)
params[:request_unit_ids] = request_unit_ids
org_params.delete(:request_unit_names)
org_params[:request_unit_ids] = request_unit_ids
end

result = organization.update(params)
result = organization.update(org_params)

return false unless result
update_partner_flags(organization)
Expand Down

0 comments on commit e80c9ae

Please sign in to comment.