From e586f6052fc75fa7e65b93a1304316ae4aff4851 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Thu, 6 Apr 2023 08:55:47 +1000 Subject: [PATCH] FEATURE: public custom sidebar sections visible to anonymous (#20931) Previously, public custom sections were only visible to logged-in users. In this PR, we are making them visible to anonymous as well. The reason is that Community Section will be moved into custom section model to be easily editable by admins. --- .../sidebar/anonymous/custom-sections.hbs | 31 +++++++++ .../sidebar/anonymous/custom-sections.js | 17 +++++ .../components/sidebar/anonymous/sections.hbs | 1 + .../app/components/sidebar/user/section.js | 4 +- .../sidebar_sections_controller.rb | 2 + app/models/sidebar_section.rb | 2 + app/serializers/current_user_serializer.rb | 3 +- app/serializers/site_serializer.rb | 12 ++++ spec/serializers/site_serializer_spec.rb | 64 +++++++++++++++++++ spec/system/custom_sidebar_sections_spec.rb | 42 ++++++++---- .../system/page_objects/components/sidebar.rb | 4 ++ 11 files changed, 168 insertions(+), 14 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/sidebar/anonymous/custom-sections.hbs create mode 100644 app/assets/javascripts/discourse/app/components/sidebar/anonymous/custom-sections.js diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/custom-sections.hbs b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/custom-sections.hbs new file mode 100644 index 00000000000..80da8163d41 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/custom-sections.hbs @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/custom-sections.js b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/custom-sections.js new file mode 100644 index 00000000000..6d7fa593dd1 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/custom-sections.js @@ -0,0 +1,17 @@ +import Component from "@glimmer/component"; +import { inject as service } from "@ember/service"; +import Section from "discourse/components/sidebar/user/section"; + +export default class SidebarAnonymousCustomSections extends Component { + @service router; + @service site; + + get sections() { + return this.site.anonymous_sidebar_sections?.map((section) => { + return new Section({ + section, + router: this.router, + }); + }); + } +} diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/sections.hbs b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/sections.hbs index aee22d9ebbf..ced0920e93c 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/anonymous/sections.hbs +++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous/sections.hbs @@ -1,5 +1,6 @@