Next/prev post navigation respects safety settings

Before change this setting was either ignored or errors were shown if users was
unable to view given post.
This commit is contained in:
Marcin Kurczewski 2013-10-27 20:48:40 +01:00
parent 3f3024d6ac
commit c4d5263422

View file

@ -119,7 +119,7 @@ class PostController
return PrivilegesHelper::confirm(Privilege::ListPosts, PostSafety::toString($safety)) and return PrivilegesHelper::confirm(Privilege::ListPosts, PostSafety::toString($safety)) and
$this->context->user->hasEnabledSafety($safety); $this->context->user->hasEnabledSafety($safety);
}); });
$dbQuery->where('safety IN (' . R::genSlots($allowedSafety) . ')'); $dbQuery->where('safety')->in('(' . R::genSlots($allowedSafety) . ')');
foreach ($allowedSafety as $s) foreach ($allowedSafety as $s)
$dbQuery->put($s); $dbQuery->put($s);
@ -586,6 +586,14 @@ class PostController
->from('post') ->from('post')
->where($next ? 'id > ?' : 'id < ?') ->where($next ? 'id > ?' : 'id < ?')
->put($id); ->put($id);
$allowedSafety = array_filter(PostSafety::getAll(), function($safety)
{
return PrivilegesHelper::confirm(Privilege::ListPosts, PostSafety::toString($safety)) and
$this->context->user->hasEnabledSafety($safety);
});
$dbQuery->and('safety')->in('(' . R::genSlots($allowedSafety) . ')');
foreach ($allowedSafety as $s)
$dbQuery->put($s);
if (!PrivilegesHelper::confirm(Privilege::ListPosts, 'hidden')) if (!PrivilegesHelper::confirm(Privilege::ListPosts, 'hidden'))
$dbQuery->andNot('hidden'); $dbQuery->andNot('hidden');
$dbQuery->orderBy($next ? 'id asc' : 'id desc') $dbQuery->orderBy($next ? 'id asc' : 'id desc')
@ -611,7 +619,7 @@ class PostController
$dbQuery->from('tag'); $dbQuery->from('tag');
$dbQuery->innerJoin('post_tag'); $dbQuery->innerJoin('post_tag');
$dbQuery->on('tag.id = post_tag.tag_id'); $dbQuery->on('tag.id = post_tag.tag_id');
$dbQuery->where('tag.id IN (' . R::genSlots($post->sharedTag) . ')'); $dbQuery->where('tag.id')->in('(' . R::genSlots($post->sharedTag) . ')');
foreach ($post->sharedTag as $tag) foreach ($post->sharedTag as $tag)
$dbQuery->put($tag->id); $dbQuery->put($tag->id);
$dbQuery->groupBy('tag.id'); $dbQuery->groupBy('tag.id');