mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 12:13:43 +08:00
FIX: Include default notification level in category serializer (#9572)
Fixes an issue where the notification level state goes missing when user edits a category in the UI.
This commit is contained in:
parent
c1c211365a
commit
b19dcac272
|
@ -83,8 +83,9 @@ class CategorySerializer < SiteCategorySerializer
|
||||||
|
|
||||||
def notification_level
|
def notification_level
|
||||||
user = scope && scope.user
|
user = scope && scope.user
|
||||||
object.notification_level ||
|
object.notification_level ||
|
||||||
(user && CategoryUser.where(user: user, category: object).first.try(:notification_level))
|
(user && CategoryUser.where(user: user, category: object).first.try(:notification_level)) ||
|
||||||
|
CategoryUser.default_notification_level
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_fields
|
def custom_fields
|
||||||
|
|
|
@ -28,4 +28,19 @@ describe CategorySerializer do
|
||||||
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
||||||
expect(json[:custom_fields]).to be_present
|
expect(json[:custom_fields]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "includes the default notification level" do
|
||||||
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
||||||
|
expect(json[:notification_level]).to eq(CategoryUser.default_notification_level)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "user notification level" do
|
||||||
|
fab!(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
it "includes the user's notification level" do
|
||||||
|
CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:watching], category.id)
|
||||||
|
json = described_class.new(category, scope: Guardian.new(user), root: false).as_json
|
||||||
|
expect(json[:notification_level]).to eq(NotificationLevels.all[:watching])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user