REFACTOR: Remove Discourse.SiteSettings from user/admin-user

This commit is contained in:
Robin Ward 2020-07-14 12:31:03 -04:00
parent a1507b2316
commit ca13160435
6 changed files with 24 additions and 22 deletions

View File

@ -21,12 +21,7 @@ export default Component.extend({
formSubmitted: false, formSubmitted: false,
actionName: "block", actionName: "block",
@discourseComputed @discourseComputed("siteSettings.use_admin_ip_whitelist")
adminWhitelistEnabled() {
return Discourse.SiteSettings.use_admin_ip_whitelist;
},
@discourseComputed("adminWhitelistEnabled")
actionNames(adminWhitelistEnabled) { actionNames(adminWhitelistEnabled) {
if (adminWhitelistEnabled) { if (adminWhitelistEnabled) {
return [ return [

View File

@ -35,7 +35,7 @@ const AdminUser = User.extend({
bounceScoreExplanation(bounce_score) { bounceScoreExplanation(bounce_score) {
if (bounce_score === 0) { if (bounce_score === 0) {
return I18n.t("admin.user.bounce_score_explanation.none"); return I18n.t("admin.user.bounce_score_explanation.none");
} else if (bounce_score < Discourse.SiteSettings.bounce_score_threshold) { } else if (bounce_score < this.siteSettings.bounce_score_threshold) {
return I18n.t("admin.user.bounce_score_explanation.some"); return I18n.t("admin.user.bounce_score_explanation.some");
} else { } else {
return I18n.t("admin.user.bounce_score_explanation.threshold_reached"); return I18n.t("admin.user.bounce_score_explanation.threshold_reached");

View File

@ -2,6 +2,7 @@ import { warn } from "@ember/debug";
import { equal } from "@ember/object/computed"; import { equal } from "@ember/object/computed";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import { Promise } from "rsvp"; import { Promise } from "rsvp";
import { getOwner } from "discourse-common/lib/get-owner";
const RestModel = EmberObject.extend({ const RestModel = EmberObject.extend({
isNew: equal("__state", "new"), isNew: equal("__state", "new"),
@ -100,9 +101,16 @@ RestModel.reopenClass({
create(args) { create(args) {
args = args || {}; args = args || {};
let owner = getOwner(this);
// Some Discourse code calls `model.create()` directly without going through the
// store. In that case the injections are not made, so we do them here. Eventually
// we should use the store for everything to fix this.
if (!args.store) { if (!args.store) {
const container = Discourse.__container__; args.store = owner.lookup("service:store");
args.store = container.lookup("service:store"); }
if (!args.siteSettings) {
args.siteSettings = owner.lookup("site-settings:main");
} }
args.__munge = this.munge; args.__munge = this.munge;

View File

@ -262,7 +262,6 @@ export default EmberObject.extend({
// TODO: Have injections be automatic // TODO: Have injections be automatic
obj.topicTrackingState = this.register.lookup("topic-tracking-state:main"); obj.topicTrackingState = this.register.lookup("topic-tracking-state:main");
obj.keyValueStore = this.register.lookup("key-value-store:main"); obj.keyValueStore = this.register.lookup("key-value-store:main");
obj.siteSettings = this.register.lookup("site-settings:main");
const klass = this.register.lookupFactory("model:" + type) || RestModel; const klass = this.register.lookupFactory("model:" + type) || RestModel;
const model = klass.create(obj); const model = klass.create(obj);

View File

@ -50,7 +50,7 @@ const User = RestModel.extend({
@discourseComputed("can_be_deleted", "post_count") @discourseComputed("can_be_deleted", "post_count")
canBeDeleted(canBeDeleted, postCount) { canBeDeleted(canBeDeleted, postCount) {
const maxPostCount = Discourse.SiteSettings.delete_all_posts_max; const maxPostCount = this.siteSettings.delete_all_posts_max;
return canBeDeleted && postCount <= maxPostCount; return canBeDeleted && postCount <= maxPostCount;
}, },
@ -100,7 +100,7 @@ const User = RestModel.extend({
@discourseComputed("username", "name") @discourseComputed("username", "name")
displayName(username, name) { displayName(username, name) {
if (Discourse.SiteSettings.enable_names && !isEmpty(name)) { if (this.siteSettings.enable_names && !isEmpty(name)) {
return name; return name;
} }
return username; return username;
@ -108,7 +108,7 @@ const User = RestModel.extend({
@discourseComputed("profile_background_upload_url") @discourseComputed("profile_background_upload_url")
profileBackgroundUrl(bgUrl) { profileBackgroundUrl(bgUrl) {
if (isEmpty(bgUrl) || !Discourse.SiteSettings.allow_profile_backgrounds) { if (isEmpty(bgUrl) || !this.siteSettings.allow_profile_backgrounds) {
return "".htmlSafe(); return "".htmlSafe();
} }
return ("background-image: url(" + getURLWithCDN(bgUrl) + ")").htmlSafe(); return ("background-image: url(" + getURLWithCDN(bgUrl) + ")").htmlSafe();
@ -664,7 +664,7 @@ const User = RestModel.extend({
return ( return (
this.staff || this.staff ||
this.trust_level > 0 || this.trust_level > 0 ||
Discourse.SiteSettings[`newuser_max_${type}s`] > 0 this.siteSettings[`newuser_max_${type}s`] > 0
); );
}, },
@ -724,7 +724,7 @@ const User = RestModel.extend({
@discourseComputed("can_delete_account") @discourseComputed("can_delete_account")
canDeleteAccount(canDeleteAccount) { canDeleteAccount(canDeleteAccount) {
return !Discourse.SiteSettings.enable_sso && canDeleteAccount; return !this.siteSettings.enable_sso && canDeleteAccount;
}, },
delete: function() { delete: function() {
@ -881,7 +881,7 @@ const User = RestModel.extend({
@discourseComputed("second_factor_enabled", "staff") @discourseComputed("second_factor_enabled", "staff")
enforcedSecondFactor(secondFactorEnabled, staff) { enforcedSecondFactor(secondFactorEnabled, staff) {
const enforce = Discourse.SiteSettings.enforce_second_factor; const enforce = this.siteSettings.enforce_second_factor;
return ( return (
!secondFactorEnabled && !secondFactorEnabled &&
(enforce === "all" || (enforce === "staff" && staff)) (enforce === "all" || (enforce === "staff" && staff))

View File

@ -35,6 +35,12 @@ export default {
app.inject(t, "messageBus", "message-bus:main") app.inject(t, "messageBus", "message-bus:main")
); );
const siteSettings = app.SiteSettings;
app.register("site-settings:main", siteSettings, { instantiate: false });
ALL_TARGETS.concat("service").forEach(t =>
app.inject(t, "siteSettings", "site-settings:main")
);
const currentUser = User.current(); const currentUser = User.current();
app.register("current-user:main", currentUser, { instantiate: false }); app.register("current-user:main", currentUser, { instantiate: false });
app.currentUser = currentUser; app.currentUser = currentUser;
@ -50,12 +56,6 @@ export default {
app.inject(t, "topicTrackingState", "topic-tracking-state:main") app.inject(t, "topicTrackingState", "topic-tracking-state:main")
); );
const siteSettings = app.SiteSettings;
app.register("site-settings:main", siteSettings, { instantiate: false });
ALL_TARGETS.concat("service").forEach(t =>
app.inject(t, "siteSettings", "site-settings:main")
);
const site = Site.current(); const site = Site.current();
app.register("site:main", site, { instantiate: false }); app.register("site:main", site, { instantiate: false });
ALL_TARGETS.forEach(t => app.inject(t, "site", "site:main")); ALL_TARGETS.forEach(t => app.inject(t, "site", "site:main"));