DEV: Add backwards-compat for SiteSettings/User globals in ember-cli (#15719)

This commit is contained in:
David Taylor 2022-01-28 11:31:19 +00:00 committed by GitHub
parent 0b8d0a14d7
commit fe1e66ba9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 0 deletions

View File

@ -1,9 +1,40 @@
import { setDefaultOwner } from "discourse-common/lib/get-owner"; import { setDefaultOwner } from "discourse-common/lib/get-owner";
import { isLegacyEmber } from "discourse-common/config/environment";
import User from "discourse/models/user";
import deprecated from "discourse-common/lib/deprecated";
export default { export default {
name: "inject-objects", name: "inject-objects",
initialize(container, app) { initialize(container, app) {
// This is required for Ember CLI tests to work // This is required for Ember CLI tests to work
setDefaultOwner(app.__container__); setDefaultOwner(app.__container__);
// Backwards compatibility for Discourse.SiteSettings and Discourse.User
if (!isLegacyEmber()) {
Object.defineProperty(app, "SiteSettings", {
get() {
deprecated(
`use injected siteSettings instead of Discourse.SiteSettings`,
{
since: "2.8",
dropFrom: "2.9",
}
);
return container.lookup("site-settings:main");
},
});
Object.defineProperty(app, "User", {
get() {
deprecated(
`import discourse/models/user instead of using Discourse.User`,
{
since: "2.8",
dropFrom: "2.9",
}
);
return User;
},
});
}
}, },
}; };