mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Refactor: Removed the last of the references to Discourse.currentUser
.
This commit is contained in:
parent
57f97880e6
commit
dd54736d06
23 changed files with 96 additions and 63 deletions
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
A base admin controller that has access to the Discourse properties.
|
||||
|
||||
@class AdminController
|
||||
@extends Discourse.Controller
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.AdminCustomizeController = Discourse.Controller.extend({});
|
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
A controller related to viewing a user in the admin section
|
||||
|
||||
@class AdminUserController
|
||||
@extends Discourse.ObjectController
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.AdminUserController = Discourse.ObjectController.extend({});
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<ul class="nav nav-pills">
|
||||
<li>{{#linkTo 'admin.dashboard'}}{{i18n admin.dashboard.title}}{{/linkTo}}</li>
|
||||
{{#if Discourse.currentUser.admin}}
|
||||
{{#if currentUser.admin}}
|
||||
<li>{{#linkTo 'admin.site_settings'}}{{i18n admin.site_settings.title}}{{/linkTo}}</li>
|
||||
<li>{{#linkTo 'adminSiteContents'}}{{i18n admin.site_content.title}}{{/linkTo}}</li>
|
||||
{{/if}}
|
||||
|
@ -12,7 +12,7 @@
|
|||
<li>{{#linkTo 'admin.groups'}}{{i18n admin.groups.title}}{{/linkTo}}</li>
|
||||
<li>{{#linkTo 'admin.email_logs'}}{{i18n admin.email_logs.title}}{{/linkTo}}</li>
|
||||
<li>{{#linkTo 'adminFlags.active'}}{{i18n admin.flags.title}}{{/linkTo}}</li>
|
||||
{{#if Discourse.currentUser.admin}}
|
||||
{{#if currentUser.admin}}
|
||||
<li>{{#linkTo 'admin.customize'}}{{i18n admin.customize.title}}{{/linkTo}}</li>
|
||||
<li>{{#linkTo 'admin.api'}}{{i18n admin.api.title}}{{/linkTo}}</li>
|
||||
{{/if}}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<div class='field'>{{i18n user.ip_address.title}}</div>
|
||||
<div class='value'>{{ip_address}}</div>
|
||||
<div class='controls'>
|
||||
{{#if Discourse.currentUser.admin}}
|
||||
{{#if currentUser.admin}}
|
||||
<button class='btn' {{action refreshBrowsers target="content"}}>
|
||||
{{i18n admin.user.refresh_browsers}}
|
||||
</button>
|
||||
|
|
|
@ -93,10 +93,12 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
}).then(function(opts) {
|
||||
opts = opts || {};
|
||||
_this.close();
|
||||
|
||||
var currentUser = Discourse.User.current();
|
||||
if (composer.get('creatingTopic')) {
|
||||
Discourse.set('currentUser.topic_count', Discourse.User.current('topic_count') + 1);
|
||||
currentUser.set('topic_count', currentUser.get('topic_count') + 1);
|
||||
} else {
|
||||
Discourse.set('currentUser.reply_count', Discourse.User.current('reply_count') + 1);
|
||||
currentUser.set('reply_count', currentUser.get('reply_count') + 1);
|
||||
}
|
||||
Discourse.URL.routeTo(opts.post.get('url'));
|
||||
}, function(error) {
|
||||
|
@ -151,7 +153,8 @@ Discourse.ComposerController = Discourse.Controller.extend({
|
|||
Discourse.ajax("/education/" + educationKey, {dataType: 'html'}).then(function(result) {
|
||||
composerController.set('educationContents', result);
|
||||
});
|
||||
}.observes('typedReply', 'content.creatingTopic', 'Discourse.currentUser.reply_count'),
|
||||
|
||||
}.observes('typedReply', 'content.creatingTopic', 'currentUser.reply_count'),
|
||||
|
||||
checkReplyLength: function() {
|
||||
this.set('typedReply', this.present('content.reply'));
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
/**
|
||||
A base controller for Discourse that includes Presence support.
|
||||
|
||||
@class Controller
|
||||
@class Controller
|
||||
@extends Ember.Controller
|
||||
@namespace Discourse
|
||||
@uses Discourse.Presence
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.Controller = Ember.Controller.extend(Discourse.Presence);
|
||||
|
||||
|
||||
**/
|
||||
Discourse.Controller = Ember.Controller.extend(Discourse.Presence, Discourse.HasCurrentUser);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
@module Discourse
|
||||
**/
|
||||
Discourse.ListController = Discourse.Controller.extend({
|
||||
currentUserBinding: 'Discourse.currentUser',
|
||||
categoryBinding: 'topicList.category',
|
||||
canCreateCategory: false,
|
||||
canCreateTopic: false,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
A custom object controller for Discourse
|
||||
|
||||
@class ObjectController
|
||||
@class ObjectController
|
||||
@extends Ember.ObjectController
|
||||
@namespace Discourse
|
||||
@uses Discourse.Presence
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence);
|
||||
**/
|
||||
Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence, Discourse.HasCurrentUser);
|
||||
|
||||
|
||||
|
|
|
@ -334,7 +334,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||
},
|
||||
|
||||
/**
|
||||
Clears the pin from a topic for the currentUser
|
||||
Clears the pin from a topic for the currently logged in user
|
||||
|
||||
@method clearPin
|
||||
**/
|
||||
|
|
31
app/assets/javascripts/discourse/mixins/has_current_user.js
Normal file
31
app/assets/javascripts/discourse/mixins/has_current_user.js
Normal 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()
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -338,7 +338,7 @@ Discourse.Topic = Discourse.Model.extend({
|
|||
},
|
||||
|
||||
/**
|
||||
Clears the pin from a topic for the currentUser
|
||||
Clears the pin from a topic for the currently logged in user
|
||||
|
||||
@method clearPin
|
||||
**/
|
||||
|
|
|
@ -160,8 +160,8 @@ Discourse.User = Discourse.Model.extend({
|
|||
type: 'PUT'
|
||||
}).then(function(data) {
|
||||
user.set('bio_excerpt',data.user.bio_excerpt);
|
||||
Discourse.set('currentUser.enable_quoting', user.get('enable_quoting'));
|
||||
Discourse.set('currentUser.external_links_in_new_tab', user.get('external_links_in_new_tab'));
|
||||
Discourse.User.current().set('enable_quoting', user.get('enable_quoting'));
|
||||
Discourse.User.current().set('external_links_in_new_tab', user.get('external_links_in_new_tab'));
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
/**
|
||||
The base Application route
|
||||
|
||||
@class ApplicationRoute
|
||||
@extends Discourse.Route
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.ApplicationRoute = Discourse.Route.extend({
|
||||
setupController: function(controller) {
|
||||
Discourse.set('currentUser', Discourse.User.current());
|
||||
}
|
||||
});
|
|
@ -66,7 +66,7 @@
|
|||
<div class='preview-wrapper'>
|
||||
<div id='wmd-preview' {{bindAttr class="hidePreview:hidden"}}></div>
|
||||
</div>
|
||||
{{#if Discourse.currentUser}}
|
||||
{{#if currentUser}}
|
||||
<a href="#" {{action togglePreview}} class='toggle-preview'>{{{content.toggleText}}}</a>
|
||||
<div id='draft-status'></div>
|
||||
{{#if view.loadingImage}}
|
||||
|
@ -77,7 +77,7 @@
|
|||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#if Discourse.currentUser}}
|
||||
{{#if currentUser}}
|
||||
<div class='submit-panel'>
|
||||
<button {{action save}} tabindex="4" {{bindAttr class=":btn :btn-primary :create content.cantSubmitPost:disabled"}}>{{view.content.saveText}}</button>
|
||||
<a href='#' {{action cancel}} class='cancel' tabindex="4">{{i18n cancel}}</a>
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
<div class='panel clearfix'>
|
||||
{{#unless showExtraInfo}}
|
||||
<div class='current-username'>
|
||||
{{#if view.currentUser}}
|
||||
<span class='username'><a {{bindAttr href="view.currentUser.path"}}>{{view.currentUser.name}}</a></span>
|
||||
{{#if currentUser}}
|
||||
<span class='username'><a {{bindAttr href="currentUser.path"}}>{{currentUser.name}}</a></span>
|
||||
{{else}}
|
||||
<button {{action showLogin}} class='btn btn-primary btn-small'>{{i18n log_in}}</button>
|
||||
{{/if}}
|
||||
|
@ -16,13 +16,13 @@
|
|||
{{/unless}}
|
||||
<ul class='icons clearfix'>
|
||||
<li class='notifications'>
|
||||
{{#if view.currentUser}}
|
||||
{{#if currentUser}}
|
||||
<a class='icon' href="#" {{action showNotifications target="view"}} data-notifications="notifications-dropdown" id='user-notifications' title='{{i18n notifications.title}}'><i class='icon-comment'></i></a>
|
||||
{{#if view.currentUser.unread_notifications}}
|
||||
<a href='#' class='badge-notification unread-notifications'>{{view.currentUser.unread_notifications}}</a>
|
||||
{{#if currentUser.unread_notifications}}
|
||||
<a href='#' class='badge-notification unread-notifications'>{{currentUser.unread_notifications}}</a>
|
||||
{{/if}}
|
||||
{{#if view.currentUser.unread_private_messages}}
|
||||
<a href='#' class='badge-notification unread-private-messages'>{{view.currentUser.unread_private_messages}}</a>
|
||||
{{#if currentUser.unread_private_messages}}
|
||||
<a href='#' class='badge-notification unread-private-messages'>{{currentUser.unread_private_messages}}</a>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<a class='icon' href="#" {{action showLogin}} title='{{i18n notifications.title}}'><i class='icon-comment'></i></a>
|
||||
|
@ -33,13 +33,13 @@
|
|||
</li>
|
||||
<li class='categories dropdown'>
|
||||
<a class='icon' data-dropdown="site-map-dropdown" href="#" title='{{i18n site_map}}'><i class='icon-reorder'></i></a>
|
||||
{{#if view.currentUser.site_flagged_posts_count}}
|
||||
<a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{view.currentUser.site_flagged_posts_count}}</a>
|
||||
{{#if currentUser.site_flagged_posts_count}}
|
||||
<a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{currentUser.site_flagged_posts_count}}</a>
|
||||
{{/if}}
|
||||
</li>
|
||||
<li class='current-user'>
|
||||
{{#if view.currentUser}}
|
||||
{{#titledLinkTo user.activity view.currentUser titleKey="current_user" class="icon"}}{{avatar Discourse.currentUser imageSize="medium" }}{{/titledLinkTo}}
|
||||
{{#if currentUser}}
|
||||
{{#titledLinkTo user.activity currentUser titleKey="current_user" class="icon"}}{{avatar currentUser imageSize="medium" }}{{/titledLinkTo}}
|
||||
{{else}}
|
||||
<div class="icon not-logged-in-avatar" {{action showLogin}}><i class='icon-user'></i></div>
|
||||
{{/if}}
|
||||
|
@ -55,7 +55,7 @@
|
|||
<li class="{{unbound readClass}}">{{{unbound rendered}}}</li>
|
||||
{{/each}}
|
||||
<li class='read last'>
|
||||
<a {{bindAttr href="view.currentUser.path"}}>{{i18n notifications.more}} …</a>
|
||||
<a {{bindAttr href="currentUser.path"}}>{{i18n notifications.more}} …</a>
|
||||
</li>
|
||||
</ul>
|
||||
{{else}}
|
||||
|
@ -65,11 +65,11 @@
|
|||
|
||||
<section class='d-dropdown' id='site-map-dropdown'>
|
||||
<ul>
|
||||
{{#if Discourse.currentUser.staff}}
|
||||
{{#if currentUser.staff}}
|
||||
<li><a href="/admin"><i class='icon icon-cog'></i>{{i18n admin_title}}</a></li>
|
||||
<li><a href="/admin/flags/active"><i class='icon icon-flag'></i>{{i18n flags_title}}</a>
|
||||
{{#if view.currentUser.site_flagged_posts_count}}
|
||||
<a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{view.currentUser.site_flagged_posts_count}}</a>
|
||||
{{#if currentUser.site_flagged_posts_count}}
|
||||
<a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{currentUser.site_flagged_posts_count}}</a>
|
||||
{{/if}}
|
||||
</li>
|
||||
{{/if}}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
{{#if Discourse.currentUser.id}}
|
||||
{{#if controller.currentUser.id}}
|
||||
<td class='star'>
|
||||
<a {{bindAttr class=":star :icon-star starred:starred"}} {{action toggleStar this}} href='#' {{bindAttr title="favoriteTooltip"}}></a>
|
||||
</td>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<table id='topic-list'>
|
||||
<thead>
|
||||
<tr>
|
||||
{{#if Discourse.currentUser}}
|
||||
{{#if currentUser}}
|
||||
<th> </th>
|
||||
{{/if}}
|
||||
<th>
|
||||
|
|
|
@ -138,6 +138,6 @@
|
|||
{{render share}}
|
||||
{{render quoteButton}}
|
||||
|
||||
{{#if Discourse.currentUser.staff}}
|
||||
{{#if currentUser.staff}}
|
||||
{{render topicAdminMenu content}}
|
||||
{{/if}}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
{{#if viewingSelf}}
|
||||
<button {{action "logout" target="Discourse"}} class='btn'>{{i18n user.log_out}}</button>
|
||||
{{/if}}
|
||||
{{#if Discourse.currentUser.staff}}
|
||||
{{#if currentUser.staff}}
|
||||
<a href="{{unbound adminPath}}" class='btn'><i class="icon-wrench"></i> {{i18n admin.user.show_admin_profile}}</a>
|
||||
{{/if}}
|
||||
<ul class="nav nav-pills">
|
||||
|
|
|
@ -11,7 +11,6 @@ Discourse.HeaderView = Discourse.View.extend({
|
|||
classNames: ['d-header', 'clearfix'],
|
||||
classNameBindings: ['editingTopic'],
|
||||
templateName: 'header',
|
||||
currentUserBinding: 'Discourse.currentUser',
|
||||
topicBinding: 'Discourse.router.topicController.content',
|
||||
|
||||
showDropdown: function($target) {
|
||||
|
@ -58,7 +57,7 @@ Discourse.HeaderView = Discourse.View.extend({
|
|||
}));
|
||||
|
||||
// We've seen all the notifications now
|
||||
headerView.set('currentUser.unread_notifications', 0);
|
||||
Discourse.User.current.set('unread_notifications', 0);
|
||||
headerView.showDropdown($('#user-notifications'));
|
||||
});
|
||||
return false;
|
||||
|
|
|
@ -14,9 +14,9 @@ Discourse.TopicExtraInfoView = Ember.ContainerView.extend({
|
|||
templateName: 'topic_extra_info',
|
||||
classNames: ['extra-info'],
|
||||
topicBinding: 'controller.topic',
|
||||
showFavoriteButton: (function() {
|
||||
return Discourse.currentUser && !this.get('topic.isPrivateMessage');
|
||||
}).property('topic.isPrivateMessage')
|
||||
showFavoriteButton: function() {
|
||||
return Discourse.User.current() && !this.get('topic.isPrivateMessage');
|
||||
}.property('topic.isPrivateMessage')
|
||||
})
|
||||
|
||||
});
|
||||
|
|
|
@ -339,9 +339,9 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
|
|||
return false;
|
||||
},
|
||||
|
||||
showFavoriteButton: (function() {
|
||||
return Discourse.currentUser && !this.get('topic.isPrivateMessage');
|
||||
}).property('topic.isPrivateMessage'),
|
||||
showFavoriteButton: function() {
|
||||
return Discourse.User.current() && !this.get('topic.isPrivateMessage');
|
||||
}.property('topic.isPrivateMessage'),
|
||||
|
||||
resetExamineDockCache: function() {
|
||||
this.docAt = null;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
**/
|
||||
Discourse.UserActivityView = Discourse.View.extend({
|
||||
templateName: 'user/activity',
|
||||
currentUserBinding: 'Discourse.currentUser',
|
||||
userBinding: 'controller.content',
|
||||
|
||||
didInsertElement: function() {
|
||||
|
|
Loading…
Reference in a new issue