Merge pull request #373 from micmania1/296-prevent-future-post-public

FIX Prevent showing future blog posts before their publish date
This commit is contained in:
Damian Mooyman 2016-02-09 14:38:36 +13:00
commit 067f415f33
3 changed files with 23 additions and 6 deletions

View File

@ -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();
}
/**

View File

@ -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));
}
}

View File

@ -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: