Skip to content

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.rb
index d92780a13b4..063ae665a88 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -138,7 +138,7 @@ class User < ActiveRecord::Base
after_create :set_default_sidebar_section_links
after_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::Base
end
end
- SidebarSectionLink.insert_all!(records) if records.present?
+ SidebarSectionLink.insert_all(records) if records.present?
end
def stat
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index b8735db48a2..b77e39ff74a 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -53,7 +53,20 @@ RSpec.describe User do
tag.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,