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

Previously, if a non-admin controller did not have a template defined, then the resolver would return an admin template with the same name. This is not the desired behavior, and regressed in fc36ac6cde. However, we *do* want this behavior for components defined in the admin bundle (because admin components are not namespaced).

This was noticed because the non-admin `badges` route was using the `admin/badges` template

This commit fixes the behavior, and adds a tests for these cases.
This commit is contained in:
David Taylor 2022-07-26 17:03:49 +01:00 committed by GitHub
parent 90c969c90f
commit 3960ba6588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -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;
}

View File

@ -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) {