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;
}
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: