FIX: User fields are case insensitive in bulk CSV (#12559)

The CSV column title had to be case sensitive match with the name of
the user field which was unnecessary complex.
This commit is contained in:
Dan Ungureanu 2021-03-31 13:42:53 +03:00 committed by GitHub
parent dce48d8aa7
commit e8c576cca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -93,7 +93,7 @@ module Jobs
user_fields = {}
fields.each do |key, value|
@user_fields[key] ||= UserField.find_by(name: key)&.id || :nil
@user_fields[key] ||= UserField.where('name ILIKE ?', key).pluck_first(:id) || :nil
user_fields[@user_fields[key]] = value if @user_fields[key] != :nil
end

View File

@ -82,14 +82,14 @@ describe Jobs::BulkInvite do
end
it 'can create staged users and prepulate user fields' do
user_field = Fabricate(:user_field)
user_field = Fabricate(:user_field, name: "Location")
described_class.new.execute(
current_user_id: admin.id,
invites: [
{ email: 'test@discourse.org' }, # new user without user fields
{ email: user.email, user_field.name => 'value 1' }, # existing user with user fields
{ email: staged_user.email, user_field.name => 'value 2' }, # existing staged user with user fields
{ email: 'test2@discourse.org', user_field.name => 'value 3' } # new staged user with user fields
{ email: user.email, location: 'value 1' }, # existing user with user fields
{ email: staged_user.email, location: 'value 2' }, # existing staged user with user fields
{ email: 'test2@discourse.org', location: 'value 3' } # new staged user with user fields
]
)