Skip to content

Commit

Permalink
DEV: attemps to limit Discourse.User.current() usage (#7943)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed Jul 26, 2019
1 parent 0603636 commit fe7f098
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 42 deletions.
Expand Up @@ -29,7 +29,7 @@ export default Ember.Controller.extend({
I18n.t("yes_value"),
confirmed => {
if (confirmed) {
Discourse.User.currentProp("hideReadOnlyAlert", true);
this.set("currentUser.hideReadOnlyAlert", true);
this._toggleReadOnlyMode(true);
}
}
Expand Down
Expand Up @@ -134,7 +134,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
return this.model.resetBounceScore();
},
approve() {
return this.model.approve();
return this.model.approve(this.currentUser);
},
deactivate() {
return this.model.deactivate();
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/admin/models/admin-user.js.es6
Expand Up @@ -227,14 +227,14 @@ const AdminUser = Discourse.User.extend({
.catch(popupAjaxError);
},

approve() {
approve(approvedBy) {
return ajax(`/admin/users/${this.id}/approve`, {
type: "PUT"
}).then(() => {
this.setProperties({
can_approve: false,
approved: true,
approved_by: Discourse.User.current()
approved_by: approvedBy
});
});
},
Expand Down
Expand Up @@ -11,7 +11,7 @@ export default Discourse.Route.extend({
},

sendInvites() {
this.transitionTo("userInvited", Discourse.User.current());
this.transitionTo("userInvited", this.currentUser);
},

deleteUser(user) {
Expand Down
Expand Up @@ -237,7 +237,7 @@ export default Ember.Component.extend({
reason = I18n.t("composer.error.post_missing");
} else if (missingReplyCharacters > 0) {
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) {
reason +=
"<br/>" +
Expand Down
Expand Up @@ -29,7 +29,7 @@ export default Ember.Component.extend(

@computed("disableActions")
canAct(disableActions) {
return Discourse.User.current() && !disableActions;
return this.currentUser && !disableActions;
},

buildBuffer(buffer) {
Expand Down
Expand Up @@ -17,7 +17,7 @@ export default Ember.Controller.extend({

@computed
loginRequired() {
return Discourse.SiteSettings.login_required && !Discourse.User.current();
return Discourse.SiteSettings.login_required && !this.currentUser;
},

@computed
Expand Down
Expand Up @@ -292,7 +292,7 @@ export default Ember.Controller.extend({

@computed("model.creatingPrivateMessage", "model.targetUsernames")
showWarning(creatingPrivateMessage, usernames) {
if (!Discourse.User.currentProp("staff")) {
if (!this.get("currentUser.staff")) {
return false;
}

Expand Down
Expand Up @@ -14,10 +14,7 @@ export default DiscoveryController.extend({
// this makes sure the composer isn't scoping to a specific category
category: null,

@computed
canEdit() {
return Discourse.User.currentProp("staff");
},
canEdit: Ember.computed.reads("currentUser.staff"),

@computed("model.categories.[].featuredTopics.length")
latestTopicOnly() {
Expand Down
Expand Up @@ -42,15 +42,9 @@ export default Ember.Controller.extend({
);
},

@computed
canInviteToForum() {
return Discourse.User.currentProp("can_invite_to_forum");
},
canInviteToForum: Ember.computed.reads("currentUser.can_invite_to_forum"),

@computed
canBulkInvite() {
return Discourse.User.currentProp("admin");
},
canBulkInvite: Ember.computed.reads("currentUser.admin"),

showSearch: Ember.computed.gte("totalInvites", 10),

Expand Down
Expand Up @@ -16,12 +16,10 @@ export default Ember.Controller.extend({
pmTaggingEnabled: Ember.computed.alias("site.can_tag_pms"),
tagId: null,

@computed("user.viewingSelf")
showNewPM(viewingSelf) {
return (
viewingSelf && Discourse.User.currentProp("can_send_private_messages")
);
},
showNewPM: Ember.computed.and(
"user.viewingSelf",
"currentUser.can_send_private_messages"
),

@computed("selected.[]", "bulkSelectEnabled")
hasSelection(selected, bulkSelectEnabled) {
Expand Down
Expand Up @@ -131,12 +131,7 @@ export default {

if (isPushNotificationsEnabled(user, site.mobileView)) {
disableDesktopNotifications();
registerPushNotifications(
Discourse.User.current(),
site.mobileView,
router,
appEvents
);
registerPushNotifications(user, site.mobileView, router, appEvents);
} else {
unsubscribePushNotifications(user);
}
Expand Down
6 changes: 0 additions & 6 deletions app/assets/javascripts/discourse/models/composer.js.es6
Expand Up @@ -308,12 +308,6 @@ const Composer = RestModel.extend({
return options;
},

@computed
isStaffUser() {
const currentUser = Discourse.User.current();
return currentUser && currentUser.staff;
},

@computed(
"loading",
"canEditTitle",
Expand Down
Expand Up @@ -191,10 +191,9 @@ export default DropdownSelectBoxComponent.extend({
});
}

const currentUser = Discourse.User.current();
const showToggleTopicBump =
currentUser &&
(currentUser.get("staff") || currentUser.trust_level === 4);
this.get("currentUser.staff") ||
this.get("currentUser.trust_level") === 4;

if (action === REPLY && showToggleTopicBump) {
items.push({
Expand Down

0 comments on commit fe7f098

Please sign in to comment.