FIX: public sidebar sections belong to system user (#20972)

Before, public sidebar sections were belonging to admin. However, a better choice is system user.
This commit is contained in:
Krzysztof Kotlarek
2023-04-05 10:52:18 +10:00
committed by GitHub
parent 6b9dd22ba7
commit b72282123b
7 changed files with 88 additions and 13 deletions

View File

@ -16,9 +16,7 @@ class SidebarSectionsController < ApplicationController
def create
sidebar_section =
SidebarSection.create!(
section_params.merge(user: current_user, sidebar_urls_attributes: links_params),
)
SidebarSection.create!(section_params.merge(sidebar_urls_attributes: links_params))
if sidebar_section.public?
StaffActionLogger.new(current_user).log_create_public_sidebar_section(sidebar_section)
@ -38,7 +36,10 @@ class SidebarSectionsController < ApplicationController
sidebar_section = SidebarSection.find_by(id: section_params["id"])
@guardian.ensure_can_edit!(sidebar_section)
sidebar_section.update!(section_params.merge(sidebar_urls_attributes: links_params))
ActiveRecord::Base.transaction do
sidebar_section.update!(section_params.merge(sidebar_urls_attributes: links_params))
sidebar_section.sidebar_section_links.update_all(user_id: sidebar_section.user_id)
end
if sidebar_section.public?
StaffActionLogger.new(current_user).log_update_public_sidebar_section(sidebar_section)
@ -95,7 +96,9 @@ class SidebarSectionsController < ApplicationController
end
def section_params
params.permit(:id, :title, :public)
section_params = params.permit(:id, :title, :public)
section_params.merge!(user: current_user) if !params[:public]
section_params
end
def links_params