Merge pull request #108 from tractorcow/pulls/2.0/frontend-moderation

API Restore ability to do frontend-moderation
This commit is contained in:
Christopher Pitt 2015-04-14 14:09:35 +12:00
commit 7585b5d19f
3 changed files with 54 additions and 6 deletions

View File

@ -23,6 +23,8 @@ class CommentsExtension extends DataExtension {
* comment_permalink_prefix: ID prefix for each comment
* require_moderation: Require moderation for all comments
* require_moderation_cms: Ignore other comment moderation config settings and set via CMS
* frontend_moderation: Display unmoderated comments in the frontend, if the user can moderate them.
* frontend_spam: Display spam comments in the frontend, if the user can moderate them.
* html_allowed: Allow for sanitized HTML in comments
* use_preview: Preview formatted comment (when allowing HTML)
*
@ -49,6 +51,8 @@ class CommentsExtension extends DataExtension {
'require_moderation' => false,
'require_moderation_nonmembers' => false,
'require_moderation_cms' => false,
'frontend_moderation' => false,
'frontend_spam' => false,
'html_allowed' => false,
'html_allowed_elements' => array('a', 'img', 'i', 'b'),
'use_preview' => false,
@ -199,11 +203,18 @@ class CommentsExtension extends DataExtension {
$order = $this->owner->getCommentsOption('order_comments_by');
$list = $this
->AllComments()
->sort($order)
->filter('IsSpam', 0);
->sort($order);
// Filter spam comments for non-administrators if configured
$showSpam = $this->owner->getCommentsOption('frontend_spam') && $this->owner->canModerateComments();
if(!$showSpam) {
$list = $list->filter('IsSpam', 0);
}
// Filter un-moderated comments for non-administrators if moderation is enabled
if($this->owner->ModerationRequired !== 'None') {
$showUnmoderated = ($this->owner->ModerationRequired === 'None')
|| ($this->owner->getCommentsOption('frontend_moderation') && $this->owner->canModerateComments());
if(!$showUnmoderated) {
$list = $list->filter('Moderated', 1);
}

View File

@ -42,6 +42,8 @@ SiteTree:
require_moderation: false
require_moderation_nonmembers: false # requires moderation for comments posted by non-members. 'require_moderation' overrides this if set.
require_moderation_cms: false # If true, ignore above values and configure moderation requirements via the CMS only
frontend_moderation: false # Display unmoderated comments in the frontend, if the user can moderate them.
frontend_spam: false # Display spam comments in the frontend, if the user can moderate them.
html_allowed: false # allow for sanitized HTML in comments
html_allowed_elements:
- a

View File

@ -57,6 +57,41 @@ class CommentsTest extends FunctionalTest {
Config::inst()->update('CommentableItem', 'comments', array('require_moderation_nonmembers' => false));
$this->assertEquals(2, $item->Comments()->Count());
// With unmoderated comments set to display in frontend
Config::inst()->update('CommentableItem', 'comments', array(
'require_moderation' => true,
'frontend_moderation' => true
));
$this->assertEquals(1, $item->Comments()->Count());
$this->logInWithPermission('ADMIN');
$this->assertEquals(2, $item->Comments()->Count());
// With spam comments set to display in frontend
Config::inst()->update('CommentableItem', 'comments', array(
'require_moderation' => true,
'frontend_moderation' => false,
'frontend_spam' => true,
));
if($member = Member::currentUser()) $member->logOut();
$this->assertEquals(1, $item->Comments()->Count());
$this->logInWithPermission('ADMIN');
$this->assertEquals(2, $item->Comments()->Count());
// With spam and unmoderated comments set to display in frontend
Config::inst()->update('CommentableItem', 'comments', array(
'require_moderation' => true,
'frontend_moderation' => true,
'frontend_spam' => true,
));
if($member = Member::currentUser()) $member->logOut();
$this->assertEquals(1, $item->Comments()->Count());
$this->logInWithPermission('ADMIN');
$this->assertEquals(4, $item->Comments()->Count());
}
/**