mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
FIX Prevent showing future blog posts before their publish date
This commit is contained in:
parent
9526e13e5c
commit
f32adf1dd3
@ -460,18 +460,19 @@ class BlogPost extends Page
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->canEdit($member)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var SS_Datetime $publishDate
|
||||
*/
|
||||
$publishDate = $this->dbObject('PublishDate');
|
||||
|
||||
// Show past posts
|
||||
if (!$publishDate->exists() || !$publishDate->InFuture()) {
|
||||
return true;
|
||||
if(!$publishDate->exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Anyone that can edit this page can view it
|
||||
return $this->canEdit($member);
|
||||
return !$publishDate->InFuture();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,4 +83,15 @@ class BlogPostTest extends SapphireTest
|
||||
$fields = $blogpost->getCMSFields();
|
||||
$this->assertNotEmpty($fields->dataFieldByName('Authors'));
|
||||
}
|
||||
|
||||
public function testCanViewFuturePost()
|
||||
{
|
||||
$blogPost = $this->objFromFixture('BlogPost', 'NullPublishDate');
|
||||
|
||||
$editor = $this->objFromFixture('Member', 'BlogEditor');
|
||||
$this->assertTrue($blogPost->canView($editor));
|
||||
|
||||
$visitor = $this->objFromFixture('Member', 'Visitor');
|
||||
$this->assertFalse($blogPost->canView($visitor));
|
||||
}
|
||||
}
|
||||
|
@ -164,6 +164,11 @@ BlogPost:
|
||||
PublishDate: '2012-01-09 15:00:00'
|
||||
Parent: =>Blog.FourthBlog
|
||||
Authors: =>Member.BlogEditor,=>Member.Writer,=>Member.Contributor
|
||||
NullPublishDate:
|
||||
Title: 'No publish date'
|
||||
PublishDate: 'NULL'
|
||||
Parent: =>Blog.FourthBlog
|
||||
Authors: =>Member.BlogEditor,=>Member.Writer,=>Member.Contributor
|
||||
|
||||
#Posts for the tag cloud widget test
|
||||
TaggedPost1:
|
||||
|
Loading…
Reference in New Issue
Block a user