diff --git a/app/models/invite_redeemer.rb b/app/models/invite_redeemer.rb index 35fc22b78f4..31978978912 100644 --- a/app/models/invite_redeemer.rb +++ b/app/models/invite_redeemer.rb @@ -125,6 +125,7 @@ class InviteRedeemer fields = user.custom_fields user_fields.each do |f| + field_params[f.id.to_s] = nil if field_params[f.id.to_s] === "false" field_val = field_params[f.id.to_s] fields["#{User::USER_FIELD_PREFIX}#{f.id}"] = field_val[ 0...UserField.max_length diff --git a/spec/models/invite_redeemer_spec.rb b/spec/models/invite_redeemer_spec.rb index f4bbc920697..e55adaa1366 100644 --- a/spec/models/invite_redeemer_spec.rb +++ b/spec/models/invite_redeemer_spec.rb @@ -390,6 +390,32 @@ RSpec.describe InviteRedeemer do expect(user.custom_fields["user_field_#{optional_field.id}"]).to eq("value2") end + it "can set custom fields with field_type confirm properly" do + optional_field_1 = Fabricate(:user_field, field_type: "confirm", required: false) + optional_field_2 = Fabricate(:user_field, field_type: "confirm", required: false) + optional_field_3 = Fabricate(:user_field, field_type: "confirm", required: false) + user_fields = { + optional_field_1.id.to_s => "false", + optional_field_2.id.to_s => "true", + optional_field_3.id.to_s => "", + } + + user = + InviteRedeemer.new( + invite: invite, + email: invite.email, + username: username, + name: name, + password: password, + user_custom_fields: user_fields, + ).redeem + + expect(user).to be_present + expect(user.custom_fields["user_field_#{optional_field_1.id}"]).to eq(nil) + expect(user.custom_fields["user_field_#{optional_field_2.id}"]).to eq("true") + expect(user.custom_fields["user_field_#{optional_field_3.id}"]).to eq(nil) + end + it "does not add user to group if inviter does not have permissions" do group = Fabricate(:group, grant_trust_level: 2) InvitedGroup.create(group_id: group.id, invite_id: invite.id)