FIX: hide user id when hide_email_address_taken (#11417)

We should always hide user_id in response when `hide_email_address_taken` setting is enabled. Currently, it can be used to determine if the email was used or not.
This commit is contained in:
Krzysztof Kotlarek 2020-12-08 08:25:35 +11:00 committed by GitHub
parent 28feb7c2ff
commit d5ba854c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

@ -647,8 +647,7 @@ class UsersController < ApplicationController
success: true,
active: user.active?,
message: activation.message,
user_id: user.id
}
}.merge(SiteSetting.hide_email_address_taken ? {} : { user_id: user.id })
elsif SiteSetting.hide_email_address_taken && user.errors[:primary_email]&.include?(I18n.t('errors.messages.taken'))
session["user_created_message"] = activation.success_message
@ -658,9 +657,8 @@ class UsersController < ApplicationController
render json: {
success: true,
active: user.active?,
message: activation.success_message,
user_id: user.id
active: false,
message: activation.success_message
}
else
errors = user.errors.to_hash

View File

@ -762,6 +762,18 @@ describe UsersController do
json = response.parsed_body
expect(json['active']).to be_falsey
expect(json['message']).to eq(I18n.t("login.activate_email", email: post_user_params[:email]))
expect(json['user_id']).not_to be_present
existing.destroy!
expect {
post_user
}.to change { User.count }
expect(response.status).to eq(200)
json = response.parsed_body
expect(json['active']).to be_falsey
expect(json['message']).to eq(I18n.t("login.activate_email", email: post_user_params[:email]))
expect(json['user_id']).not_to be_present
end
end
end