DEV: attemps to limit Discourse.User.current() usage (#7943)

This commit is contained in:
Joffrey JAFFEUX 2019-07-26 11:20:11 +02:00 committed by GitHub
parent 0603636cea
commit fe7f0982af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 19 additions and 42 deletions

View File

@ -29,7 +29,7 @@ export default Ember.Controller.extend({
I18n.t("yes_value"), I18n.t("yes_value"),
confirmed => { confirmed => {
if (confirmed) { if (confirmed) {
Discourse.User.currentProp("hideReadOnlyAlert", true); this.set("currentUser.hideReadOnlyAlert", true);
this._toggleReadOnlyMode(true); this._toggleReadOnlyMode(true);
} }
} }

View File

@ -134,7 +134,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
return this.model.resetBounceScore(); return this.model.resetBounceScore();
}, },
approve() { approve() {
return this.model.approve(); return this.model.approve(this.currentUser);
}, },
deactivate() { deactivate() {
return this.model.deactivate(); return this.model.deactivate();

View File

@ -227,14 +227,14 @@ const AdminUser = Discourse.User.extend({
.catch(popupAjaxError); .catch(popupAjaxError);
}, },
approve() { approve(approvedBy) {
return ajax(`/admin/users/${this.id}/approve`, { return ajax(`/admin/users/${this.id}/approve`, {
type: "PUT" type: "PUT"
}).then(() => { }).then(() => {
this.setProperties({ this.setProperties({
can_approve: false, can_approve: false,
approved: true, approved: true,
approved_by: Discourse.User.current() approved_by: approvedBy
}); });
}); });
}, },

View File

@ -11,7 +11,7 @@ export default Discourse.Route.extend({
}, },
sendInvites() { sendInvites() {
this.transitionTo("userInvited", Discourse.User.current()); this.transitionTo("userInvited", this.currentUser);
}, },
deleteUser(user) { deleteUser(user) {

View File

@ -237,7 +237,7 @@ export default Ember.Component.extend({
reason = I18n.t("composer.error.post_missing"); reason = I18n.t("composer.error.post_missing");
} else if (missingReplyCharacters > 0) { } else if (missingReplyCharacters > 0) {
reason = I18n.t("composer.error.post_length", { min: minimumPostLength }); reason = I18n.t("composer.error.post_length", { min: minimumPostLength });
const tl = Discourse.User.currentProp("trust_level"); const tl = this.get("currentUser.trust_level");
if (tl === 0 || tl === 1) { if (tl === 0 || tl === 1) {
reason += reason +=
"<br/>" + "<br/>" +

View File

@ -29,7 +29,7 @@ export default Ember.Component.extend(
@computed("disableActions") @computed("disableActions")
canAct(disableActions) { canAct(disableActions) {
return Discourse.User.current() && !disableActions; return this.currentUser && !disableActions;
}, },
buildBuffer(buffer) { buildBuffer(buffer) {

View File

@ -17,7 +17,7 @@ export default Ember.Controller.extend({
@computed @computed
loginRequired() { loginRequired() {
return Discourse.SiteSettings.login_required && !Discourse.User.current(); return Discourse.SiteSettings.login_required && !this.currentUser;
}, },
@computed @computed

View File

@ -292,7 +292,7 @@ export default Ember.Controller.extend({
@computed("model.creatingPrivateMessage", "model.targetUsernames") @computed("model.creatingPrivateMessage", "model.targetUsernames")
showWarning(creatingPrivateMessage, usernames) { showWarning(creatingPrivateMessage, usernames) {
if (!Discourse.User.currentProp("staff")) { if (!this.get("currentUser.staff")) {
return false; return false;
} }

View File

@ -14,10 +14,7 @@ export default DiscoveryController.extend({
// this makes sure the composer isn't scoping to a specific category // this makes sure the composer isn't scoping to a specific category
category: null, category: null,
@computed canEdit: Ember.computed.reads("currentUser.staff"),
canEdit() {
return Discourse.User.currentProp("staff");
},
@computed("model.categories.[].featuredTopics.length") @computed("model.categories.[].featuredTopics.length")
latestTopicOnly() { latestTopicOnly() {

View File

@ -42,15 +42,9 @@ export default Ember.Controller.extend({
); );
}, },
@computed canInviteToForum: Ember.computed.reads("currentUser.can_invite_to_forum"),
canInviteToForum() {
return Discourse.User.currentProp("can_invite_to_forum");
},
@computed canBulkInvite: Ember.computed.reads("currentUser.admin"),
canBulkInvite() {
return Discourse.User.currentProp("admin");
},
showSearch: Ember.computed.gte("totalInvites", 10), showSearch: Ember.computed.gte("totalInvites", 10),

View File

@ -16,12 +16,10 @@ export default Ember.Controller.extend({
pmTaggingEnabled: Ember.computed.alias("site.can_tag_pms"), pmTaggingEnabled: Ember.computed.alias("site.can_tag_pms"),
tagId: null, tagId: null,
@computed("user.viewingSelf") showNewPM: Ember.computed.and(
showNewPM(viewingSelf) { "user.viewingSelf",
return ( "currentUser.can_send_private_messages"
viewingSelf && Discourse.User.currentProp("can_send_private_messages") ),
);
},
@computed("selected.[]", "bulkSelectEnabled") @computed("selected.[]", "bulkSelectEnabled")
hasSelection(selected, bulkSelectEnabled) { hasSelection(selected, bulkSelectEnabled) {

View File

@ -131,12 +131,7 @@ export default {
if (isPushNotificationsEnabled(user, site.mobileView)) { if (isPushNotificationsEnabled(user, site.mobileView)) {
disableDesktopNotifications(); disableDesktopNotifications();
registerPushNotifications( registerPushNotifications(user, site.mobileView, router, appEvents);
Discourse.User.current(),
site.mobileView,
router,
appEvents
);
} else { } else {
unsubscribePushNotifications(user); unsubscribePushNotifications(user);
} }

View File

@ -308,12 +308,6 @@ const Composer = RestModel.extend({
return options; return options;
}, },
@computed
isStaffUser() {
const currentUser = Discourse.User.current();
return currentUser && currentUser.staff;
},
@computed( @computed(
"loading", "loading",
"canEditTitle", "canEditTitle",

View File

@ -191,10 +191,9 @@ export default DropdownSelectBoxComponent.extend({
}); });
} }
const currentUser = Discourse.User.current();
const showToggleTopicBump = const showToggleTopicBump =
currentUser && this.get("currentUser.staff") ||
(currentUser.get("staff") || currentUser.trust_level === 4); this.get("currentUser.trust_level") === 4;
if (action === REPLY && showToggleTopicBump) { if (action === REPLY && showToggleTopicBump) {
items.push({ items.push({