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;
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user