FIX: Do not reset seen popups when skip_new_user_tips is false (#19345)

* FIX: Save only visible fields from the sidebar page

* FIX: Do not reset seen popups when set to false

If the option was unchecked, but it was not changed at all by the user
it was still sent to the server as a 'false' value which reset all seen
popups. This removes that behavior and resetting the list of seen popups
must be done using the "skip new user tips" button.
This commit is contained in:
Bianca Nenciu 2022-12-07 18:27:10 +02:00 committed by GitHub
parent 1db3a578e4
commit 16e3bc3ff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -13,6 +13,12 @@ export default class extends Controller {
@tracked selectedSidebarCategories = []; @tracked selectedSidebarCategories = [];
@tracked selectedSidebarTagNames = []; @tracked selectedSidebarTagNames = [];
saveAttrNames = [
"sidebar_category_ids",
"sidebar_tag_names",
"sidebar_list_destination",
];
sidebarListDestinations = [ sidebarListDestinations = [
{ {
name: I18n.t("user.experimental_sidebar.list_destination_default"), name: I18n.t("user.experimental_sidebar.list_destination_default"),
@ -42,7 +48,7 @@ export default class extends Controller {
); );
this.model this.model
.save() .save(this.saveAttrNames)
.then((result) => { .then((result) => {
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);

View File

@ -180,8 +180,8 @@ class UserUpdater
end end
end end
if attributes.key?(:skip_new_user_tips) if attributes.key?(:skip_new_user_tips) && user.user_option.skip_new_user_tips
user.user_option.seen_popups = user.user_option.skip_new_user_tips ? [-1] : nil user.user_option.seen_popups = [-1]
end end
# automatically disable digests when mailing_list_mode is enabled # automatically disable digests when mailing_list_mode is enabled

View File

@ -534,14 +534,15 @@ RSpec.describe UserUpdater do
expect(user.user_option.skip_new_user_tips).to eq(true) expect(user.user_option.skip_new_user_tips).to eq(true)
expect(user.user_option.seen_popups).to eq([-1]) expect(user.user_option.seen_popups).to eq([-1])
expect(messages.map(&:data)).to contain_exactly([-1]) expect(messages.map(&:data)).to contain_exactly([-1])
end
messages = MessageBus.track_publish('/user-tips') do it 'does not reset seen_popups' do
UserUpdater.new(Discourse.system_user, user).update(skip_new_user_tips: false) user.user_option.update!(seen_popups: [1, 2, 3])
end
UserUpdater.new(Discourse.system_user, user).update(skip_new_user_tips: false)
expect(user.user_option.skip_new_user_tips).to eq(false) expect(user.user_option.skip_new_user_tips).to eq(false)
expect(user.user_option.seen_popups).to eq(nil) expect(user.user_option.seen_popups).to eq([1, 2, 3])
expect(messages.map(&:data)).to contain_exactly(nil)
end end
end end