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.sketchy=registered
viewPost.unsafe=registered viewPost.unsafe=registered
viewPost.hidden=moderator viewPost.hidden=moderator
downloadPost=anonymous
downloadPost.safe=anonymous
downloadPost.sketchy=anonymous
downloadPost.unsafe=anonymous
downloadPost.hidden=moderator
retrievePost=anonymous retrievePost=anonymous
favoritePost=registered favoritePost=registered

View file

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

View file

@ -3,6 +3,7 @@ class Privilege extends AbstractEnum implements IEnum
{ {
const ListPosts = 'listPosts'; const ListPosts = 'listPosts';
const ViewPost = 'viewPost'; const ViewPost = 'viewPost';
const DownloadPost = 'downloadPost';
const RetrievePost = 'retrievePost'; const RetrievePost = 'retrievePost';
const FavoritePost = 'favoritePost'; const FavoritePost = 'favoritePost';
const HidePost = 'hidePost'; const HidePost = 'hidePost';

View file

@ -92,18 +92,10 @@ class ApiPrivilegeTest extends AbstractFullApiTest
public function testDynamicPostRetrievalPrivileges() public function testDynamicPostRetrievalPrivileges()
{ {
$jobs = $job = new GetPostJob();
[
new GetPostJob(),
new GetPostContentJob(),
];
$post = $this->postMocker->mockSingle();
foreach ($jobs as $job)
{
$this->testedJobs []= $job; $this->testedJobs []= $job;
$post = $this->postMocker->mockSingle();
$post->setHidden(true); $post->setHidden(true);
PostModel::save($post); PostModel::save($post);
@ -115,6 +107,23 @@ class ApiPrivilegeTest extends AbstractFullApiTest
natcasesort($sub); natcasesort($sub);
$this->assert->areEquivalent(['hidden', 'safe'], $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() public function testDynamicPostThumbnailPrivileges()

View file

@ -3,7 +3,7 @@ class GetPostContentJobTest extends AbstractTest
{ {
public function testPostRetrieval() public function testPostRetrieval()
{ {
$this->grantAccess('viewPost'); $this->grantAccess('downloadPost');
$post = $this->postMocker->mockSingle(); $post = $this->postMocker->mockSingle();
$output = $this->assert->doesNotThrow(function() use ($post) $output = $this->assert->doesNotThrow(function() use ($post)
@ -24,7 +24,7 @@ class GetPostContentJobTest extends AbstractTest
public function testIdFail() public function testIdFail()
{ {
$this->grantAccess('viewPost'); $this->grantAccess('downloadPost');
$this->assert->throws(function() $this->assert->throws(function()
{ {
@ -38,7 +38,7 @@ class GetPostContentJobTest extends AbstractTest
public function testInvalidName() public function testInvalidName()
{ {
$this->grantAccess('viewPost'); $this->grantAccess('downloadPost');
$this->assert->throws(function() $this->assert->throws(function()
{ {