mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
SPEC: make sure digest doesn't pick any topics in categories that are muted
This commit is contained in:
parent
a7fa1b33e5
commit
fd5677808c
4 changed files with 34 additions and 32 deletions
|
@ -250,9 +250,7 @@ class UserNotifications < ActionMailer::Base
|
|||
)
|
||||
|
||||
template = "user_notifications.user_#{notification_type}"
|
||||
if post.topic.private_message?
|
||||
template << "_pm"
|
||||
end
|
||||
template << "_pm" if post.topic.private_message?
|
||||
|
||||
email_opts = {
|
||||
topic_title: title,
|
||||
|
|
|
@ -16,16 +16,14 @@ class CategoryUser < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.auto_track_new_topic(topic)
|
||||
apply_default_to_topic(
|
||||
topic,
|
||||
apply_default_to_topic(topic,
|
||||
TopicUser.notification_levels[:tracking],
|
||||
TopicUser.notification_reasons[:auto_track_category]
|
||||
)
|
||||
end
|
||||
|
||||
def self.auto_watch_new_topic(topic)
|
||||
apply_default_to_topic(
|
||||
topic,
|
||||
apply_default_to_topic(topic,
|
||||
TopicUser.notification_levels[:watching],
|
||||
TopicUser.notification_reasons[:auto_watch_category]
|
||||
)
|
||||
|
@ -49,8 +47,6 @@ class CategoryUser < ActiveRecord::Base
|
|||
|
||||
def self.set_notification_level_for_category(user, level, category_id)
|
||||
record = CategoryUser.where(user: user, category_id: category_id).first
|
||||
# oder CategoryUser.where(user: user, category_id: category_id).destroy_all
|
||||
# und danach mir create anlegen.
|
||||
|
||||
if record.present?
|
||||
record.notification_level = level
|
||||
|
@ -62,22 +58,20 @@ class CategoryUser < ActiveRecord::Base
|
|||
|
||||
def self.apply_default_to_topic(topic, level, reason)
|
||||
# Can not afford to slow down creation of topics when a pile of users are watching new topics, reverting to SQL for max perf here
|
||||
sql = <<SQL
|
||||
sql = <<-SQL
|
||||
INSERT INTO topic_users(user_id, topic_id, notification_level, notifications_reason_id)
|
||||
SELECT user_id, :topic_id, :level, :reason
|
||||
FROM category_users
|
||||
WHERE notification_level = :level AND
|
||||
category_id = :category_id AND
|
||||
NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = :topic_id AND user_id = category_users.user_id)
|
||||
WHERE notification_level = :level
|
||||
AND category_id = :category_id
|
||||
AND NOT EXISTS(SELECT 1 FROM topic_users WHERE topic_id = :topic_id AND user_id = category_users.user_id)
|
||||
SQL
|
||||
|
||||
exec_sql(
|
||||
sql,
|
||||
exec_sql(sql,
|
||||
topic_id: topic.id,
|
||||
category_id: topic.category_id,
|
||||
level: level,
|
||||
reason: reason
|
||||
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -1181,6 +1181,16 @@ describe Topic do
|
|||
Topic.for_digest(user, 1.year.ago, top_order: true).should == [topic]
|
||||
end
|
||||
|
||||
it "doesn't return topics from muted categories" do
|
||||
user = Fabricate(:user)
|
||||
category = Fabricate(:category)
|
||||
topic = Fabricate(:topic, category: category)
|
||||
|
||||
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
|
||||
|
||||
Topic.for_digest(user, 1.year.ago, top_order: true).should be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'secured' do
|
||||
|
|
Loading…
Reference in a new issue