FIX: modify notification after remove auto_watch_category (#10568)

When a category is removed from `auto_watch_category` we are removing
CategoryUser. However, there are still TopicUser with notification level
set to `watching` which was inherited from Category.

We should move them back to `regular` unless they were modified by a user.
This commit is contained in:
Krzysztof Kotlarek
2020-09-01 13:07:41 +10:00
committed by GitHub
parent e824385e64
commit 084e15b447
3 changed files with 41 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ class Admin::SiteSettingsController < Admin::AdminController
value = Upload.get_from_url(value) || ""
end
update_existing_users = params[:updateExistingUsers].present?
update_existing_users = params[:update_existing_user].present?
previous_value = SiteSetting.send(id) || "" if update_existing_users
SiteSetting.set_and_log(id, value, current_user)
@@ -58,7 +58,14 @@ class Admin::SiteSettingsController < Admin::AdminController
notification_level = NotificationLevels.all[:regular]
end
CategoryUser.where(category_id: (previous_category_ids - new_category_ids), notification_level: notification_level).delete_all
categories_to_unwatch = previous_category_ids - new_category_ids
CategoryUser.where(category_id: categories_to_unwatch, notification_level: notification_level).delete_all
TopicUser
.joins(:topic)
.where(notification_level: TopicUser.notification_levels[:watching],
notifications_reason_id: TopicUser.notification_reasons[:auto_watch_category],
topics: { category_id: categories_to_unwatch })
.update_all(notification_level: TopicUser.notification_levels[:regular])
(new_category_ids - previous_category_ids).each do |category_id|
skip_user_ids = CategoryUser.where(category_id: category_id).pluck(:user_id)