重置默认类别观看设置

我认为以下步骤解决了该问题!

在站点设置中,我将类别(31)设置为默认监视,追溯性地设置。
检查:

CategoryUser.where(category_id: 31).pluck(:user_id, :notification_level)

我的类别 31 的大多数用户的 notification_level3:+1:

现在,此更改要产生 100% 的效果还有两件事:

  1. 用户的全局电子邮件偏好设置。
  2. 用户在类别(31)中每个主题的通知偏好设置。

:warning: 以下行将修改您用户的个人设置。不要发生争执。

首先,为了“重新激活”用户的电子邮件,必须将用户的 email_level 设置为 1(即“离开时”)或 2(“始终”):

UserOption.update_all(email_level: 1)

检查:

UserOption.group(:email_level).count

我得到类似 => {1=>X} 的结果,其中 X 是用户数。

其次,主题 notification_level 优先于类别 notification_level(已在站点设置中修改)。最简单的方法是移除主题首选项。为此,只需逐个删除条目:

TopicUser.where(topic_id: <topic_id_nr>).destroy_all

检查:

TopicUser.where(topic_id: <topic_id_nr>).exists?

得到类似 => [ ] 的结果,这意味着没有用户具有主题偏好设置,类别 notification_level 将是所有用户的默认设置。


附注:不知何故,一些用户仍然没有设置类别的通知偏好设置(31)(即 category_user 表中没有条目)。为了确保设置了他们的 notification_level,必须创建一个带有 notification_level 值的条目:

User.find_each do |user|
  unless CategoryUser.exists?(user_id: user.id, category_id: 31)
    CategoryUser.create!(user_id: user.id, category_id: 31, notification_level: 3)
  end
end

检查:

CategoryUser.where(category_id: 31).pluck(:id, :notification_level)