mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
FIX: allow single string values on custom multiple select fields and not just arrays (#14236)
This commit is contained in:
parent
763f48abc7
commit
85c31c73ba
@ -1607,6 +1607,7 @@ class UsersController < ApplicationController
|
||||
if field.field_type == "dropdown"
|
||||
field.user_field_options.find_by_value(field_values)&.value
|
||||
elsif field.field_type == "multiselect"
|
||||
field_values = Array.wrap(field_values)
|
||||
bad_values = field_values - field.user_field_options.map(&:value)
|
||||
field_values - bad_values
|
||||
else
|
||||
|
@ -1279,6 +1279,16 @@ describe UsersController do
|
||||
end
|
||||
end
|
||||
|
||||
it "should allow single values and not just arrays" do
|
||||
expect do
|
||||
put update_user_url, params: { user_fields: { field_id => 'Axe' } }
|
||||
end.to change { user.reload.user_fields[field_id] }.from(nil).to('Axe')
|
||||
|
||||
expect do
|
||||
put update_user_url, params: { user_fields: { field_id => %w[Axe Juice Sword] } }
|
||||
end.to change { user.reload.user_fields[field_id] }.from('Axe').to(%w[Axe Sword])
|
||||
end
|
||||
|
||||
it "shouldn't allow unregistered field values" do
|
||||
expect do
|
||||
put update_user_url, params: { user_fields: { field_id => %w[Juice] } }
|
||||
|
Loading…
Reference in New Issue
Block a user