FIX: Render detailed_404 page from 403 responses

FIX: Render detailed_404 page from 403 responses

This was previously broken by 59ef48c0b9d70a6639a545d1c96f3cc6f93ebf2c (#11425, #11424).

Centralize the logic into the exception controller, which avoids the problematic bug and makes it easy to add additional detailed 404 pages in the future.

diff --git a/app/assets/javascripts/discourse/app/controllers/exception.js b/app/assets/javascripts/discourse/app/controllers/exception.js
index 0057782..d4a285b 100644
--- a/app/assets/javascripts/discourse/app/controllers/exception.js
+++ b/app/assets/javascripts/discourse/app/controllers/exception.js
@@ -51,6 +51,9 @@ export default Controller.extend({
   isServer: gte("thrown.status", 500),
   isUnknown: none("isNetwork", "isServer"),
 
+  // Handling for the detailed_404 setting (which actually creates 403s)
+  errorHtml: alias("thrown.responseJSON.extras.html"),
+
   // TODO
   // make ajax requests to /srv/status with exponential backoff
   // if one succeeds, set networkFixed to true, which puts a "Fixed!" message on the page
diff --git a/app/assets/javascripts/discourse/app/templates/exception.hbs b/app/assets/javascripts/discourse/app/templates/exception.hbs
index 99d6e45..41555d7 100644
--- a/app/assets/javascripts/discourse/app/templates/exception.hbs
+++ b/app/assets/javascripts/discourse/app/templates/exception.hbs
@@ -1,22 +1,26 @@
 <div class="container">
-  <div class="error-page">
-    <div class="face">:(</div>
-    <div class="reason">{{reason}}</div>
-    <div class="url">
-      {{i18n "errors.prev_page"}} <a href={{requestUrl}} data-auto-route="true">{{requestUrl}}</a>
-    </div>
-    <div class="desc">
-      {{#if networkFixed}}
-        {{d-icon "check-circle"}}
-      {{/if}}
+  {{#if (and this.errorHtml this.isForbidden)}}
+    <div class="not-found">{{html-safe this.errorHtml}}</div>
+  {{else}}
+    <div class="error-page">
+      <div class="face">:(</div>
+      <div class="reason">{{reason}}</div>
+      <div class="url">
+        {{i18n "errors.prev_page"}} <a href={{requestUrl}} data-auto-route="true">{{requestUrl}}</a>
+      </div>
+      <div class="desc">
+        {{#if networkFixed}}
+          {{d-icon "check-circle"}}
+        {{/if}}
 
-      {{desc}}
-    </div>
-    <div class="buttons">
-      {{#each enabledButtons as |buttonData|}}
-        {{d-button icon=buttonData.icon action=buttonData.action label=buttonData.key class=buttonData.classes}}
-      {{/each}}
-      {{conditional-loading-spinner condition=loading}}
+        {{desc}}
+      </div>
+      <div class="buttons">
+        {{#each enabledButtons as |buttonData|}}
+          {{d-button icon=buttonData.icon action=buttonData.action label=buttonData.key class=buttonData.classes}}
+        {{/each}}
+        {{conditional-loading-spinner condition=loading}}
+      </div>
     </div>
-  </div>
+  {{/if}}
 </div>
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 7250809..8ba80d6 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -214,6 +214,7 @@ class CategoriesController < ApplicationController
           'not in group',
           @category,
           custom_message: 'not_in_group.title_category',
+          custom_message_params: { group: group.name },
           group: group
         )
       else
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index dd99be5..4213fa9 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -297,7 +297,7 @@ en:
   invalid_whisper_access: "Either whispers are not enabled or you do not have access to create whisper posts"
   not_in_group:
     title_topic: "You need to request membership to the '%{group}' group to see this topic."
-    title_category: "You must be in a group to see this category."
+    title_category: "You need to request membership to the '%{group}' group to see this category."
     request_membership: "Request Membership"
     join_group: "Join Group"
   deleted_topic: "Oops! This topic has been deleted and is no longer available."

GitHub sha: f25c55b5be1e2a2c21ee7510f96f65a084062cf3

This commit appears in #13378 which was approved by eviltrout. It was merged by riking.