From 60a9030d25d8f48102d4fbc975766d39d6fb3793 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 16 Jan 2017 16:33:14 -0500 Subject: [PATCH] UX: don't show search and hamburger menus to anon visitors on login-required sites --- .../discourse/widgets/header.js.es6 | 2 + .../acceptance/login-required-test.js.es6 | 15 -------- test/javascripts/widgets/header-test.js.es6 | 38 +++++++++++++++++++ 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/header.js.es6 b/app/assets/javascripts/discourse/widgets/header.js.es6 index 03fe6a6901e..e4abd884939 100644 --- a/app/assets/javascripts/discourse/widgets/header.js.es6 +++ b/app/assets/javascripts/discourse/widgets/header.js.es6 @@ -104,6 +104,8 @@ createWidget('header-icons', { }, html(attrs) { + if (this.siteSettings.login_required && !this.currentUser) { return []; } + const hamburger = this.attach('header-dropdown', { title: 'hamburger_menu', icon: 'bars', diff --git a/test/javascripts/acceptance/login-required-test.js.es6 b/test/javascripts/acceptance/login-required-test.js.es6 index abdb2eea949..4bbec697a41 100644 --- a/test/javascripts/acceptance/login-required-test.js.es6 +++ b/test/javascripts/acceptance/login-required-test.js.es6 @@ -26,19 +26,4 @@ test("redirect", () => { andThen(() => { ok(invisible('.login-modal'), "it closes the login modal"); }); - - click('#search-button'); - andThen(() => { - ok(exists('.login-modal'), "clicking search opens the login modal"); - }); - - click('.modal-header .close'); - andThen(() => { - ok(invisible('.login-modal'), "it closes the login modal"); - }); - - click('#toggle-hamburger-menu'); - andThen(() => { - ok(exists('.login-modal'), "site map opens the login modal"); - }); }); diff --git a/test/javascripts/widgets/header-test.js.es6 b/test/javascripts/widgets/header-test.js.es6 index f3a7b8f9071..71676a0338c 100644 --- a/test/javascripts/widgets/header-test.js.es6 +++ b/test/javascripts/widgets/header-test.js.es6 @@ -35,3 +35,41 @@ widgetTest('sign up / login buttons', { }); } }); + +widgetTest('anon when login required', { + template: '{{mount-widget widget="header" showCreateAccount="showCreateAccount" showLogin="showLogin" args=args}}', + anonymous: true, + + setup() { + this.set('args', { canSignUp: true }); + this.on('showCreateAccount', () => this.signupShown = true); + this.on('showLogin', () => this.loginShown = true); + this.siteSettings.login_required = true; + }, + + test(assert) { + assert.ok(exists('button.login-button')); + assert.ok(exists('button.sign-up-button')); + assert.ok(!exists('#search-button')); + assert.ok(!exists('#toggle-hamburger-menu')); + } +}); + +widgetTest('logged in when login required', { + template: '{{mount-widget widget="header" showCreateAccount="showCreateAccount" showLogin="showLogin" args=args}}', + + setup() { + this.set('args', { canSignUp: true }); + this.on('showCreateAccount', () => this.signupShown = true); + this.on('showLogin', () => this.loginShown = true); + this.siteSettings.login_required = true; + }, + + test(assert) { + assert.ok(!exists('button.login-button')); + assert.ok(!exists('button.sign-up-button')); + assert.ok(exists('#search-button')); + assert.ok(exists('#toggle-hamburger-menu')); + assert.ok(exists('#current-user')); + } +});