"Applying default user options historically" is a one way street

AI-generated summary

The discussion revolves around the issue of applying default user options historically in Discourse. RGJ explains that when a default user option is set from false to true (or vice versa), it doesn’t behave as expected. Specifically, when changing a default option from disabled to enabled, users do not receive a popup asking if they want to apply the change historically, and the setting remains disabled for existing users.

RGJ has identified the issue as related to the SiteSetting controller and provided links to the relevant code. A proposed fix for this issue has been submitted by gerhard in the form of a pull request (PR #16890).

When a default user option is set from false to true, it doesn’t behave like it should.
It does not ask if the setting should be applied to existing users and even if it did, that wouldn’t work.

Repro:

  • Have a setting like for instance “open external links in new tab” enabled
  • Set admin - settings - user preferences - default other external links in new tab to enabled
  • Set admin - settings - user preferences - default other external links in new tab to disabled
  • Get a popup Would you like to apply this change historically? This will change preferences for X existing users. and choose Yes
  • For all users the “open external links in new tab” is now disabled

So far so good, but:

  • Set admin - settings - user preferences - default other external links in new tab to enabled
  • Get no popup and it is still disabled for everyone.

Expected last step:

  • Get a popup Would you like to apply this change historically? This will change preferences for X existing users. where choosing Yes would enable it for everyone

This goes for all default_ user preferences.

This seems to be related to here and here

previous_value = SiteSetting.public_send(id) || "" if update_existing_users

which sets previous_value to "" if the setting is false, and then

UserOption.where(user_option => previous_value).update_all(attrs)

and

json[:user_count] = UserOption.where(user_option => previous_value).

doesn’t do anything.

9 Likes

Here’s a PR:

https://github.com/discourse/discourse/pull/16890

4 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.