REFACTOR: Remove `Discourse.SiteSettings` from user/admin-user
This commit is contained in:
parent
a1507b2316
commit
ca13160435
|
@ -21,12 +21,7 @@ export default Component.extend({
|
|||
formSubmitted: false,
|
||||
actionName: "block",
|
||||
|
||||
@discourseComputed
|
||||
adminWhitelistEnabled() {
|
||||
return Discourse.SiteSettings.use_admin_ip_whitelist;
|
||||
},
|
||||
|
||||
@discourseComputed("adminWhitelistEnabled")
|
||||
@discourseComputed("siteSettings.use_admin_ip_whitelist")
|
||||
actionNames(adminWhitelistEnabled) {
|
||||
if (adminWhitelistEnabled) {
|
||||
return [
|
||||
|
|
|
@ -35,7 +35,7 @@ const AdminUser = User.extend({
|
|||
bounceScoreExplanation(bounce_score) {
|
||||
if (bounce_score === 0) {
|
||||
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");
|
||||
} else {
|
||||
return I18n.t("admin.user.bounce_score_explanation.threshold_reached");
|
||||
|
|
|
@ -2,6 +2,7 @@ import { warn } from "@ember/debug";
|
|||
import { equal } from "@ember/object/computed";
|
||||
import EmberObject from "@ember/object";
|
||||
import { Promise } from "rsvp";
|
||||
import { getOwner } from "discourse-common/lib/get-owner";
|
||||
|
||||
const RestModel = EmberObject.extend({
|
||||
isNew: equal("__state", "new"),
|
||||
|
@ -100,9 +101,16 @@ RestModel.reopenClass({
|
|||
|
||||
create(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) {
|
||||
const container = Discourse.__container__;
|
||||
args.store = container.lookup("service:store");
|
||||
args.store = owner.lookup("service:store");
|
||||
}
|
||||
if (!args.siteSettings) {
|
||||
args.siteSettings = owner.lookup("site-settings:main");
|
||||
}
|
||||
|
||||
args.__munge = this.munge;
|
||||
|
|
|
@ -262,7 +262,6 @@ export default EmberObject.extend({
|
|||
// TODO: Have injections be automatic
|
||||
obj.topicTrackingState = this.register.lookup("topic-tracking-state: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 model = klass.create(obj);
|
||||
|
|
|
@ -50,7 +50,7 @@ const User = RestModel.extend({
|
|||
|
||||
@discourseComputed("can_be_deleted", "post_count")
|
||||
canBeDeleted(canBeDeleted, postCount) {
|
||||
const maxPostCount = Discourse.SiteSettings.delete_all_posts_max;
|
||||
const maxPostCount = this.siteSettings.delete_all_posts_max;
|
||||
return canBeDeleted && postCount <= maxPostCount;
|
||||
},
|
||||
|
||||
|
@ -100,7 +100,7 @@ const User = RestModel.extend({
|
|||
|
||||
@discourseComputed("username", "name")
|
||||
displayName(username, name) {
|
||||
if (Discourse.SiteSettings.enable_names && !isEmpty(name)) {
|
||||
if (this.siteSettings.enable_names && !isEmpty(name)) {
|
||||
return name;
|
||||
}
|
||||
return username;
|
||||
|
@ -108,7 +108,7 @@ const User = RestModel.extend({
|
|||
|
||||
@discourseComputed("profile_background_upload_url")
|
||||
profileBackgroundUrl(bgUrl) {
|
||||
if (isEmpty(bgUrl) || !Discourse.SiteSettings.allow_profile_backgrounds) {
|
||||
if (isEmpty(bgUrl) || !this.siteSettings.allow_profile_backgrounds) {
|
||||
return "".htmlSafe();
|
||||
}
|
||||
return ("background-image: url(" + getURLWithCDN(bgUrl) + ")").htmlSafe();
|
||||
|
@ -664,7 +664,7 @@ const User = RestModel.extend({
|
|||
return (
|
||||
this.staff ||
|
||||
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")
|
||||
canDeleteAccount(canDeleteAccount) {
|
||||
return !Discourse.SiteSettings.enable_sso && canDeleteAccount;
|
||||
return !this.siteSettings.enable_sso && canDeleteAccount;
|
||||
},
|
||||
|
||||
delete: function() {
|
||||
|
@ -881,7 +881,7 @@ const User = RestModel.extend({
|
|||
|
||||
@discourseComputed("second_factor_enabled", "staff")
|
||||
enforcedSecondFactor(secondFactorEnabled, staff) {
|
||||
const enforce = Discourse.SiteSettings.enforce_second_factor;
|
||||
const enforce = this.siteSettings.enforce_second_factor;
|
||||
return (
|
||||
!secondFactorEnabled &&
|
||||
(enforce === "all" || (enforce === "staff" && staff))
|
||||
|
|
|
@ -35,6 +35,12 @@ export default {
|
|||
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();
|
||||
app.register("current-user:main", currentUser, { instantiate: false });
|
||||
app.currentUser = currentUser;
|
||||
|
@ -50,12 +56,6 @@ export default {
|
|||
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();
|
||||
app.register("site:main", site, { instantiate: false });
|
||||
ALL_TARGETS.forEach(t => app.inject(t, "site", "site:main"));
|
||||
|
|
Loading…
Reference in New Issue