FIX: skip category preference update if already set by group. (#20823)

`default_categories_*` site settings will update the category preferences on user creation. But it shouldn't update the user's category preference if a group's setting already updated it for that user.
This commit is contained in:
Vinoth Kannan 2023-03-28 19:43:01 +05:30 committed by GitHub
parent 0b05fa71ca
commit 08ff6eebad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -1968,7 +1968,7 @@ class User < ActiveRecord::Base
end
end
CategoryUser.insert_all!(values) if values.present?
CategoryUser.insert_all(values) if values.present?
end
def set_default_tags_preferences

View File

@ -2097,6 +2097,19 @@ RSpec.describe User do
expect(CategoryUser.lookup(user, :regular).pluck(:category_id)).to eq([category4.id])
end
it "does not update category preferences if already set by group" do
user_id = 123
CategoryUser.create!(
user_id: user_id,
category_id: category2.id,
notification_level: CategoryUser.notification_levels[:normal],
)
user = Fabricate(:user, id: user_id, trust_level: 1)
expect(CategoryUser.lookup(user, :normal).pluck(:category_id)).to include(category2.id)
end
it "does not set category preferences for staged users" do
user = Fabricate(:user, staged: true)
expect(CategoryUser.lookup(user, :watching).pluck(:category_id)).to eq([])