FIX: 'disable_edit_notifications' will only disable revisions made by the system user

This commit is contained in:
Régis Hanol 2014-09-09 18:56:04 +02:00
parent eb34ecfc0c
commit 598a3f3e10
2 changed files with 18 additions and 6 deletions

View File

@ -41,10 +41,10 @@ class PostAlertObserver < ActiveRecord::Observer
post = post_revision.post post = post_revision.post
return unless post return unless post
return if SiteSetting.disable_edit_notifications
return if post_revision.user.blank? return if post_revision.user.blank?
return if post_revision.user_id == post.user_id return if post_revision.user_id == post.user_id
return if post.topic.private_message? return if post.topic.private_message?
return if SiteSetting.disable_edit_notifications && post_revision.user_id == Discourse::SYSTEM_USER_ID
alerter.create_notification(post.user, Notification.types[:edited], post, display_username: post_revision.user.username) alerter.create_notification(post.user, Notification.types[:edited], post, display_username: post_revision.user.username)
end end

View File

@ -40,11 +40,23 @@ describe PostAlertObserver do
}.should change(post.user.notifications, :count).by(1) }.should change(post.user.notifications, :count).by(1)
end end
it 'does not notifiy a user of the revision when edit notifications are disabled' do context "edit notifications are disabled" do
SiteSetting.stubs(:disable_edit_notifications).returns(true)
lambda { before { SiteSetting.stubs(:disable_edit_notifications).returns(true) }
post.revise(evil_trout, "world is the new body of the message")
}.should_not change(post.user.notifications, :count).by(1)
it 'notifies a user of the revision made by another user' do
lambda {
post.revise(evil_trout, "world is the new body of the message")
}.should change(post.user.notifications, :count).by(1)
end
it 'does not notifiy a user of the revision made by the system user' do
lambda {
post.revise(Discourse.system_user, "world is the new body of the message")
}.should_not change(post.user.notifications, :count)
end
end end
end end