FIX: Better error message for redeemed invite (#12580)

FIX: Better error message for redeemed invite (#12580)

This commit improves the error message when a user tries to redeem a completely redeemed invite link.

diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index f6b8945..bdff145 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -52,7 +52,11 @@ class InvitesController < ApplicationController
       flash.now[:error] = if invite.blank?
         I18n.t('invite.not_found', base_url: Discourse.base_url)
       elsif invite.redeemed?
-        I18n.t('invite.not_found_template', site_name: SiteSetting.title, base_url: Discourse.base_url)
+        if invite.is_invite_link?
+          I18n.t('invite.not_found_template_link', site_name: SiteSetting.title, base_url: Discourse.base_url)
+        else
+          I18n.t('invite.not_found_template', site_name: SiteSetting.title, base_url: Discourse.base_url)
+        end
       elsif invite.expired?
         I18n.t('invite.expired', base_url: Discourse.base_url)
       end
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 4e1ca38..47b6981 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -236,6 +236,8 @@ en:
       <p>If you remember your password you can <a href="%{base_url}/login">Log In</a>.</p>
 
       <p>Otherwise please <a href="%{base_url}/password-reset">Reset Password</a>.</p>
+    not_found_template_link: |
+      <p>The invitation to <a href="%{base_url}">%{site_name}</a> can no longer be redeemed. Please ask the person who invited you to send you a new invitation.</p>
     error_message: "There was an error accepting invite. Please contact the site's administrator."
     user_exists: "There's no need to invite <b>%{email}</b>, they <a href='%{base_path}/u/%{username}/summary'>already have an account!</a>"
     confirm_email: "<p>You’re almost done! We sent an activation mail to your email address. Please follow the instructions in the mail to activate your account.</p><p>If it doesn’t arrive, check your spam folder.</p>"
diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb
index 5bd1289..6e3d810 100644
--- a/spec/requests/invites_controller_spec.rb
+++ b/spec/requests/invites_controller_spec.rb
@@ -74,12 +74,19 @@ describe InvitesController do
     end
 
     it 'returns error if invite has already been redeemed' do
-      Fabricate(:invited_user, invite: invite, user: Fabricate(:user))
+      expect(invite.redeem).not_to eq(nil)
 
       get "/invites/#{invite.invite_key}"
       expect(response.status).to eq(200)
       expect(response.body).to_not have_tag(:script, with: { src: '/assets/application.js' })
       expect(response.body).to include(I18n.t('invite.not_found_template', site_name: SiteSetting.title, base_url: Discourse.base_url))
+
+      invite.update!(email: nil) # convert to email invite
+
+      get "/invites/#{invite.invite_key}"
+      expect(response.status).to eq(200)
+      expect(response.body).to_not have_tag(:script, with: { src: '/assets/application.js' })
+      expect(response.body).to include(I18n.t('invite.not_found_template_link', site_name: SiteSetting.title, base_url: Discourse.base_url))
     end
   end
 

GitHub sha: 81e5352e

This commit appears in #12580 which was approved by eviltrout. It was merged by udan11.