Skip to content

A platform for community discussion. Free, open, simple.

DEV: Display Sidebar template for anonymous user (#17962)

Alan Guo Xiang Tan0f0ea75a2103
diff --git a/app/assets/javascripts/discourse/app/components/sidebar.js b/app/assets/javascripts/discourse/app/components/sidebar.js
index c9fdd81ac42..f4316c392a6 100644
--- a/app/assets/javascripts/discourse/app/components/sidebar.js
+++ b/app/assets/javascripts/discourse/app/components/sidebar.js
@@ -5,6 +5,7 @@ import { inject as service } from "@ember/service";
export default class Sidebar extends Component {
@service appEvents;
@service site;
+ @service currentUser;
constructor() {
super(...arguments);
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.hbs b/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.hbs
new file mode 100644
index 00000000000..17f3217c72e
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.hbs
@@ -0,0 +1,3 @@
+<div class="sidebar-sections sidebar-sections-anonymous">
+ {{!-- add sections for anonymous user --}}
+</div>
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.js b/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.js
new file mode 100644
index 00000000000..e7adf2382ca
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.js
@@ -0,0 +1,3 @@
+import Component from "@glimmer/component";
+
+export default class SidebarAnonymousSectuons extends Component {}
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/footer.js b/app/assets/javascripts/discourse/app/components/sidebar/footer.js
new file mode 100644
index 00000000000..68b8c7afe7e
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/sidebar/footer.js
@@ -0,0 +1,12 @@
+import Component from "@glimmer/component";
+import { getOwner } from "discourse-common/lib/get-owner";
+import { inject as service } from "@ember/service";
+
+export default class SidebarFooter extends Component {
+ @service site;
+ @service siteSettings;
+
+ get capabilities() {
+ return getOwner(this).lookup("capabilities:main");
+ }
+}
diff --git a/app/assets/javascripts/discourse/app/controllers/application.js b/app/assets/javascripts/discourse/app/controllers/application.js
index b6d0f25c8bd..80c07b17b29 100644
--- a/app/assets/javascripts/discourse/app/controllers/application.js
+++ b/app/assets/javascripts/discourse/app/controllers/application.js
@@ -17,11 +17,7 @@ export default Controller.extend({
init() {
this._super(...arguments);
-
- this.showSidebar =
- this.currentUser &&
- !this.site.mobileView &&
- !this.keyValueStore.getItem(HIDE_SIDEBAR_KEY);
+ this.showSidebar = !this.keyValueStore.getItem(HIDE_SIDEBAR_KEY);
},
@discourseComputed
diff --git a/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs b/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs
index 31cda7a3058..03f183e0b54 100644
--- a/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs
@@ -1,6 +1,11 @@
<DSection @pageClass="has-sidebar" @class="sidebar-container" @scrollTop={{false}}>
<div class="sidebar-scroll-wrap">
- <Sidebar::Sections @collapsableSections={{true}}/>
- <Sidebar::Footer @tagName=""/>
+ {{#if this.currentUser}}
+ <Sidebar::Sections @collapsableSections={{true}}/>
+ <Sidebar::Footer />
+ {{else}}
+ <Sidebar::AnonymousSections />
+ <Sidebar::Footer />
+ {{/if}}
</div>
</DSection>
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-user-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-user-test.js
new file mode 100644
index 00000000000..0bdab3fc292
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-user-test.js
@@ -0,0 +1,26 @@
+import { test } from "qunit";
+
+import { visit } from "@ember/test-helpers";
+
+import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
+
+acceptance("Sidebar - Anonymous User", function (needs) {
+ needs.settings({
+ enable_experimental_sidebar_hamburger: true,
+ enable_sidebar: true,
+ });
+
+ test("sidebar is displayed", async function (assert) {
+ await visit("/");
+
+ assert.ok(
+ document.body.classList.contains("has-sidebar-page"),
+ "adds sidebar utility class to body"
+ );
+
+ assert.ok(
+ exists(".sidebar-container"),
+ "sidebar exists for anonymouse user"
+ );
+ });
+});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js
index f75d4b22486..38edead380c 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js
@@ -4,20 +4,6 @@ import { test } from "qunit";
import { click, visit } from "@ember/test-helpers";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
-acceptance("Sidebar - Anon User", function () {
- // Don't show sidebar for anon user until we know what we want to display
- test("sidebar is not displayed", async function (assert) {
- await visit("/");
-
- assert.ok(
- !document.body.classList.contains("has-sidebar-page"),
- "does not add sidebar utility class to body"
- );
-
- assert.ok(!exists(".sidebar-container"));
- });
-});
-
acceptance(
"Sidebar - Experimental sidebar and hamburger setting disabled",
function (needs) {