A platform for community discussion. Free, open, simple.
FIX: Update sidebar links when promoted to admin (#18928)
Blake Ericksoncb8746c7e79f
diff --git a/app/models/user.rb b/app/models/user.rbindex d92780a13b4..063ae665a88 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -138,7 +138,7 @@ class User < ActiveRecord::Baseafter_create :set_default_sidebar_section_linksafter_update :set_default_sidebar_section_links, if: Proc.new {- self.saved_change_to_staged?+ self.saved_change_to_staged? || self.saved_change_to_admin?}after_update :trigger_user_updated_event, if: Proc.new {@@ -1944,7 +1944,7 @@ class User < ActiveRecord::Baseendend- SidebarSectionLink.insert_all!(records) if records.present?+ SidebarSectionLink.insert_all(records) if records.present?enddef statdiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex b8735db48a2..b77e39ff74a 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -53,7 +53,20 @@ RSpec.describe User dotag.id)- user = Fabricate(:admin)+ admin = Fabricate(:admin)++ expect(SidebarSectionLink.where(linkable_type: 'Category', user_id: admin.id).pluck(:linkable_id)).to contain_exactly(+ category.id,+ secured_category.id+ )++ expect(SidebarSectionLink.where(linkable_type: 'Tag', user_id: admin.id).pluck(:linkable_id)).to contain_exactly(+ tag.id,+ hidden_tag.id+ )++ # A user promoted to admin should get secured sidebar records+ user.update(admin: true)expect(SidebarSectionLink.where(linkable_type: 'Category', user_id: user.id).pluck(:linkable_id)).to contain_exactly(category.id,