mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
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:
parent
eadde16232
commit
3deea94a8c
@ -23,6 +23,8 @@ class CommentsExtension extends DataExtension {
|
|||||||
* comment_permalink_prefix: ID prefix for each comment
|
* comment_permalink_prefix: ID prefix for each comment
|
||||||
* require_moderation: Require moderation for all comments
|
* require_moderation: Require moderation for all comments
|
||||||
* require_moderation_cms: Ignore other comment moderation config settings and set via CMS
|
* 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
|
* html_allowed: Allow for sanitized HTML in comments
|
||||||
* use_preview: Preview formatted comment (when allowing HTML)
|
* use_preview: Preview formatted comment (when allowing HTML)
|
||||||
*
|
*
|
||||||
@ -49,6 +51,8 @@ class CommentsExtension extends DataExtension {
|
|||||||
'require_moderation' => false,
|
'require_moderation' => false,
|
||||||
'require_moderation_nonmembers' => false,
|
'require_moderation_nonmembers' => false,
|
||||||
'require_moderation_cms' => false,
|
'require_moderation_cms' => false,
|
||||||
|
'frontend_moderation' => false,
|
||||||
|
'frontend_spam' => false,
|
||||||
'html_allowed' => false,
|
'html_allowed' => false,
|
||||||
'html_allowed_elements' => array('a', 'img', 'i', 'b'),
|
'html_allowed_elements' => array('a', 'img', 'i', 'b'),
|
||||||
'use_preview' => false,
|
'use_preview' => false,
|
||||||
@ -199,11 +203,18 @@ class CommentsExtension extends DataExtension {
|
|||||||
$order = $this->owner->getCommentsOption('order_comments_by');
|
$order = $this->owner->getCommentsOption('order_comments_by');
|
||||||
$list = $this
|
$list = $this
|
||||||
->AllComments()
|
->AllComments()
|
||||||
->sort($order)
|
->sort($order);
|
||||||
->filter('IsSpam', 0);
|
|
||||||
|
// 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
|
// 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);
|
$list = $list->filter('Moderated', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ SiteTree:
|
|||||||
extensions:
|
extensions:
|
||||||
- CommentsExtension
|
- CommentsExtension
|
||||||
comments:
|
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
|
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: 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
|
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
|
comments_holder_id: 'comments-holder' # id for the comments holder
|
||||||
comment_permalink_prefix: 'comment-' # id prefix for each comment. If needed make this different
|
comment_permalink_prefix: 'comment-' # id prefix for each comment. If needed make this different
|
||||||
require_moderation: false
|
require_moderation: false
|
||||||
require_moderation_nonmembers: false # requires moderation for comments posted by non-members. 'require_moderation' overrides this if set.
|
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_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: false # allow for sanitized HTML in comments
|
||||||
html_allowed_elements:
|
html_allowed_elements:
|
||||||
- a
|
- a
|
||||||
|
@ -57,6 +57,41 @@ class CommentsTest extends FunctionalTest {
|
|||||||
|
|
||||||
Config::inst()->update('CommentableItem', 'comments', array('require_moderation_nonmembers' => false));
|
Config::inst()->update('CommentableItem', 'comments', array('require_moderation_nonmembers' => false));
|
||||||
$this->assertEquals(2, $item->Comments()->Count());
|
$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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user