FIX: sidebar_list_destination on CurrentUserSerializer (#18660)

Before, `sidebar_list_destination` was an attribute on UserOptionSerializer. The problem was that this attribute was added to user model only when the user entered the preferences panel. We want that attribute to be available all the time, therefore it was moved to CurrentUserSerializer.
This commit is contained in:
Krzysztof Kotlarek 2022-10-19 11:48:36 +11:00 committed by GitHub
parent 99d9c933c6
commit 45bdfa1c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 34 additions and 56 deletions

View File

@ -46,6 +46,10 @@ export default class extends Controller {
if (result.user.sidebar_tags) { if (result.user.sidebar_tags) {
this.model.set("sidebar_tags", result.user.sidebar_tags); this.model.set("sidebar_tags", result.user.sidebar_tags);
} }
this.model.set(
"sidebar_list_destination",
this.newSidebarListDestination
);
this.saved = true; this.saved = true;
}) })

View File

@ -350,7 +350,7 @@ const User = RestModel.extend({
); );
}, },
sidebarListDestination: readOnly("user_option.sidebar_list_destination"), sidebarListDestination: readOnly("sidebar_list_destination"),
changeUsername(new_username) { changeUsername(new_username) {
return ajax(userPath(`${this.username_lower}/preferences/username`), { return ajax(userPath(`${this.username_lower}/preferences/username`), {

View File

@ -295,9 +295,7 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
test("clicking section links - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) { test("clicking section links - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) {
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
const { category1 } = setupUserSidebarCategories(); const { category1 } = setupUserSidebarCategories();
@ -336,9 +334,7 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
created_in_new_period: true, created_in_new_period: true,
}); });
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
await visit("/"); await visit("/");
@ -384,9 +380,7 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) {
created_in_new_period: true, created_in_new_period: true,
}); });
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
await visit("/"); await visit("/");

View File

@ -162,9 +162,7 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
test("clicking on everything link - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) { test("clicking on everything link - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) {
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
await visit("/t/280"); await visit("/t/280");
@ -201,9 +199,7 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
created_in_new_period: true, created_in_new_period: true,
}); });
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
await visit("/t/280"); await visit("/t/280");
await click(".sidebar-section-community .sidebar-section-link-everything"); await click(".sidebar-section-community .sidebar-section-link-everything");
@ -248,9 +244,7 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
created_in_new_period: true, created_in_new_period: true,
}); });
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
await visit("/t/280"); await visit("/t/280");
await click(".sidebar-section-community .sidebar-section-link-everything"); await click(".sidebar-section-community .sidebar-section-link-everything");
@ -299,9 +293,7 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
test("clicking on tracked link - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) { test("clicking on tracked link - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) {
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
await visit("/t/280"); await visit("/t/280");
@ -340,9 +332,7 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
created_in_new_period: true, created_in_new_period: true,
}); });
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
await visit("/t/280"); await visit("/t/280");
await click(".sidebar-section-community .sidebar-section-link-tracked"); await click(".sidebar-section-community .sidebar-section-link-tracked");
@ -389,9 +379,7 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
created_in_new_period: true, created_in_new_period: true,
}); });
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
await visit("/t/280"); await visit("/t/280");
await click(".sidebar-section-community .sidebar-section-link-tracked"); await click(".sidebar-section-community .sidebar-section-link-tracked");

View File

@ -238,9 +238,7 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
test("clicking tag section links - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) { test("clicking tag section links - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) {
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
await visit("/"); await visit("/");
@ -266,9 +264,7 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
test("clicking tag section links - sidebar_list_destination set to unread/new with new topics", async function (assert) { test("clicking tag section links - sidebar_list_destination set to unread/new with new topics", async function (assert) {
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
this.container.lookup("service:topic-tracking-state").loadStates([ this.container.lookup("service:topic-tracking-state").loadStates([
@ -308,9 +304,7 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
test("clicking tag section links - sidebar_list_destination set to unread/new with unread topics", async function (assert) { test("clicking tag section links - sidebar_list_destination set to unread/new with unread topics", async function (assert) {
updateCurrentUser({ updateCurrentUser({
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
},
}); });
this.container.lookup("service:topic-tracking-state").loadStates([ this.container.lookup("service:topic-tracking-state").loadStates([

View File

@ -46,10 +46,8 @@ acceptance("User Preferences - Sidebar", function (needs) {
{ name: "monkey", pm_only: false }, { name: "monkey", pm_only: false },
{ name: "gazelle", pm_only: false }, { name: "gazelle", pm_only: false },
], ],
user_option: {
sidebar_list_destination: "unread_new", sidebar_list_destination: "unread_new",
}, },
},
}); });
} }
}); });

View File

@ -81,7 +81,8 @@ class CurrentUserSerializer < BasicUserSerializer
:likes_notifications_disabled, :likes_notifications_disabled,
:grouped_unread_notifications, :grouped_unread_notifications,
:redesigned_user_menu_enabled, :redesigned_user_menu_enabled,
:redesigned_user_page_nav_enabled :redesigned_user_page_nav_enabled,
:sidebar_list_destination
delegate :user_stat, to: :object, private: true delegate :user_stat, to: :object, private: true
delegate :any_posts, :draft_count, :pending_posts_count, :read_faq?, to: :user_stat delegate :any_posts, :draft_count, :pending_posts_count, :read_faq?, to: :user_stat
@ -160,6 +161,10 @@ class CurrentUserSerializer < BasicUserSerializer
object.user_option.bookmark_auto_delete_preference object.user_option.bookmark_auto_delete_preference
end end
def sidebar_list_destination
object.user_option.sidebar_list_none_selected? ? SiteSetting.default_sidebar_list_destination : object.user_option.sidebar_list_destination
end
def can_send_private_email_messages def can_send_private_email_messages
scope.can_send_private_messages_to_email? scope.can_send_private_messages_to_email?
end end

View File

@ -34,8 +34,7 @@ class UserOptionSerializer < ApplicationSerializer
:timezone, :timezone,
:skip_new_user_tips, :skip_new_user_tips,
:default_calendar, :default_calendar,
:oldest_search_log_date, :oldest_search_log_date
:sidebar_list_destination
def auto_track_topics_after_msecs def auto_track_topics_after_msecs
object.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecs object.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecs
@ -52,8 +51,4 @@ class UserOptionSerializer < ApplicationSerializer
def theme_ids def theme_ids
object.theme_ids.presence || [SiteSetting.default_theme_id] object.theme_ids.presence || [SiteSetting.default_theme_id]
end end
def sidebar_list_destination
object.sidebar_list_none_selected? ? SiteSetting.default_sidebar_list_destination : object.sidebar_list_destination
end
end end

View File

@ -388,5 +388,14 @@ RSpec.describe CurrentUserSerializer do
end end
end end
describe "#sidebar_list_destination" do
it "returns choosen value or default" do
expect(serializer.as_json[:sidebar_list_destination]).to eq(SiteSetting.default_sidebar_list_destination)
user.user_option.update!(sidebar_list_destination: "unread_new")
expect(serializer.as_json[:sidebar_list_destination]).to eq("unread_new")
end
end
include_examples "#display_sidebar_tags", described_class include_examples "#display_sidebar_tags", described_class
end end

View File

@ -426,13 +426,4 @@ RSpec.describe UserSerializer do
end end
include_examples "#display_sidebar_tags", UserSerializer include_examples "#display_sidebar_tags", UserSerializer
describe "#sidebar_list_destination" do
it "returns choosen value or default" do
expect(serializer.as_json[:user_option][:sidebar_list_destination]).to eq(SiteSetting.default_sidebar_list_destination)
user.user_option.update!(sidebar_list_destination: "unread_new")
expect(serializer.as_json[:user_option][:sidebar_list_destination]).to eq("unread_new")
end
end
end end