Split post page view and post download privileges
This commit is contained in:
parent
3a34609fa4
commit
427f305101
5 changed files with 37 additions and 22 deletions
|
@ -99,6 +99,11 @@ viewPost.safe=anonymous
|
|||
viewPost.sketchy=registered
|
||||
viewPost.unsafe=registered
|
||||
viewPost.hidden=moderator
|
||||
downloadPost=anonymous
|
||||
downloadPost.safe=anonymous
|
||||
downloadPost.sketchy=anonymous
|
||||
downloadPost.unsafe=anonymous
|
||||
downloadPost.hidden=moderator
|
||||
retrievePost=anonymous
|
||||
favoritePost=registered
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class GetPostContentJob extends AbstractJob
|
|||
|
||||
public function getRequiredMainPrivilege()
|
||||
{
|
||||
return Privilege::ViewPost;
|
||||
return Privilege::DownloadPost;
|
||||
}
|
||||
|
||||
public function getRequiredSubPrivileges()
|
||||
|
|
|
@ -3,6 +3,7 @@ class Privilege extends AbstractEnum implements IEnum
|
|||
{
|
||||
const ListPosts = 'listPosts';
|
||||
const ViewPost = 'viewPost';
|
||||
const DownloadPost = 'downloadPost';
|
||||
const RetrievePost = 'retrievePost';
|
||||
const FavoritePost = 'favoritePost';
|
||||
const HidePost = 'hidePost';
|
||||
|
|
|
@ -92,18 +92,10 @@ class ApiPrivilegeTest extends AbstractFullApiTest
|
|||
|
||||
public function testDynamicPostRetrievalPrivileges()
|
||||
{
|
||||
$jobs =
|
||||
[
|
||||
new GetPostJob(),
|
||||
new GetPostContentJob(),
|
||||
];
|
||||
|
||||
$post = $this->postMocker->mockSingle();
|
||||
|
||||
foreach ($jobs as $job)
|
||||
{
|
||||
$job = new GetPostJob();
|
||||
$this->testedJobs []= $job;
|
||||
|
||||
$post = $this->postMocker->mockSingle();
|
||||
$post->setHidden(true);
|
||||
PostModel::save($post);
|
||||
|
||||
|
@ -115,6 +107,23 @@ class ApiPrivilegeTest extends AbstractFullApiTest
|
|||
natcasesort($sub);
|
||||
$this->assert->areEquivalent(['hidden', 'safe'], $sub);
|
||||
}
|
||||
|
||||
public function testDynamicPostContentRetrievalPrivileges()
|
||||
{
|
||||
$job = new GetPostContentJob();
|
||||
$this->testedJobs []= $job;
|
||||
|
||||
$post = $this->postMocker->mockSingle();
|
||||
$post->setHidden(true);
|
||||
PostModel::save($post);
|
||||
|
||||
$job->setArgument(JobArgs::ARG_POST_ID, $post->getId());
|
||||
$job->setArgument(JobArgs::ARG_POST_NAME, $post->getName());
|
||||
$job->prepare();
|
||||
$this->assert->areEqual(Privilege::DownloadPost, $job->getRequiredMainPrivilege());
|
||||
$sub = $job->getRequiredSubPrivileges();
|
||||
natcasesort($sub);
|
||||
$this->assert->areEquivalent(['hidden', 'safe'], $sub);
|
||||
}
|
||||
|
||||
public function testDynamicPostThumbnailPrivileges()
|
||||
|
|
|
@ -3,7 +3,7 @@ class GetPostContentJobTest extends AbstractTest
|
|||
{
|
||||
public function testPostRetrieval()
|
||||
{
|
||||
$this->grantAccess('viewPost');
|
||||
$this->grantAccess('downloadPost');
|
||||
$post = $this->postMocker->mockSingle();
|
||||
|
||||
$output = $this->assert->doesNotThrow(function() use ($post)
|
||||
|
@ -24,7 +24,7 @@ class GetPostContentJobTest extends AbstractTest
|
|||
|
||||
public function testIdFail()
|
||||
{
|
||||
$this->grantAccess('viewPost');
|
||||
$this->grantAccess('downloadPost');
|
||||
|
||||
$this->assert->throws(function()
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ class GetPostContentJobTest extends AbstractTest
|
|||
|
||||
public function testInvalidName()
|
||||
{
|
||||
$this->grantAccess('viewPost');
|
||||
$this->grantAccess('downloadPost');
|
||||
|
||||
$this->assert->throws(function()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue