Merge pull request #352 from creative-commoners/pulls/3/stop-using-depr

API Stop using deprecated API
This commit is contained in:
Sabina Talipova 2022-12-06 09:44:15 +13:00 committed by GitHub
commit 5d044bd6eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 19 deletions

View File

@ -19,6 +19,7 @@ use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\PaginatedList;
use SilverStripe\Security\Security;
use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware;
/**
* @package comments
@ -499,7 +500,7 @@ class CommentingController extends Controller
public function redirectBack()
{
// Don't cache the redirect back ever
HTTP::set_cache_age(0);
HTTPCacheControlMiddleware::singleton()->setMaxAge(0);
$url = null;

View File

@ -77,9 +77,9 @@ class CommentForm extends Form
// limited HTML is allowed. Populated by JS/Ajax.
if ($usePreview) {
$fields->insertAfter(
'Comment',
ReadonlyField::create('PreviewComment', _t('CommentInterface.PREVIEWLABEL', 'Preview'))
->setAttribute('style', 'display: none'), // enable through JS
'Comment'
->setAttribute('style', 'display: none') // enable through JS
);
}

View File

@ -28,6 +28,7 @@ use SilverStripe\ORM\PaginatedList;
use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
/**
* Represents a single comment object.
@ -265,7 +266,12 @@ class Comment extends DataObject
*/
public function getParent()
{
Deprecation::notice('4.0.0', 'Use $this->Parent() instead');
// this is wrapped in withNoReplacement() because it's called by ViewableData::__get()
// which looks for a `"get$property"` method, which itself is called by
// AssetControllExtension::findAssets()
Deprecation::withNoReplacement(function () {
Deprecation::notice('4.0.0', 'Use $this->Parent() instead');
});
return $this->BaseClass && $this->ParentID
? DataObject::get_by_id($this->BaseClass, $this->ParentID, true)
: null;
@ -428,7 +434,7 @@ class Comment extends DataObject
protected function getMember($member = null)
{
if (!$member) {
$member = Member::currentUser();
$member = Security::getCurrentUser();
}
if (is_numeric($member)) {
@ -477,7 +483,7 @@ class Comment extends DataObject
protected function actionLink($action, $member = null)
{
if (!$member) {
$member = Member::currentUser();
$member = Security::getCurrentUser();
}
if (!$member) {
return false;
@ -650,9 +656,9 @@ class Comment extends DataObject
// Show member name if given
if (($author = $this->Author()) && $author->exists()) {
$fields->insertAfter(
'Name',
TextField::create('AuthorMember', $this->fieldLabel('Author'), $author->Title)
->performReadonlyTransformation(),
'Name'
->performReadonlyTransformation()
);
}

View File

@ -5,6 +5,7 @@ namespace SilverStripe\Comments\Model\Comment;
use SilverStripe\Control\Controller;
use SilverStripe\Security\Member;
use SilverStripe\Security\RandomGenerator;
use SilverStripe\Security\Security;
/**
* Provides the ability to generate cryptographically secure tokens for comment moderation
@ -87,7 +88,7 @@ class SecurityToken
*/
public function checkRequest($request)
{
$member = Member::currentUser();
$member = Security::getCurrentUser();
if (!$member) {
return false;
}

View File

@ -25,7 +25,7 @@
<% if $PagedComments %>
<ul class="comments-list root-level">
<% loop $PagedComments %>
<li class="comment $EvenOdd<% if FirstLast %> $FirstLast <% end_if %> $SpamClass">
<li class="comment $EvenOdd<% if $FirstLast %> $FirstLast <% end_if %> $SpamClass">
<% include CommentsInterface_singlecomment %>
</li>
<% end_loop %>

View File

@ -11,7 +11,7 @@
<% if $Replies %>
<ul class="comments-list level-{$Depth}">
<% loop $Replies %>
<li class="comment $EvenOdd<% if FirstLast %> $FirstLast <% end_if %> $SpamClass">
<li class="comment $EvenOdd<% if $FirstLast %> $FirstLast <% end_if %> $SpamClass">
<% include CommentsInterface_singlecomment %>
</li>
<% end_loop %>

View File

@ -14,6 +14,7 @@ use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
use SilverStripe\Security\SecurityToken;
use SilverStripe\Security\Security;
class CommentingControllerTest extends FunctionalTest
{
@ -98,7 +99,7 @@ class CommentingControllerTest extends FunctionalTest
$comment = $this->objFromFixture(Comment::class, 'testModeratedComment1');
$st = new CommentSecurityToken($comment);
$url = 'comments/approve/' . $comment->ID;
$url = $st->addToUrl($url, Member::currentUser());
$url = $st->addToUrl($url, Security::getCurrentUser());
$response = $this->get($url, null, ['Referer' => '/']);
$this->assertEquals(302, $response->getStatusCode());
$comment = DataObject::get_by_id(Comment::class, $comment->ID);
@ -131,7 +132,7 @@ class CommentingControllerTest extends FunctionalTest
$comment->markSpam();
$st = new CommentSecurityToken($comment);
$url = 'comments/ham/' . $comment->ID;
$url = $st->addToUrl($url, Member::currentUser());
$url = $st->addToUrl($url, Security::getCurrentUser());
$response = $this->get($url);
$this->assertEquals(302, $response->getStatusCode());
$comment = DataObject::get_by_id(Comment::class, $comment->ID);
@ -153,7 +154,7 @@ class CommentingControllerTest extends FunctionalTest
$comment->markApproved();
$st = new CommentSecurityToken($comment);
$url = 'comments/spam/' . $comment->ID;
$url = $st->addToUrl($url, Member::currentUser());
$url = $st->addToUrl($url, Security::getCurrentUser());
$response = $this->get($url);
$this->assertEquals(302, $response->getStatusCode());
$comment = DataObject::get_by_id(Comment::class, $comment->ID);
@ -274,7 +275,7 @@ class CommentingControllerTest extends FunctionalTest
);
$this->assertEquals(302, $response->getStatusCode());
// $this->assertStringStartsWith('CommentableItemController#comment-', $response->getHeader('Location'));
$this->assertDOSEquals(
$this->assertListEquals(
array(
array(
'Name' => 'Poster',
@ -305,7 +306,7 @@ class CommentingControllerTest extends FunctionalTest
);
$this->assertEquals(302, $response->getStatusCode());
// $this->assertStringStartsWith('CommentableItemController#comment-', $response->getHeader('Location'));
$this->assertDOSEquals(
$this->assertListEquals(
array(
array(
'Name' => 'Test Author',

View File

@ -13,6 +13,7 @@ use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
use SilverStripe\View\Requirements;
use SilverStripe\Security\Security;
class CommentsExtensionTest extends FunctionalTest
{
@ -218,8 +219,8 @@ class CommentsExtensionTest extends FunctionalTest
public function testCanModerateComments()
{
// ensure nobody logged in
if (Member::currentUser()) {
Member::currentUser()->logOut();
if (Security::getCurrentUser()) {
Security::getCurrentUser()->logOut();
}
$item = $this->objFromFixture(CommentableItem::class, 'first');

View File

@ -18,6 +18,7 @@ use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\Dev\Deprecation;
class CommentsGridFieldActionTest extends SapphireTest
{
@ -40,6 +41,9 @@ class CommentsGridFieldActionTest extends SapphireTest
protected function setUp(): void
{
parent::setUp();
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$this->list = new DataList(Team::class);
$config = CommentsGridFieldConfig::create()->addComponent(new GridFieldDeleteAction());
$this->gridField = new CommentsGridField('testfield', 'testfield', $this->list, $config);

View File

@ -8,6 +8,7 @@ use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
class CommentableItem extends DataObject implements TestOnly
{
@ -39,7 +40,8 @@ class CommentableItem extends DataObject implements TestOnly
} elseif (is_numeric($member)) {
$memberID = $member;
} else {
$memberID = Member::currentUserID();
$currentUser = Security::getCurrentUser();
$memberID = $currentUser ? $currentUser->ID : 0;
}
if ($memberID && Permission::checkMember($memberID, array('ADMIN', 'CMS_ACCESS_CommentAdmin'))) {