FIX: show accurate error message based on invite token validity

FIX: show accurate error message based on invite token validity

diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index 77dba98..c888cff 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -19,16 +19,21 @@ class InvitesController < ApplicationController
 
     invite = Invite.find_by(invite_key: params[:id])
 
-    if invite.present? && !invite.redeemed?
-      store_preloaded("invite_info", MultiJson.dump(
-        invited_by: UserNameSerializer.new(invite.invited_by, scope: guardian, root: false),
-        email: invite.email,
-        username: UserNameSuggester.suggest(invite.email))
-      )
-
-      render layout: 'application'
+    if invite.present?
+      if !invite.redeemed?
+        store_preloaded("invite_info", MultiJson.dump(
+          invited_by: UserNameSerializer.new(invite.invited_by, scope: guardian, root: false),
+          email: invite.email,
+          username: UserNameSuggester.suggest(invite.email))
+        )
+
+        render layout: 'application'
+      else
+        flash.now[:error] = I18n.t('invite.not_found_template', site_name: SiteSetting.title, base_url: Discourse.base_url)
+        render layout: 'no_ember'
+      end
     else
-      flash.now[:error] = I18n.t('invite.not_found_template', site_name: SiteSetting.title, base_url: Discourse.base_url)
+      flash.now[:error] = I18n.t('invite.not_found')
       render layout: 'no_ember'
     end
   end
diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb
index d51a301..c2557e5 100644
--- a/spec/requests/invites_controller_spec.rb
+++ b/spec/requests/invites_controller_spec.rb
@@ -12,7 +12,7 @@ describe InvitesController do
 
       body = response.body
       expect(body).to_not have_tag(:script, with: { src: '/assets/application.js' })
-      expect(CGI.unescapeHTML(body)).to include(I18n.t('invite.not_found_template', site_name: SiteSetting.title, base_url: Discourse.base_url))
+      expect(CGI.unescapeHTML(body)).to include(I18n.t('invite.not_found', site_name: SiteSetting.title, base_url: Discourse.base_url))
     end
 
     it "renders the accept invite page if invite exists" do

GitHub
sha: bea7a8a4