Using Discourse.XYZ in templates is deprecated. This fixes that, plus

adds some more integration tests to make sure login required is working.
This commit is contained in:
Robin Ward 2014-09-05 13:08:28 -04:00
parent 4907053cc4
commit 4bec839d9d
8 changed files with 37 additions and 13 deletions

View file

@ -98,14 +98,6 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
return loginController.authenticationComplete(options);
},
loginRequired: function() {
return Discourse.SiteSettings.login_required && !Discourse.User.current();
}.property().volatile(),
redirectIfLoginRequired: function(route) {
if(this.get('loginRequired')) { route.transitionTo('login'); }
},
/**
Start up the Discourse application by running all the initializers we've defined.

View file

@ -6,4 +6,9 @@ export default Ember.Controller.extend({
Discourse.SiteSettings.allow_new_registrations &&
!Discourse.SiteSettings.enable_sso;
}.property(),
loginRequired: function() {
return Discourse.SiteSettings.login_required && !Discourse.User.current();
}.property()
});

View file

@ -7,6 +7,7 @@ export default DiscourseController.extend({
loadingNotifications: false,
needs: ['application'],
loginRequired: Em.computed.alias('controllers.application.loginRequired'),
canSignUp: Em.computed.alias('controllers.application.canSignUp'),
showSignUpButton: function() {

View file

@ -21,6 +21,13 @@ Discourse.Route = Em.Route.extend({
Em.run.scheduleOnce('afterRender', Discourse.Route, 'cleanDOM');
},
redirectIfLoginRequired: function() {
var app = this.controllerFor('application');
if (app.get('loginRequired')) {
this.replaceWith('login');
}
},
openTopicDraft: function(model){
// If there's a draft, open the create topic composer
if (model.draft) {

View file

@ -8,8 +8,7 @@
@module Discourse
**/
Discourse.DiscoveryRoute = Discourse.Route.extend(Discourse.ScrollTop, Discourse.OpenComposer, {
redirect: function() { Discourse.redirectIfLoginRequired(this); },
redirect: function() { return this.redirectIfLoginRequired(); },
beforeModel: function(transition) {
if (transition.targetName.indexOf("discovery.top") === -1 &&

View file

@ -4,7 +4,7 @@ var isTransitioning = false,
SCROLL_DELAY = 500;
Discourse.TopicRoute = Discourse.Route.extend({
redirect: function() { Discourse.redirectIfLoginRequired(this); },
redirect: function() { return this.redirectIfLoginRequired(); },
queryParams: {
filter: { replace: true },

View file

@ -65,7 +65,7 @@
</li>
{{/if}}
<li>
{{#if Discourse.loginRequired}}
{{#if loginRequired}}
<a id='search-button' class='icon expand' href='#' aria-hidden="true" {{action showLogin}}>
{{icon search}}
</a>
@ -80,7 +80,7 @@
{{/if}}
</li>
<li class='categories dropdown'>
{{#if Discourse.loginRequired}}
{{#if loginRequired}}
<a class='icon'
href="#"
aria-hidden="true"

View file

@ -19,4 +19,24 @@ test("redirect", function() {
andThen(function() {
ok(exists('.login-modal'), "they can still access the login modal");
});
click('.modal-header .close');
andThen(function() {
ok(!exists('.login-modal'), "it closes the login modal");
});
click('#search-button');
andThen(function() {
ok(exists('.login-modal'), "clicking search opens the login modal");
});
click('.modal-header .close');
andThen(function() {
ok(!exists('.login-modal'), "it closes the login modal");
});
click('#site-map');
andThen(function() {
ok(exists('.login-modal'), "site map opens the login modal");
});
});