From 9aa2723d57cf9edaad0873ba64d3d1e5a9d7fdc7 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Sat, 24 Oct 2020 21:21:01 +0530 Subject: [PATCH] UX: improve error message for already logged in users (#11020) --- app/controllers/invites_controller.rb | 2 +- config/locales/server.en.yml | 2 +- spec/requests/invites_controller_spec.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index 530f9e7db8e..fb4723c21fa 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -254,7 +254,7 @@ class InvitesController < ApplicationController def ensure_not_logged_in if current_user - flash[:error] = I18n.t("login.already_logged_in", current_user: current_user.username) + flash[:error] = I18n.t("login.already_logged_in") render layout: 'no_ember' false end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 444b85d9c8f..aa40f7f7050 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2452,7 +2452,7 @@ en: missing_user_field: "You have not completed all the user fields" auth_complete: "Authentication is complete." click_to_continue: "Click here to continue." - already_logged_in: "Oops, looks like you are attempting to accept an invitation for another user. If you are not %{current_user}, please log out and try again." + already_logged_in: "Sorry! This invitation is intended for new users, who do not already have an existing account." second_factor_title: "Two-Factor Authentication" second_factor_description: "Please enter the required authentication code from your app:" second_factor_backup_description: "Please enter one of your backup codes:" diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb index 995ded2a21a..0648dc17dce 100644 --- a/spec/requests/invites_controller_spec.rb +++ b/spec/requests/invites_controller_spec.rb @@ -10,6 +10,15 @@ describe InvitesController do fab!(:invite) { Fabricate(:invite) } fab!(:user) { Fabricate(:coding_horror) } + it 'does not work for logged in users' do + sign_in(Fabricate(:user)) + get "/invites/#{invite.invite_key}" + + expect(response.status).to eq(200) + body = response.body + expect(CGI.unescapeHTML(body)).to include(I18n.t("login.already_logged_in")) + end + it "returns error if invite not found" do get "/invites/nopeNOPEnope"