FIX: hide sidebar toggle button when no sidebar (#18068)

When sidebar is not available (for example for anonymous user for sites which requires log in), toggle button should be hidden as well.
This commit is contained in:
Krzysztof Kotlarek 2022-08-24 14:09:40 +10:00 committed by GitHub
parent 6771673a1b
commit 7a58bd8827
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions

View File

@ -18,8 +18,7 @@ export default Controller.extend({
init() { init() {
this._super(...arguments); this._super(...arguments);
this.showSidebar = this.showSidebar =
(this.currentUser || !this.siteSettings.login_required) && this.canDisplaySidebar && !this.keyValueStore.getItem(HIDE_SIDEBAR_KEY);
!this.keyValueStore.getItem(HIDE_SIDEBAR_KEY);
}, },
@discourseComputed @discourseComputed
@ -31,6 +30,11 @@ export default Controller.extend({
); );
}, },
@discourseComputed
canDisplaySidebar() {
return this.currentUser || !this.siteSettings.login_required;
},
@discourseComputed @discourseComputed
loginRequired() { loginRequired() {
return this.siteSettings.login_required && !this.currentUser; return this.siteSettings.login_required && !this.currentUser;
@ -60,9 +64,18 @@ export default Controller.extend({
@discourseComputed( @discourseComputed(
"enable_sidebar", "enable_sidebar",
"siteSettings.enable_sidebar", "siteSettings.enable_sidebar",
"router.currentRouteName" "router.currentRouteName",
"canDisplaySidebar"
) )
sidebarEnabled(sidebarQueryParamOverride, enableSidebar, currentRouteName) { sidebarEnabled(
sidebarQueryParamOverride,
enableSidebar,
currentRouteName,
canDisplaySidebar
) {
if (!canDisplaySidebar) {
return false;
}
if (sidebarQueryParamOverride === "1") { if (sidebarQueryParamOverride === "1") {
return true; return true;
} }

View File

@ -22,6 +22,11 @@ acceptance("Sidebar - Anonymous User", function (needs) {
exists(".sidebar-container"), exists(".sidebar-container"),
"sidebar exists for anonymous user" "sidebar exists for anonymous user"
); );
assert.ok(
exists(".header-sidebar-toggle"),
"toggle button for anonymous user"
);
}); });
}); });
@ -32,12 +37,17 @@ acceptance("Sidebar - Anonymous User - Login Required", function (needs) {
login_required: true, login_required: true,
}); });
test("sidebar is hidden", async function (assert) { test("sidebar and toggle button is hidden", async function (assert) {
await visit("/"); await visit("/");
assert.ok( assert.ok(
!exists(".sidebar-container"), !exists(".sidebar-container"),
"sidebar is hidden for anonymous user" "sidebar is hidden for anonymous user"
); );
assert.ok(
!exists(".header-sidebar-toggle"),
"toggle button is hidden for anonymous user"
);
}); });
}); });