DEV: move sidebar community section to database (#21166)

* DEV: move sidebar community section to database

Before, community section was hard-coded. In the future, we are planning to allow admins to edit it. Therefore, it has to be moved to database to `custom_sections` table.

Few steps and simplifications has to be made:
- custom section was hidden behind `enable_custom_sidebar_sections` feature flag. It has to be deleted so all forums, see community section;
- migration to add `section_type` column to sidebar section to show it is a special type;
- migration to add `segment` column to sidebar links to determine if link should be displayed in primary section or in more section;
- simplify more section to have one level only (secondary section links are merged);
- ensure that links like `everything` are correctly tracking state;
- make user an anonymous links position consistence. For example, from now on `faq` link for user and anonymous is visible in more tab;
- delete old community-section template.
This commit is contained in:
Krzysztof Kotlarek
2023-05-04 12:14:09 +10:00
committed by GitHub
parent afc1611be7
commit 709fa24558
51 changed files with 705 additions and 502 deletions

View File

@@ -2,7 +2,6 @@
class SidebarSectionsController < ApplicationController
requires_login
before_action :check_if_member_of_group
before_action :check_access_if_public
def index
@@ -20,11 +19,7 @@ class SidebarSectionsController < ApplicationController
if sidebar_section.public?
StaffActionLogger.new(current_user).log_create_public_sidebar_section(sidebar_section)
MessageBus.publish(
"/refresh-sidebar-sections",
nil,
group_ids: SiteSetting.enable_custom_sidebar_sections_map,
)
MessageBus.publish("/refresh-sidebar-sections", nil)
Site.clear_anon_cache!
end
@@ -44,11 +39,7 @@ class SidebarSectionsController < ApplicationController
if sidebar_section.public?
StaffActionLogger.new(current_user).log_update_public_sidebar_section(sidebar_section)
MessageBus.publish(
"/refresh-sidebar-sections",
nil,
group_ids: SiteSetting.enable_custom_sidebar_sections_map,
)
MessageBus.publish("/refresh-sidebar-sections", nil)
Site.clear_anon_cache!
end
@@ -86,11 +77,7 @@ class SidebarSectionsController < ApplicationController
if sidebar_section.public?
StaffActionLogger.new(current_user).log_destroy_public_sidebar_section(sidebar_section)
MessageBus.publish(
"/refresh-sidebar-sections",
nil,
group_ids: SiteSetting.enable_custom_sidebar_sections_map,
)
MessageBus.publish("/refresh-sidebar-sections", nil)
end
render json: SidebarSectionSerializer.new(sidebar_section)
rescue Discourse::InvalidAccess
@@ -111,14 +98,6 @@ class SidebarSectionsController < ApplicationController
params.permit(:sidebar_section_id, links_order: [])
end
def check_if_member_of_group
### TODO remove when enable_custom_sidebar_sections SiteSetting is removed
if !SiteSetting.enable_custom_sidebar_sections.present? ||
!current_user.in_any_groups?(SiteSetting.enable_custom_sidebar_sections_map)
raise Discourse::InvalidAccess
end
end
private
def check_access_if_public