A platform for community discussion. Free, open, simple.
FIX: Display a proper error when user already exists and email addresses are hidden. (#20585)
Roman Rizzi910bf74c2e0d
diff --git a/app/assets/javascripts/discourse/app/controllers/create-invite.js b/app/assets/javascripts/discourse/app/controllers/create-invite.jsindex 35f25166176..3dcafa4899c 100644--- a/app/assets/javascripts/discourse/app/controllers/create-invite.js+++ b/app/assets/javascripts/discourse/app/controllers/create-invite.js@@ -123,10 +123,6 @@ export default Controller.extend(return this.invite.save(data).then(() => {- if (!this.invite.id) {- return;- }-this.rollbackBuffer();if (diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rbindex a8483d2b46f..08cfc423ef7 100644--- a/app/controllers/invites_controller.rb+++ b/app/controllers/invites_controller.rb@@ -87,7 +87,6 @@ class InvitesController < ApplicationControllerrender json: failed_json, status: 422endrescue Invite::UserExists => e- return render json: {}, status: 200 if SiteSetting.hide_email_address_taken?render_json_error(e.message)rescue ActiveRecord::RecordInvalid => erender_json_error(e.record.errors.full_messages.first)@@ -206,9 +205,6 @@ class InvitesController < ApplicationControllerparams.permit(:email, :custom_message, :max_redemptions_allowed, :expires_at),)rescue ActiveRecord::RecordInvalid => e- if SiteSetting.hide_email_address_taken? && e.record.email_already_exists?- return render json: {}, status: 200- endreturn render_json_error(e.record.errors.full_messages.first)endenddiff --git a/app/models/invite.rb b/app/models/invite.rbindex dae62e32317..fbe34461c43 100644--- a/app/models/invite.rb+++ b/app/models/invite.rb@@ -349,7 +349,9 @@ class Invite < ActiveRecord::Baseenddef user_exists_error_msg(email)- I18n.t("invite.user_exists", email: CGI.escapeHTML(email))+ error_key = SiteSetting.hide_email_address_taken? ? "generic_error_response" : "user_exists"++ I18n.t("invite.#{error_key}", email: CGI.escapeHTML(email))endenddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 289db78cb00..405bd9c8096 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -255,6 +255,7 @@ en:user_exists: "There's no need to invite <b>%{email}</b>, they already have an account!"invite_exists: "You already invited <b>%{email}</b>."invalid_email: "%{email} isn't a valid email address."+ generic_error_response: "There was a problem with your request."rate_limit:one: "You have already sent %{count} invite in the last 24 hours, please wait %{time_left} before trying again."other: "You have already sent %{count} invites in the last 24 hours, please wait %{time_left} before trying again."diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rbindex 05c1757eac2..c760567ad34 100644--- a/spec/requests/invites_controller_spec.rb+++ b/spec/requests/invites_controller_spec.rb@@ -444,8 +444,8 @@ RSpec.describe InvitesController doit "doesn’t inform the user" docreate_invite- expect(response).to have_http_status :ok- expect(response.parsed_body).to be_blank+ expect(response).to have_http_status :unprocessable_entity+ expect(body).to match(/There was a problem with your request./)endendend@@ -595,8 +595,8 @@ RSpec.describe InvitesController doit "doesn't inform the user" doupdate_invite- expect(response).to have_http_status :ok- expect(response.parsed_body).to be_blank+ expect(response).to have_http_status :unprocessable_entity+ expect(body).to match(/There was a problem with your request./)endendend