From 11e43bd434697d7eca6aa48e3287d79ef2cac0ac Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 12 Aug 2014 16:55:23 -0400 Subject: [PATCH] FIX: Don't show Sign Up button in cases where users can't sign up --- .../javascripts/discourse/controllers/application.js.es6 | 6 ++++++ app/assets/javascripts/discourse/controllers/header.js.es6 | 3 +++ app/assets/javascripts/discourse/controllers/login.js.es6 | 7 +++---- .../javascripts/discourse/templates/header.js.handlebars | 2 ++ test/javascripts/controllers/header-test.js.es6 | 4 +++- test/javascripts/controllers/topic-test.js.es6 | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/application.js.es6 b/app/assets/javascripts/discourse/controllers/application.js.es6 index 29d200ca082..115654b621b 100644 --- a/app/assets/javascripts/discourse/controllers/application.js.es6 +++ b/app/assets/javascripts/discourse/controllers/application.js.es6 @@ -1,3 +1,9 @@ export default Ember.Controller.extend({ styleCategory: null, + + canSignUp: function() { + return !Discourse.SiteSettings.invite_only && + Discourse.SiteSettings.allow_new_registrations && + !Discourse.SiteSettings.enable_sso; + }.property(), }); diff --git a/app/assets/javascripts/discourse/controllers/header.js.es6 b/app/assets/javascripts/discourse/controllers/header.js.es6 index 90798d38f6b..47ff0ff9eaf 100644 --- a/app/assets/javascripts/discourse/controllers/header.js.es6 +++ b/app/assets/javascripts/discourse/controllers/header.js.es6 @@ -11,6 +11,9 @@ export default Discourse.Controller.extend({ showExtraInfo: null, notifications: null, loadingNotifications: false, + needs: ['application'], + + showSignUpButton: Em.computed.alias('controllers.application.canSignUp'), showStarButton: function() { return Discourse.User.current() && !this.get('topic.isPrivateMessage'); diff --git a/app/assets/javascripts/discourse/controllers/login.js.es6 b/app/assets/javascripts/discourse/controllers/login.js.es6 index 2fbf865c5e2..2515a7da632 100644 --- a/app/assets/javascripts/discourse/controllers/login.js.es6 +++ b/app/assets/javascripts/discourse/controllers/login.js.es6 @@ -8,7 +8,7 @@ @module Discourse **/ export default Discourse.Controller.extend(Discourse.ModalFunctionality, { - needs: ['modal', 'createAccount'], + needs: ['modal', 'createAccount', 'application'], authenticate: null, loggingIn: false, loggedIn: false, @@ -37,8 +37,7 @@ export default Discourse.Controller.extend(Discourse.ModalFunctionality, { loginDisabled: Em.computed.or('loggingIn', 'loggedIn'), showSignupLink: function() { - return !Discourse.SiteSettings.invite_only && - Discourse.SiteSettings.allow_new_registrations && + return this.get('controllers.application.canSignUp') && !this.get('loggingIn') && this.blank('authenticate'); }.property('loggingIn', 'authenticate'), @@ -77,7 +76,7 @@ export default Discourse.Controller.extend(Discourse.ModalFunctionality, { $hidden_login_form.submit(); } - }, function(e) { + }, function() { // Failed to login if (self.blank('loginName') || self.blank('loginPassword')) { self.flash(I18n.t('login.blank_username_or_password'), 'error'); diff --git a/app/assets/javascripts/discourse/templates/header.js.handlebars b/app/assets/javascripts/discourse/templates/header.js.handlebars index 89e24ba4bb1..4c4d7ba97fe 100644 --- a/app/assets/javascripts/discourse/templates/header.js.handlebars +++ b/app/assets/javascripts/discourse/templates/header.js.handlebars @@ -41,9 +41,11 @@ {{/unless}} {{#unless currentUser}} + {{#if showSignUpButton}} + {{/if}} diff --git a/test/javascripts/controllers/header-test.js.es6 b/test/javascripts/controllers/header-test.js.es6 index ead441172d6..aabbd9ad5ed 100644 --- a/test/javascripts/controllers/header-test.js.es6 +++ b/test/javascripts/controllers/header-test.js.es6 @@ -1,4 +1,6 @@ -moduleFor("controller:header", "controller:header"); +moduleFor("controller:header", "controller:header", { + needs: ['controller:application'] +}); test("showNotifications action", function() { var resolveRequestWith; diff --git a/test/javascripts/controllers/topic-test.js.es6 b/test/javascripts/controllers/topic-test.js.es6 index 6cae2006a84..cf853c0d3a1 100644 --- a/test/javascripts/controllers/topic-test.js.es6 +++ b/test/javascripts/controllers/topic-test.js.es6 @@ -1,6 +1,6 @@ moduleFor('controller:topic', 'controller:topic', { needs: ['controller:header', 'controller:modal', 'controller:composer', 'controller:quote-button', - 'controller:search', 'controller:topic-progress'] + 'controller:search', 'controller:topic-progress', 'controller:application'] }); var buildTopic = function() {