This guide explains how to edit a user preference for everyone or a subset of users in Discourse.
Required user level: System Administrator
Console access is required.
If you need to update the user preference for all of your users or a large subset of users, you can do so via the rails console.
Summary
In this guide, you’ll learn:
- How to access the Rails console for making bulk changes
- Examples of modifying user preferences
- How to identify settings names
Accessing the Rails console
To enter the Rails console in your Discourse setup, execute the following commands:
./launcher enter app
rails c
Then, run a command that selects the set of users you wish to update.
Examples of modifying user preferences
Below are command examples to update various user preferences:
Setting the last seen date for inactive users
Set the last seen date for users who have never logged in.
User.where("last_seen_at IS NULL").update_all(last_seen_at: 1.week.ago)
Disabling mailing list mode for all users
Switch users back to the default to prevent them from receiving emails for every new post.
UserOption.update_all(mailing_list_mode: false)
Suppressing emails to active users
Revert to default settings to prevent email notifications when users are actively present on the site.
UserOption.update_all(email_always: true)
Enabling chat for all beta group members
beta_group = Group.find_by_name("beta")
beta_group.users.each do |user|
UserOption.where(user_id: user.id).update_all(enable_chat: true)
end
Configuring email notifications to exclude previous replies
Set preference to exclude previous replies in email notifications.
UserOption.update_all(email_previous_replies: 0)
Where email_previous_replies
can have values:
- 0: always
- 1: unless previously sent
- 2: never
For more information, refer to controlling previous replies in emails.
Identifying the name of a setting
To determine the user setting name and available options:
- Use the data explorer plugin to inspect the
user_options
table. - Search the Discourse GitHub repository.
For example, to adjust the setting related to “When I post in a topic, set that topic to,” you need to modify the notification_level_when_replying
user option.
Check the relevant setting to watching.
You can also configure Docker to expose psql
and utilize PGadmin for easier management.
Last edited by @SaraDev 2024-11-15T00:32:38Z
Check document
Perform check on document: