DEV: Replace `site-settings:main` with `service:site-settings` (#17734)

This will allow consumers to inject it using `siteSettings: service()` in preparation for the removal of implicit injections in Ember 4.0. `site-settings:main` is still available and will print a deprecation notice.
This commit is contained in:
David Taylor 2022-08-01 09:43:33 +01:00 committed by GitHub
parent ad6b5825bf
commit 9534f13256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 58 additions and 53 deletions

View File

@ -17,12 +17,7 @@ export default class DiscourseGlimmerComponent extends GlimmerComponent {
@service("search") searchService;
@service keyValueStore;
@service pmTopicTrackingState;
@cached
get siteSettings() {
const applicationInstance = getOwner(this);
return applicationInstance.lookup("site-settings:main");
}
@service siteSettings;
@cached
get currentUser() {

View File

@ -18,7 +18,7 @@ export function autoLoadModules(container, registry) {
});
let context = {
siteSettings: container.lookup("site-settings:main"),
siteSettings: container.lookup("service:site-settings"),
keyValueStore: container.lookup("service:key-value-store"),
capabilities: container.lookup("capabilities:main"),
currentUser: container.lookup("current-user:main"),

View File

@ -8,7 +8,7 @@ export default {
name: "codeblock-buttons",
initialize(container) {
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
withPluginApi("0.8.7", (api) => {
function _cleanUp() {

View File

@ -6,7 +6,7 @@ export default {
name: "enable-emoji",
initialize(container) {
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
if (!siteSettings.enable_emoji) {
return;
}

View File

@ -19,7 +19,7 @@ export default {
dropFrom: "2.9",
}
);
return container.lookup("site-settings:main");
return container.lookup("service:site-settings");
},
});
Object.defineProperty(app, "User", {

View File

@ -6,7 +6,7 @@ export default {
after: "inject-objects",
isVerboseLocalizationEnabled(container) {
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
if (siteSettings.verbose_localization) {
return true;
}

View File

@ -11,7 +11,7 @@ export default {
return;
}
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
const messageBus = container.lookup("service:message-bus");
const keyValueStore = container.lookup("service:key-value-store");
const currentUser = container.lookup("current-user:main");

View File

@ -42,7 +42,7 @@ export default {
const messageBus = container.lookup("service:message-bus"),
user = container.lookup("current-user:main"),
siteSettings = container.lookup("site-settings:main");
siteSettings = container.lookup("service:site-settings");
messageBus.alwaysLongPoll = !isProduction();
messageBus.shouldLongPollCallback = () =>

View File

@ -14,7 +14,7 @@ export default {
name: "post-decorations",
initialize(container) {
withPluginApi("0.1", (api) => {
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
const session = container.lookup("session:main");
const site = container.lookup("site:main");
api.decorateCookedElement(

View File

@ -5,7 +5,7 @@ export default {
name: "register-media-optimization-upload-processor",
initialize(container) {
let siteSettings = container.lookup("site-settings:main");
let siteSettings = container.lookup("service:site-settings");
if (siteSettings.composer_media_optimization_image_enabled) {
addComposerUploadPreProcessor(
UppyMediaOptimization,

View File

@ -5,7 +5,7 @@ export default {
name: "sharing-sources",
initialize(container) {
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
Sharing.addSource({
id: "twitter",

View File

@ -11,7 +11,7 @@ export default {
initialize(container) {
const screenTrack = container.lookup("service:screen-track");
const session = Session.current();
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
const keyValueStore = container.lookup("service:key-value-store");
const user = container.lookup("current-user:main");
const appEvents = container.lookup("service:app-events");

View File

@ -122,7 +122,7 @@ export default {
});
const site = container.lookup("site:main");
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
const router = container.lookup("router:main");
bus.subscribe("/categories", (data) => {

View File

@ -23,7 +23,7 @@ export default {
DiscourseURL.rewrite(/^\/groups\//, "/g/");
// Initialize default homepage
let siteSettings = container.lookup("site-settings:main");
let siteSettings = container.lookup("service:site-settings");
initializeDefaultHomepage(siteSettings);
DiscourseURL.rewrite(/^\/u\/([^\/]+)\/?$/, "/u/$1/summary", {

View File

@ -136,7 +136,7 @@ export default {
this.searchService = this.container.lookup("service:search");
this.appEvents = this.container.lookup("service:app-events");
this.currentUser = this.container.lookup("current-user:main");
this.siteSettings = this.container.lookup("site-settings:main");
this.siteSettings = this.container.lookup("service:site-settings");
// Disable the shortcut if private messages are disabled
if (!this.siteSettings.enable_personal_messages) {

View File

@ -344,7 +344,7 @@ let _uncategorized;
Category.reopenClass({
slugEncoded() {
let siteSettings = getOwner(this).lookup("site-settings:main");
let siteSettings = getOwner(this).lookup("service:site-settings");
return siteSettings.slug_generation_method === "encoded";
},

View File

@ -244,7 +244,7 @@ NavItem.reopenClass({
since: "2.6.0",
dropFrom: "2.7.0",
});
args.siteSettings = getOwner(this).lookup("site-settings:main");
args.siteSettings = getOwner(this).lookup("service:site-settings");
}
let items = args.siteSettings.top_menu.split("|");

View File

@ -110,7 +110,7 @@ RestModel.reopenClass({
args.store = owner.lookup("service:store");
}
if (!args.siteSettings) {
args.siteSettings = owner.lookup("site-settings:main");
args.siteSettings = owner.lookup("service:site-settings");
}
if (!args.appEvents) {
args.appEvents = owner.lookup("service:appEvents");

View File

@ -17,7 +17,7 @@ export default {
name: "discourse-bootstrap",
// The very first initializer to run
initialize(container, app) {
initialize(container) {
setURLContainer(container);
setDefaultOwner(container);
@ -54,7 +54,6 @@ export default {
setupURL(setupData.cdn, setupData.baseUrl, setupData.baseUri);
setEnvironment(setupData.environment);
app.SiteSettings = PreloadStore.get("siteSettings");
I18n.defaultLocale = setupData.defaultLocale;
window.Logster = window.Logster || {};

View File

@ -9,17 +9,6 @@ import deprecated from "discourse-common/lib/deprecated";
const ALL_TARGETS = ["controller", "component", "route", "model", "adapter"];
export function registerObjects(app) {
if (app.__registeredObjects__) {
// don't run registrations twice.
return;
}
app.__registeredObjects__ = true;
const siteSettings = app.SiteSettings;
app.register("site-settings:main", siteSettings, { instantiate: false });
}
function injectServiceIntoService({ container, app, property, specifier }) {
// app.inject doesn't allow implicit injection of services into services.
// However, we need to do it in order to convert our old service-like objects
@ -56,8 +45,6 @@ export default {
after: "discourse-bootstrap",
initialize(container, app) {
registerObjects(app);
deprecateRegistration({
app,
container,
@ -103,7 +90,16 @@ export default {
dropFrom: "3.0.0",
});
let siteSettings = container.lookup("site-settings:main");
deprecateRegistration({
app,
container,
oldName: "site-settings:main",
newName: "service:site-settings",
since: "2.9.0.beta7",
dropFrom: "3.0.0",
});
const siteSettings = container.lookup("service:site-settings");
const currentUser = User.current();
app.register("current-user:main", currentUser, { instantiate: false });
@ -135,7 +131,7 @@ export default {
app.inject(t, "searchService", "service:search");
app.inject(t, "session", "session:main");
app.inject(t, "messageBus", "service:message-bus");
app.inject(t, "siteSettings", "site-settings:main");
app.inject(t, "siteSettings", "service:site-settings");
app.inject(t, "topicTrackingState", "topic-tracking-state:main");
app.inject(t, "keyValueStore", "service:key-value-store");
});
@ -147,7 +143,12 @@ export default {
property: "messageBus",
specifier: "service:message-bus",
});
app.inject("service", "siteSettings", "site-settings:main");
injectServiceIntoService({
container,
app,
property: "siteSettings",
specifier: "service:site-settings",
});
app.inject("service", "topicTrackingState", "topic-tracking-state:main");
injectServiceIntoService({
container,

View File

@ -0,0 +1,9 @@
import PreloadStore from "discourse/lib/preload-store";
export default class SiteSettingsService {
static isServiceFactory = true;
static create() {
return PreloadStore.get("siteSettings");
}
}

View File

@ -141,7 +141,7 @@ export default class Widget {
this.key = this.buildKey ? this.buildKey(attrs) : null;
this.site = register.lookup("site:main");
this.siteSettings = register.lookup("site-settings:main");
this.siteSettings = register.lookup("service:site-settings");
this.currentUser = register.lookup("current-user:main");
this.capabilities = register.lookup("capabilities:main");
this.store = register.lookup("service:store");

View File

@ -73,7 +73,7 @@ export default function (customLookup = () => {}) {
this._tracker = this._tracker || TopicTrackingState.create();
return this._tracker;
}
if (type === "site-settings:main") {
if (type === "service:site-settings") {
this._settings = this._settings || currentSettings();
return this._settings;
}

View File

@ -28,11 +28,11 @@ import { buildResolver } from "discourse-common/resolver";
import { createHelperContext } from "discourse-common/lib/helpers";
import deprecated from "discourse-common/lib/deprecated";
import { flushMap } from "discourse/services/store";
import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects";
import sinon from "sinon";
import { disableCloaking } from "discourse/widgets/post-stream";
import { clearState as clearPresenceState } from "discourse/tests/helpers/presence-pretender";
import { addModuleExcludeMatcher } from "ember-cli-test-loader/test-support/index";
import SiteSettingService from "discourse/services/site-settings";
const Plugin = $.fn.modal;
const Modal = Plugin.Constructor;
@ -94,6 +94,8 @@ function createApplication(config, settings) {
return container;
});
SiteSettingService.create = () => settings;
if (!started) {
app.instanceInitializer({
name: "test-helper",
@ -105,8 +107,6 @@ function createApplication(config, settings) {
started = true;
}
app.SiteSettings = settings;
registerObjects(app);
return app;
}
@ -278,7 +278,7 @@ export default function setupTests(config) {
createHelperContext({
get siteSettings() {
return app.__container__.lookup("site-settings:main");
return app.__container__.lookup("service:site-settings");
},
capabilities: {},
get site() {

View File

@ -109,7 +109,7 @@ function _rangeElements(element) {
}
function initializeDiscourseLocalDates(api) {
const siteSettings = api.container.lookup("site-settings:main");
const siteSettings = api.container.lookup("service:site-settings");
const defaultTitle = I18n.t("discourse_local_dates.default_title", {
site_name: siteSettings.title,
});
@ -336,7 +336,7 @@ export default {
return;
}
const siteSettings = owner.lookup("site-settings:main");
const siteSettings = owner.lookup("service:site-settings");
showPopover(event, {
trigger: "click",
@ -357,7 +357,7 @@ export default {
initialize(container) {
window.addEventListener("click", this.showDatePopover);
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
if (siteSettings.discourse_local_dates_enabled) {
$.fn.applyLocalDates = function () {
deprecated(

View File

@ -119,7 +119,7 @@ export default {
name: "new-user-narratve",
initialize(container) {
const siteSettings = container.lookup("site-settings:main");
const siteSettings = container.lookup("service:site-settings");
if (siteSettings.discourse_narrative_bot_enabled) {
withPluginApi("0.8.7", initialize);
}

View File

@ -24,8 +24,9 @@ function cleanUpPolls() {
function initializePolls(api) {
const register = getRegister(api),
pollGroupableUserFields =
api.container.lookup("site-settings:main").poll_groupable_user_fields;
pollGroupableUserFields = api.container.lookup(
"service:site-settings"
).poll_groupable_user_fields;
cleanUpPolls();
api.modifyClass("controller:topic", {