Split post page view and post download privileges

This commit is contained in:
Marcin Kurczewski 2014-06-10 21:12:14 +02:00
parent 3a34609fa4
commit 427f305101
5 changed files with 37 additions and 22 deletions

View file

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

View file

@ -36,7 +36,7 @@ class GetPostContentJob extends AbstractJob
public function getRequiredMainPrivilege()
{
return Privilege::ViewPost;
return Privilege::DownloadPost;
}
public function getRequiredSubPrivileges()

View file

@ -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';

View file

@ -92,29 +92,38 @@ class ApiPrivilegeTest extends AbstractFullApiTest
public function testDynamicPostRetrievalPrivileges()
{
$jobs =
[
new GetPostJob(),
new GetPostContentJob(),
];
$job = new GetPostJob();
$this->testedJobs []= $job;
$post = $this->postMocker->mockSingle();
$post->setHidden(true);
PostModel::save($post);
foreach ($jobs as $job)
{
$this->testedJobs []= $job;
$job->setArgument(JobArgs::ARG_POST_ID, $post->getId());
$job->setArgument(JobArgs::ARG_POST_NAME, $post->getName());
$job->prepare();
$this->assert->areEqual(Privilege::ViewPost, $job->getRequiredMainPrivilege());
$sub = $job->getRequiredSubPrivileges();
natcasesort($sub);
$this->assert->areEquivalent(['hidden', 'safe'], $sub);
}
$post->setHidden(true);
PostModel::save($post);
public function testDynamicPostContentRetrievalPrivileges()
{
$job = new GetPostContentJob();
$this->testedJobs []= $job;
$job->setArgument(JobArgs::ARG_POST_ID, $post->getId());
$job->setArgument(JobArgs::ARG_POST_NAME, $post->getName());
$job->prepare();
$this->assert->areEqual(Privilege::ViewPost, $job->getRequiredMainPrivilege());
$sub = $job->getRequiredSubPrivileges();
natcasesort($sub);
$this->assert->areEquivalent(['hidden', 'safe'], $sub);
}
$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()

View file

@ -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()
{