From fe1e66ba9d8a1171186ebbf1638255516279ef3c Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 28 Jan 2022 11:31:19 +0000 Subject: [PATCH] DEV: Add backwards-compat for SiteSettings/User globals in ember-cli (#15719) --- .../app/initializers/inject-objects.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/assets/javascripts/discourse/app/initializers/inject-objects.js b/app/assets/javascripts/discourse/app/initializers/inject-objects.js index 533e9134af9..b325542587d 100644 --- a/app/assets/javascripts/discourse/app/initializers/inject-objects.js +++ b/app/assets/javascripts/discourse/app/initializers/inject-objects.js @@ -1,9 +1,40 @@ 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 { name: "inject-objects", initialize(container, app) { // This is required for Ember CLI tests to work 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; + }, + }); + } }, };