FIX Prevent showing future blog posts before their publish date

This commit is contained in:
micmania1 2016-02-05 02:28:09 +00:00
parent 9526e13e5c
commit f32adf1dd3
3 changed files with 23 additions and 6 deletions

View File

@ -460,18 +460,19 @@ class BlogPost extends Page
return false; return false;
} }
if($this->canEdit($member)) {
return true;
}
/** /**
* @var SS_Datetime $publishDate * @var SS_Datetime $publishDate
*/ */
$publishDate = $this->dbObject('PublishDate'); $publishDate = $this->dbObject('PublishDate');
if(!$publishDate->exists()) {
// Show past posts return false;
if (!$publishDate->exists() || !$publishDate->InFuture()) {
return true;
} }
// Anyone that can edit this page can view it return !$publishDate->InFuture();
return $this->canEdit($member);
} }
/** /**

View File

@ -83,4 +83,15 @@ class BlogPostTest extends SapphireTest
$fields = $blogpost->getCMSFields(); $fields = $blogpost->getCMSFields();
$this->assertNotEmpty($fields->dataFieldByName('Authors')); $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));
}
} }

View File

@ -164,6 +164,11 @@ BlogPost:
PublishDate: '2012-01-09 15:00:00' PublishDate: '2012-01-09 15:00:00'
Parent: =>Blog.FourthBlog Parent: =>Blog.FourthBlog
Authors: =>Member.BlogEditor,=>Member.Writer,=>Member.Contributor 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 #Posts for the tag cloud widget test
TaggedPost1: TaggedPost1: