FIX: #73 If moderation enabled, ensure spam responses aren't included.

This commit is contained in:
Will Rossiter 2013-11-28 21:29:11 +13:00
parent 877537c284
commit 5a8de05ea7
3 changed files with 63 additions and 2 deletions

View File

@ -60,9 +60,12 @@ class CommentsExtension extends DataExtension {
// Filter unmoderated comments for non-administrators if moderation is enabled
if (Commenting::get_config_value($this->ownerBaseClass, 'require_moderation') || Commenting::get_config_value($this->ownerBaseClass, 'require_moderation_nonmembers')) {
$list = $list->filter('Moderated', 1);
$list = $list->filter(array(
'Moderated' => 1,
'IsSpam' => 0
));
} else {
// Filter spam comments for non-administrators if auto-moderted
// Filter spam comments for non-administrators if auto-moderated
$list = $list->filter('IsSpam', 0);
}
}

View File

@ -18,6 +18,36 @@ class CommentsTest extends FunctionalTest {
}
public function testCommentsList() {
// comments don't require moderation so unmoderated comments can be
// shown but not spam posts
Commenting::set_config_value('CommentableItem','require_moderation', false);
$item = $this->objFromFixture('CommentableItem', 'spammed');
$this->assertDOSEquals(array(
array('Name' => 'Comment 1'),
array('Name' => 'Comment 3')
), $item->getComments(), 'Only 2 non spam posts should be shown');
// when moderated, only moderated, non spam posts should be shown.
Commenting::set_config_value('CommentableItem','require_moderation', true);
$this->assertDOSEquals(array(
array('Name' => 'Comment 3')
), $item->getComments(), 'Only 1 non spam, moderated post should be shown');
// when logged in as an user with CMS_ACCESS_CommentAdmin rights they
// should see all the comments whether we have moderation on or not
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
Commenting::set_config_value('CommentableItem','require_moderation', true);
$this->assertEquals(4, $item->getComments()->Count());
Commenting::set_config_value('CommentableItem','require_moderation', false);
$this->assertEquals(4, $item->getComments()->Count());
}
public function testCanView() {
$visitor = $this->objFromFixture('Member', 'visitor');
$admin = $this->objFromFixture('Member', 'commentadmin');
@ -222,6 +252,7 @@ class CommentsTest extends FunctionalTest {
Commenting::set_config_value('CommentableItem','html_allowed', $origAllowed);
}
}

View File

@ -27,6 +27,9 @@ CommentableItem:
nocomments:
Title: No comments
ProvideComments: 0
spammed:
ProvideComments: 1
Title: spammed
Comment:
firstComA:
@ -138,3 +141,27 @@ Comment:
Moderated: 0
IsSpam: 1
BaseClass: CommentableItem
testCommentList1:
ParentID: =>CommentableItem.spammed
Name: Comment 1
Moderated: 0
IsSpam: 0
BaseClass: CommentableItem
testCommentList2:
ParentID: =>CommentableItem.spammed
Name: Comment 2
Moderated: 1
IsSpam: 1
BaseClass: CommentableItem
testCommentList3:
ParentID: =>CommentableItem.spammed
Name: Comment 3
Moderated: 1
IsSpam: 0
BaseClass: CommentableItem
testCommentList4:
ParentID: =>CommentableItem.spammed
Name: Comment 4
Moderated: 0
IsSpam: 1
BaseClass: CommentableItem