API Restore ability to do frontend-moderation

This feature is disabled by default, but can be turned on either for spam, unmoderated comments, or both.
This commit is contained in:
Damian Mooyman 2015-04-14 10:31:32 +12:00
parent eadde16232
commit 3deea94a8c
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

@ -24,7 +24,7 @@ SiteTree:
extensions:
- CommentsExtension
comments:
enabled: true # Enables commenting to be disabled for a specific class (or subclass of a parent with commenting enabled)
enabled: true # Enables commenting to be disabled for a specific class (or subclass of a parent with commenting enabled)
enabled_cms: false # The 'enabled' option will be set via the CMS instead of config
require_login: false # boolean, whether a user needs to login
require_login_cms: false # The 'require_login' option will be set via the CMS instead of config
@ -40,8 +40,10 @@ SiteTree:
comments_holder_id: 'comments-holder' # id for the comments holder
comment_permalink_prefix: 'comment-' # id prefix for each comment. If needed make this different
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
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());
}
/**