From d5ba854c916f55e9f7f503322bbe6100330109af Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 8 Dec 2020 08:25:35 +1100 Subject: [PATCH] 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. --- app/controllers/users_controller.rb | 8 +++----- spec/requests/users_controller_spec.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d97ad5f71e4..42700f31d5a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index be4b5eff8fe..b3635d1439d 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -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