Revert "inject currentUser into controllers & routes"

This reverts commit 7ec34b205a.
This commit is contained in:
Sam 2013-09-11 13:26:46 +10:00
parent e420ce3da3
commit 681ff74cb8
10 changed files with 50 additions and 35 deletions

View File

@ -229,21 +229,3 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
Discourse.Router = Discourse.Router.reopen({ location: 'discourse_location' });
Discourse.initializer({
name: 'currentUser',
initialize: function(container) {
container.register('user:current', Discourse.User.current(), { instantiate: false });
}
});
Discourse.initializer({
name: 'injectCurrentUser',
initialize: function(container) {
if (container.lookup('user:current')) {
container.injection('controller', 'currentUser', 'user:current');
container.injection('route', 'currentUser', 'user:current');
}
}
});

View File

@ -103,7 +103,7 @@ Discourse.ComposerController = Discourse.Controller.extend({
opts = opts || {};
composerController.close();
var currentUser = this.get('currentUser');
var currentUser = Discourse.User.current();
if (composer.get('creatingTopic')) {
currentUser.set('topic_count', currentUser.get('topic_count') + 1);
} else {

View File

@ -7,4 +7,4 @@
@uses Discourse.Presence
@module Discourse
**/
Discourse.Controller = Ember.Controller.extend(Discourse.Presence);
Discourse.Controller = Ember.Controller.extend(Discourse.Presence, Discourse.HasCurrentUser);

View File

@ -21,8 +21,8 @@ Discourse.HeaderController = Discourse.Controller.extend({
}.property(),
showFavoriteButton: function() {
return this.get('currentUser') && !this.get('topic.isPrivateMessage');
}.property('currentUser', 'topic.isPrivateMessage'),
return Discourse.User.current() && !this.get('topic.isPrivateMessage');
}.property('topic.isPrivateMessage'),
mobileDevice: function() {
return Discourse.Mobile.isMobileDevice;

View File

@ -13,7 +13,7 @@ Discourse.ListController = Discourse.Controller.extend({
needs: ['composer', 'modal', 'listTopics'],
availableNavItems: function() {
var loggedOn = !!this.get('currentUser');
var loggedOn = !!Discourse.User.current();
return Discourse.SiteSettings.top_menu.split("|").map(function(i) {
return Discourse.NavItem.fromText(i, {
@ -22,7 +22,7 @@ Discourse.ListController = Discourse.Controller.extend({
}).filter(function(i) {
return i !== null;
});
}.property('currentUser'),
}.property(),
createTopicText: function() {
if (this.get('category.name')) {
@ -125,12 +125,12 @@ Discourse.ListController = Discourse.Controller.extend({
canEditCategory: function() {
if( this.present('category') ) {
var u = this.get('currentUser');
var u = Discourse.User.current();
return u && u.staff;
} else {
return false;
}
}.property('currentUser', 'category')
}.property('category')
});

View File

@ -7,4 +7,6 @@
@uses Discourse.Presence
@module Discourse
**/
Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence);
Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence, Discourse.HasCurrentUser);

View File

@ -31,7 +31,7 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
**/
selectText: function(postId) {
// anonymous users cannot "quote-reply"
if (!this.get('currentUser')) return;
if (!Discourse.User.current()) return;
// don't display the "quote-reply" button if we can't create a post
if (!this.get('controllers.topic.model.details.can_create_post')) return;

View File

@ -260,8 +260,8 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
},
showFavoriteButton: function() {
return this.get('currentUser') && !this.get('isPrivateMessage');
}.property('currentUser', 'isPrivateMessage'),
return Discourse.User.current() && !this.get('isPrivateMessage');
}.property('isPrivateMessage'),
recoverTopic: function() {
this.get('content').recover();
@ -269,7 +269,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
deleteTopic: function() {
this.unsubscribe();
this.get('content').destroy(this.get('currentUser'));
this.get('content').destroy(Discourse.User.current());
},
resetRead: function() {
@ -417,7 +417,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
},
toggleBookmark: function(post) {
if (!this.get('currentUser')) {
if (!Discourse.User.current()) {
alert(I18n.t("bookmarks.not_bookmarked"));
return;
}
@ -439,7 +439,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
},
deletePost: function(post) {
var user = this.get('currentUser'),
var user = Discourse.User.current(),
replyCount = post.get('reply_count'),
self = this;

View File

@ -0,0 +1,31 @@
/**
This mixin provides a `currentUser` property that can be used to retrieve information
about the currently logged in user. It is mostly useful to controllers so it can be
exposted to templates.
Outside of templates, code should probably use `Discourse.User.current()` instead of
this property.
@class Discourse.HasCurrentUser
@extends Ember.Mixin
@namespace Discourse
@module HasCurrentUser
**/
Discourse.HasCurrentUser = Em.Mixin.create({
/**
Returns a reference to the currently logged in user.
@method currentUser
@return {Discourse.User} the currently logged in user if present.
*/
currentUser: function() {
return Discourse.User.current();
}.property().volatile()
});

View File

@ -12,7 +12,7 @@ Discourse.UserRoute = Discourse.Route.extend({
// If we're viewing the currently logged in user, return that object
// instead.
var currentUser = this.get('currentUser');
var currentUser = Discourse.User.current();
if (currentUser && (params.username.toLowerCase() === currentUser.get('username_lower'))) {
return currentUser;
}
@ -95,7 +95,7 @@ Discourse.UserActivityRoute = Discourse.Route.extend({
var composerController = this.controllerFor('composer');
controller.set('model', user);
if (this.get('currentUser')) {
if (Discourse.User.current()) {
Discourse.Draft.get('new_private_message').then(function(data) {
if (data.draft) {
composerController.open({