mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 11:19:51 +00:00
FIX: skip category notification_level unless scoped
#b19dcac2 improved the serializer so it sends default notification
levels to users to work around cases where a category edit would
would result in clients being left with invalid notification state
Unfortunately this did not address the root issue.
When we edit categories we publish state to multiple users this
means that the serializer is executed unscoped with no user.
The client already handles this case per:
dcad720a4c/app/assets/javascripts/discourse/app/models/site.js (L119-L119)
If a property is not shipped to it, it will leave it alone on the
existing category.
This fix ensures that these wide category info updates do not
include notification state to avoid corruption of local state.
This commit is contained in:
parent
0e2f7ecfd0
commit
2987901043
@ -81,6 +81,10 @@ class CategorySerializer < SiteCategorySerializer
|
||||
scope && scope.can_edit?(object)
|
||||
end
|
||||
|
||||
def include_notification_level?
|
||||
scope && scope.user
|
||||
end
|
||||
|
||||
def notification_level
|
||||
user = scope && scope.user
|
||||
object.notification_level ||
|
||||
|
@ -1134,6 +1134,24 @@ describe Category do
|
||||
end
|
||||
end
|
||||
|
||||
describe "messageBus" do
|
||||
it "does not publish notification level when publishing to /categories" do
|
||||
category = Fabricate(:category)
|
||||
category.name = "Amazing category"
|
||||
messages = MessageBus.track_publish("/categories") do
|
||||
category.save!
|
||||
end
|
||||
|
||||
expect(messages.length).to eq(1)
|
||||
message = messages.first
|
||||
|
||||
category_hash = message.data[:categories].first
|
||||
|
||||
expect(category_hash[:name]).to eq(category.name)
|
||||
expect(category_hash.key?(:notification_level)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ensure_consistency!" do
|
||||
it "creates category topic" do
|
||||
|
||||
|
@ -29,9 +29,9 @@ describe CategorySerializer do
|
||||
expect(json[:custom_fields]).to be_present
|
||||
end
|
||||
|
||||
it "includes the default notification level" do
|
||||
it "does not include the default notification level when there is no user" do
|
||||
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
||||
expect(json[:notification_level]).to eq(CategoryUser.default_notification_level)
|
||||
expect(json.key?(:notification_level)).to eq(false)
|
||||
end
|
||||
|
||||
describe "user notification level" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user