Skip to content

A platform for community discussion. Free, open, simple.

FIX: Ensure admin templates are not used for non-admin controllers (#17667)

David Taylor3960ba6588f8
diff --git a/app/assets/javascripts/discourse-common/addon/resolver.js b/app/assets/javascripts/discourse-common/addon/resolver.js
index 216d6670c96..8159a4205df 100644
--- a/app/assets/javascripts/discourse-common/addon/resolver.js
+++ b/app/assets/javascripts/discourse-common/addon/resolver.js
@@ -274,7 +274,12 @@ export function buildResolver(baseName) {
let namespaced, match;
if (parsedName.fullNameWithoutType.startsWith("components/")) {
- // Look up components as-is
+ return (
+ // Built-in
+ this.findTemplate(parsedName, "admin/templates/") ||
+ // Plugin
+ this.findTemplate(parsedName, "javascripts/admin/")
+ );
} else if (/^admin[_\.-]/.test(parsedName.fullNameWithoutType)) {
namespaced = parsedName.fullNameWithoutType.slice(6);
} else if (
@@ -294,12 +299,6 @@ export function buildResolver(baseName) {
this.findTemplate(adminParsedName, "javascripts/admin/");
}
- resolved ??=
- // Built-in
- this.findTemplate(parsedName, "admin/templates/") ||
- // Plugin
- this.findTemplate(parsedName, "javascripts/admin/");
-
return resolved;
}
diff --git a/app/assets/javascripts/discourse/tests/unit/ember/resolver-test.js b/app/assets/javascripts/discourse/tests/unit/ember/resolver-test.js
index 70aaada61bd..ab63301194d 100644
--- a/app/assets/javascripts/discourse/tests/unit/ember/resolver-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/ember/resolver-test.js
@@ -317,6 +317,7 @@ module("Unit | Ember | resolver", function (hooks) {
"admin/templates/dashboard_general",
"admin-baz-qux",
"javascripts/admin/plugin-template",
+ "admin/templates/components/my-admin-component",
]);
// Switches prefix to admin/templates when camelized
@@ -395,6 +396,20 @@ module("Unit | Ember | resolver", function (hooks) {
"javascripts/admin/plugin-template",
"looks up templates in plugins"
);
+
+ lookupTemplate(
+ assert,
+ "template:foo",
+ undefined,
+ "doesn't return admin templates for regular controllers"
+ );
+
+ lookupTemplate(
+ assert,
+ "template:components/my-admin-component",
+ "admin/templates/components/my-admin-component",
+ "returns admin-defined component templates"
+ );
});
test("resolves component templates with 'admin' prefix to 'admin/templates/' namespace", function (assert) {