mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
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:
parent
4907053cc4
commit
4bec839d9d
8 changed files with 37 additions and 13 deletions
|
@ -98,14 +98,6 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
||||||
return loginController.authenticationComplete(options);
|
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.
|
Start up the Discourse application by running all the initializers we've defined.
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,9 @@ export default Ember.Controller.extend({
|
||||||
Discourse.SiteSettings.allow_new_registrations &&
|
Discourse.SiteSettings.allow_new_registrations &&
|
||||||
!Discourse.SiteSettings.enable_sso;
|
!Discourse.SiteSettings.enable_sso;
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
|
loginRequired: function() {
|
||||||
|
return Discourse.SiteSettings.login_required && !Discourse.User.current();
|
||||||
|
}.property()
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@ export default DiscourseController.extend({
|
||||||
loadingNotifications: false,
|
loadingNotifications: false,
|
||||||
needs: ['application'],
|
needs: ['application'],
|
||||||
|
|
||||||
|
loginRequired: Em.computed.alias('controllers.application.loginRequired'),
|
||||||
canSignUp: Em.computed.alias('controllers.application.canSignUp'),
|
canSignUp: Em.computed.alias('controllers.application.canSignUp'),
|
||||||
|
|
||||||
showSignUpButton: function() {
|
showSignUpButton: function() {
|
||||||
|
|
|
@ -21,6 +21,13 @@ Discourse.Route = Em.Route.extend({
|
||||||
Em.run.scheduleOnce('afterRender', Discourse.Route, 'cleanDOM');
|
Em.run.scheduleOnce('afterRender', Discourse.Route, 'cleanDOM');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
redirectIfLoginRequired: function() {
|
||||||
|
var app = this.controllerFor('application');
|
||||||
|
if (app.get('loginRequired')) {
|
||||||
|
this.replaceWith('login');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
openTopicDraft: function(model){
|
openTopicDraft: function(model){
|
||||||
// If there's a draft, open the create topic composer
|
// If there's a draft, open the create topic composer
|
||||||
if (model.draft) {
|
if (model.draft) {
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.DiscoveryRoute = Discourse.Route.extend(Discourse.ScrollTop, Discourse.OpenComposer, {
|
Discourse.DiscoveryRoute = Discourse.Route.extend(Discourse.ScrollTop, Discourse.OpenComposer, {
|
||||||
|
redirect: function() { return this.redirectIfLoginRequired(); },
|
||||||
redirect: function() { Discourse.redirectIfLoginRequired(this); },
|
|
||||||
|
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
if (transition.targetName.indexOf("discovery.top") === -1 &&
|
if (transition.targetName.indexOf("discovery.top") === -1 &&
|
||||||
|
|
|
@ -4,7 +4,7 @@ var isTransitioning = false,
|
||||||
SCROLL_DELAY = 500;
|
SCROLL_DELAY = 500;
|
||||||
|
|
||||||
Discourse.TopicRoute = Discourse.Route.extend({
|
Discourse.TopicRoute = Discourse.Route.extend({
|
||||||
redirect: function() { Discourse.redirectIfLoginRequired(this); },
|
redirect: function() { return this.redirectIfLoginRequired(); },
|
||||||
|
|
||||||
queryParams: {
|
queryParams: {
|
||||||
filter: { replace: true },
|
filter: { replace: true },
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<li>
|
<li>
|
||||||
{{#if Discourse.loginRequired}}
|
{{#if loginRequired}}
|
||||||
<a id='search-button' class='icon expand' href='#' aria-hidden="true" {{action showLogin}}>
|
<a id='search-button' class='icon expand' href='#' aria-hidden="true" {{action showLogin}}>
|
||||||
{{icon search}}
|
{{icon search}}
|
||||||
</a>
|
</a>
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</li>
|
</li>
|
||||||
<li class='categories dropdown'>
|
<li class='categories dropdown'>
|
||||||
{{#if Discourse.loginRequired}}
|
{{#if loginRequired}}
|
||||||
<a class='icon'
|
<a class='icon'
|
||||||
href="#"
|
href="#"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
|
|
|
@ -19,4 +19,24 @@ test("redirect", function() {
|
||||||
andThen(function() {
|
andThen(function() {
|
||||||
ok(exists('.login-modal'), "they can still access the login modal");
|
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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue