PrivilegesHelper shortened to Access

Methods are shorter, too
This commit is contained in:
Marcin Kurczewski 2014-04-29 23:52:17 +02:00
parent 81e43286b5
commit 396ea97cad
22 changed files with 157 additions and 173 deletions

View file

@ -1,5 +1,5 @@
<?php
class PrivilegesHelper
class Access
{
private static $privileges = [];
@ -32,7 +32,7 @@ class PrivilegesHelper
}
}
public static function confirm($privilege, $subPrivilege = null)
public static function check($privilege, $subPrivilege = null)
{
if (php_sapi_name() == 'cli')
return true;
@ -60,13 +60,13 @@ class PrivilegesHelper
return intval($user->accessRank) >= $minAccessRank;
}
public static function confirmWithException($privilege, $subPrivilege = null)
public static function assert($privilege, $subPrivilege = null)
{
if (!self::confirm($privilege, $subPrivilege))
if (!self::check($privilege, $subPrivilege))
throw new SimpleException('Insufficient privileges');
}
public static function getIdentitySubPrivilege($user)
public static function getIdentity($user)
{
if (!$user)
return 'all';
@ -74,8 +74,9 @@ class PrivilegesHelper
return $user->id == $userFromContext->id ? 'own' : 'all';
}
public static function confirmEmail($user)
public static function assertEmailConfirmation()
{
$user = getContext()->user;
if (!$user->emailConfirmed)
throw new SimpleException('Need e-mail address confirmation to continue');
}
@ -88,10 +89,10 @@ class PrivilegesHelper
$context = getContext();
return array_filter(PostSafety::getAll(), function($safety) use ($context)
{
return PrivilegesHelper::confirm(Privilege::ListPosts, PostSafety::toString($safety)) and
$context->user->hasEnabledSafety($safety);
return Access::check(Privilege::ListPosts, PostSafety::toString($safety))
and $context->user->hasEnabledSafety($safety);
});
}
}
PrivilegesHelper::init();
Access::init();

View file

@ -32,7 +32,7 @@ class AuthController
throw new SimpleException('You are banned');
if ($config->registration->needEmailForRegistering)
PrivilegesHelper::confirmEmail($dbUser);
Access::requireEmail($dbUser);
$context->user = $dbUser;
self::doReLog();

View file

@ -3,7 +3,7 @@ class CommentController
{
public function listAction($page)
{
PrivilegesHelper::confirmWithException(Privilege::ListComments);
Access::assert(Privilege::ListComments);
$page = max(1, intval($page));
$commentsPerPage = intval(getConfig()->comments->commentsPerPage);
@ -33,9 +33,9 @@ class CommentController
public function addAction($postId)
{
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::AddComment);
Access::assert(Privilege::AddComment);
if (getConfig()->registration->needEmailForCommenting)
PrivilegesHelper::confirmEmail($context->user);
Access::assertEmailConfirmation();
$post = PostModel::findById($postId);
$context->transport->post = $post;
@ -70,9 +70,9 @@ class CommentController
$comment = CommentModel::findById($id);
$context->transport->comment = $comment;
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::EditComment,
PrivilegesHelper::getIdentitySubPrivilege($comment->getCommenter()));
Access::getIdentity($comment->getCommenter()));
if (InputHelper::get('submit'))
{
@ -95,9 +95,9 @@ class CommentController
{
$comment = CommentModel::findById($id);
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::DeleteComment,
PrivilegesHelper::getIdentitySubPrivilege($comment->getCommenter()));
Access::getIdentity($comment->getCommenter()));
CommentModel::remove($comment);

View file

@ -4,7 +4,7 @@ class LogController
public function listAction()
{
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::ListLogs);
Access::assert(Privilege::ListLogs);
$path = TextHelper::absolutePath(getConfig()->main->logsPath);
@ -38,7 +38,7 @@ class LogController
return;
}
PrivilegesHelper::confirmWithException(Privilege::ViewLog);
Access::assert(Privilege::ViewLog);
//parse input
$page = max(1, intval($page));

View file

@ -66,14 +66,14 @@ class PostController
$postsPerPage = intval(getConfig()->browsing->postsPerPage);
$context->transport->searchQuery = $query;
$context->transport->lastSearchQuery = $query;
PrivilegesHelper::confirmWithException(Privilege::ListPosts);
Access::assert(Privilege::ListPosts);
if ($source == 'mass-tag')
{
PrivilegesHelper::confirmWithException(Privilege::MassTag);
Access::assert(Privilege::MassTag);
$context->massTagTag = $additionalInfo;
$context->massTagQuery = $query;
if (!PrivilegesHelper::confirm(Privilege::MassTag, 'all'))
if (!Access::confirm(Privilege::MassTag, 'all'))
$query = trim($query . ' submit:' . $context->user->name);
}
@ -100,9 +100,9 @@ class PostController
if (InputHelper::get('submit'))
{
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::MassTag,
PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::getIdentity($post->getUploader()));
$tags = $post->getTags();
@ -157,9 +157,9 @@ class PostController
public function uploadAction()
{
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::UploadPost);
Access::assert(Privilege::UploadPost);
if (getConfig()->registration->needEmailForUploading)
PrivilegesHelper::confirmEmail($context->user);
Access::assertEmailConfirmation();
if (InputHelper::get('submit'))
{
@ -232,7 +232,7 @@ class PostController
public function flagAction($id)
{
$post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FlagPost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::FlagPost, Access::getIdentity($post->getUploader()));
if (InputHelper::get('submit'))
{
@ -252,7 +252,7 @@ class PostController
public function hideAction($id)
{
$post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::HidePost, Access::getIdentity($post->getUploader()));
if (InputHelper::get('submit'))
{
@ -267,7 +267,7 @@ class PostController
public function unhideAction($id)
{
$post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::HidePost, Access::getIdentity($post->getUploader()));
if (InputHelper::get('submit'))
{
@ -282,7 +282,7 @@ class PostController
public function deleteAction($id)
{
$post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::DeletePost, Access::getIdentity($post->getUploader()));
if (InputHelper::get('submit'))
{
@ -297,7 +297,7 @@ class PostController
{
$context = getContext();
$post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::FavoritePost, Access::getIdentity($post->getUploader()));
if (InputHelper::get('submit'))
{
@ -314,7 +314,7 @@ class PostController
{
$context = getContext();
$post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::FavoritePost, Access::getIdentity($post->getUploader()));
if (InputHelper::get('submit'))
{
@ -330,7 +330,7 @@ class PostController
{
$context = getContext();
$post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::ScorePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::ScorePost, Access::getIdentity($post->getUploader()));
if (InputHelper::get('submit'))
{
@ -346,7 +346,7 @@ class PostController
{
$context = getContext();
$post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FeaturePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::FeaturePost, Access::getIdentity($post->getUploader()));
PropertyModel::set(PropertyModel::FeaturedPostId, $post->id);
PropertyModel::set(PropertyModel::FeaturedPostDate, time());
PropertyModel::set(PropertyModel::FeaturedPostUserName, $context->user->name);
@ -361,9 +361,9 @@ class PostController
CommentModel::preloadCommenters($post->getComments());
if ($post->hidden)
PrivilegesHelper::confirmWithException(Privilege::ViewPost, 'hidden');
PrivilegesHelper::confirmWithException(Privilege::ViewPost);
PrivilegesHelper::confirmWithException(Privilege::ViewPost, PostSafety::toString($post->safety));
Access::assert(Privilege::ViewPost, 'hidden');
Access::assert(Privilege::ViewPost);
Access::assert(Privilege::ViewPost, PostSafety::toString($post->safety));
try
{
@ -403,8 +403,8 @@ class PostController
if (!file_exists($path))
{
$post = PostModel::findByIdOrName($name);
PrivilegesHelper::confirmWithException(Privilege::ListPosts);
PrivilegesHelper::confirmWithException(Privilege::ListPosts, PostSafety::toString($post->safety));
Access::assert(Privilege::ListPosts);
Access::assert(Privilege::ListPosts, PostSafety::toString($post->safety));
$post->makeThumb($width, $height);
if (!file_exists($path))
{
@ -430,8 +430,8 @@ class PostController
$config = getConfig();
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::RetrievePost);
PrivilegesHelper::confirmWithException(Privilege::RetrievePost, PostSafety::toString($post->safety));
Access::assert(Privilege::RetrievePost);
Access::assert(Privilege::RetrievePost, PostSafety::toString($post->safety));
$path = $config->main->filesPath . DS . $post->name;
$path = TextHelper::absolutePath($path);
@ -465,7 +465,7 @@ class PostController
if (!empty($_FILES['file']['name']))
{
if (!$isNew)
PrivilegesHelper::confirmWithException(Privilege::EditPostFile, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::EditPostFile, Access::getIdentity($post->getUploader()));
$suppliedFile = $_FILES['file'];
self::handleUploadErrors($suppliedFile);
@ -480,7 +480,7 @@ class PostController
elseif (InputHelper::get('url'))
{
if (!$isNew)
PrivilegesHelper::confirmWithException(Privilege::EditPostFile, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::EditPostFile, Access::getIdentity($post->getUploader()));
$url = InputHelper::get('url');
$post->setContentFromUrl($url);
@ -495,7 +495,7 @@ class PostController
if ($suppliedSafety !== null)
{
if (!$isNew)
PrivilegesHelper::confirmWithException(Privilege::EditPostSafety, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::EditPostSafety, Access::getIdentity($post->getUploader()));
$oldSafety = $post->safety;
$post->setSafety($suppliedSafety);
@ -510,7 +510,7 @@ class PostController
if ($suppliedTags !== null)
{
if (!$isNew)
PrivilegesHelper::confirmWithException(Privilege::EditPostTags, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::EditPostTags, Access::getIdentity($post->getUploader()));
$oldTags = array_map(function($tag) { return $tag->name; }, $post->getTags());
$post->setTagsFromText($suppliedTags);
@ -528,7 +528,7 @@ class PostController
if ($suppliedSource !== null)
{
if (!$isNew)
PrivilegesHelper::confirmWithException(Privilege::EditPostSource, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::EditPostSource, Access::getIdentity($post->getUploader()));
$oldSource = $post->source;
$post->setSource($suppliedSource);
@ -543,7 +543,7 @@ class PostController
if ($suppliedRelations !== null)
{
if (!$isNew)
PrivilegesHelper::confirmWithException(Privilege::EditPostRelations, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::EditPostRelations, Access::getIdentity($post->getUploader()));
$oldRelatedIds = array_map(function($post) { return $post->id; }, $post->getRelations());
$post->setRelationsFromText($suppliedRelations);
@ -560,7 +560,7 @@ class PostController
if (!empty($_FILES['thumb']['name']))
{
if (!$isNew)
PrivilegesHelper::confirmWithException(Privilege::EditPostThumb, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
Access::assert(Privilege::EditPostThumb, Access::getIdentity($post->getUploader()));
$suppliedFile = $_FILES['thumb'];
self::handleUploadErrors($suppliedFile);

View file

@ -5,7 +5,7 @@ class TagController
{
$context = getContext();
$context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::ListTags);
Access::assert(Privilege::ListTags);
$suppliedFilter = $filter ?: 'order:alpha,asc';
$page = max(1, intval($page));
@ -39,7 +39,7 @@ class TagController
public function autoCompleteAction()
{
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::ListTags);
Access::assert(Privilege::ListTags);
$suppliedSearch = InputHelper::get('search');
@ -60,7 +60,7 @@ class TagController
public function relatedAction()
{
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::ListTags);
Access::assert(Privilege::ListTags);
$suppliedContext = (array) InputHelper::get('context');
$suppliedTag = InputHelper::get('tag');
@ -85,7 +85,7 @@ class TagController
$context->viewName = 'tag-list-wrapper';
$context->handleExceptions = true;
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
Access::assert(Privilege::MergeTags);
if (InputHelper::get('submit'))
{
TagModel::removeUnused();
@ -112,7 +112,7 @@ class TagController
$context->viewName = 'tag-list-wrapper';
$context->handleExceptions = true;
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
Access::assert(Privilege::MergeTags);
if (InputHelper::get('submit'))
{
TagModel::removeUnused();
@ -138,7 +138,7 @@ class TagController
$context = getContext();
$context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::MassTag);
Access::assert(Privilege::MassTag);
if (InputHelper::get('submit'))
{
$suppliedOldPage = intval(InputHelper::get('old-page'));

View file

@ -103,7 +103,7 @@ class UserController
public function listAction($filter, $page)
{
$context = getContext();
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ListUsers);
$suppliedFilter = $filter ?: InputHelper::get('filter') ?: 'order:alpha,asc';
@ -128,9 +128,9 @@ class UserController
public function flagAction($name)
{
$user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::FlagUser,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
if (InputHelper::get('submit'))
{
@ -152,9 +152,9 @@ class UserController
public function banAction($name)
{
$user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::BanUser,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
if (InputHelper::get('submit'))
{
@ -169,9 +169,9 @@ class UserController
public function unbanAction($name)
{
$user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::BanUser,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
if (InputHelper::get('submit'))
{
@ -186,7 +186,7 @@ class UserController
public function acceptRegistrationAction($name)
{
$user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::AcceptUserRegistration);
if (InputHelper::get('submit'))
@ -202,12 +202,12 @@ class UserController
{
$context = getContext();
$user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ViewUser,
PrivilegesHelper::getIdentitySubPrivilege($user));
PrivilegesHelper::confirmWithException(
Access::getIdentity($user));
Access::assert(
Privilege::DeleteUser,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
$this->loadUserView($user);
$context->transport->tab = 'delete';
@ -239,12 +239,12 @@ class UserController
{
$context = getContext();
$user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ViewUser,
PrivilegesHelper::getIdentitySubPrivilege($user));
PrivilegesHelper::confirmWithException(
Access::getIdentity($user));
Access::assert(
Privilege::ChangeUserSettings,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
$this->loadUserView($user);
$context->transport->tab = 'settings';
@ -276,9 +276,9 @@ class UserController
try
{
$user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ViewUser,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
$this->loadUserView($user);
$context->transport->tab = 'edit';
@ -298,9 +298,9 @@ class UserController
if ($suppliedName != '' and $suppliedName != $user->name)
{
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ChangeUserName,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
$suppliedName = UserModel::validateUserName($suppliedName);
$oldName = $user->name;
@ -312,9 +312,9 @@ class UserController
if ($suppliedPassword1 != '')
{
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ChangeUserPassword,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
if ($suppliedPassword1 != $suppliedPassword2)
throw new SimpleException('Specified passwords must be the same');
@ -325,9 +325,9 @@ class UserController
if ($suppliedEmail != '' and $suppliedEmail != $user->emailConfirmed)
{
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ChangeUserEmail,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
$suppliedEmail = UserModel::validateEmail($suppliedEmail);
if ($context->user->id == $user->id)
@ -349,9 +349,9 @@ class UserController
if ($suppliedAccessRank != '' and $suppliedAccessRank != $user->accessRank)
{
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ChangeUserAccessRank,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
$suppliedAccessRank = UserModel::validateAccessRank($suppliedAccessRank);
$user->accessRank = $suppliedAccessRank;
@ -397,9 +397,9 @@ class UserController
if ($page === null)
$page = 1;
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ViewUser,
PrivilegesHelper::getIdentitySubPrivilege($user));
Access::getIdentity($user));
$this->loadUserView($user);
@ -430,9 +430,9 @@ class UserController
public function toggleSafetyAction($safety)
{
$context = getContext();
PrivilegesHelper::confirmWithException(
Access::assert(
Privilege::ChangeUserSettings,
PrivilegesHelper::getIdentitySubPrivilege($context->user));
Access::getIdentity($context->user));
if (!in_array($safety, PostSafety::getAll()))
throw new SimpleExcetpion('Invalid safety');

View file

@ -36,8 +36,6 @@ class PostEntity extends AbstractEntity
$this->setCache('uploader', $user);
}
public function getComments()
{
if ($this->hasCache('comments'))
@ -47,9 +45,6 @@ class PostEntity extends AbstractEntity
return $comments;
}
public function getFavorites()
{
if ($this->hasCache('favoritee'))
@ -65,8 +60,6 @@ class PostEntity extends AbstractEntity
return $favorites;
}
public function getRelations()
{
if ($this->hasCache('relations'))
@ -123,8 +116,6 @@ class PostEntity extends AbstractEntity
$this->setRelations($relatedPosts);
}
public function getTags()
{
if ($this->hasCache('tags'))
@ -173,9 +164,6 @@ class PostEntity extends AbstractEntity
return false;
}
public function setHidden($hidden)
{
$this->hidden = boolval($hidden);
@ -191,7 +179,6 @@ class PostEntity extends AbstractEntity
$this->source = PostModel::validateSource($source);
}
public function getThumbCustomPath($width = null, $height = null)
{
return PostModel::getThumbCustomPath($this->name, $width, $height);
@ -343,8 +330,6 @@ class PostEntity extends AbstractEntity
return true;
}
public function setContentFromPath($srcPath)
{
$this->fileSize = filesize($srcPath);
@ -471,8 +456,6 @@ class PostEntity extends AbstractEntity
}
}
public function getEditToken()
{
$x = [];

View file

@ -8,10 +8,10 @@ class CommentSearchParser extends AbstractSearchParser
$this->statement->addInnerJoin('post', new Sql\EqualsFunctor('post_id', 'post.id'));
$crit = new Sql\ConjunctionFunctor();
$allowedSafety = PrivilegesHelper::getAllowedSafety();
$allowedSafety = Access::getAllowedSafety();
$crit->add(Sql\InFunctor::fromArray('post.safety', Sql\Binding::fromArray($allowedSafety)));
if (!PrivilegesHelper::confirm(Privilege::ListPosts, 'hidden'))
if (!Access::check(Privilege::ListPosts, 'hidden'))
$crit->add(new Sql\NegationFunctor(new Sql\StringExpression('hidden')));
$this->statement->setCriterion($crit);

View file

@ -14,7 +14,7 @@ class PostSearchParser extends AbstractSearchParser
$this->tags = [];
$crit = new Sql\ConjunctionFunctor();
$allowedSafety = PrivilegesHelper::getAllowedSafety();
$allowedSafety = Access::getAllowedSafety();
$crit->add(Sql\InFunctor::fromArray('safety', Sql\Binding::fromArray($allowedSafety)));
$this->statement->setCriterion($crit);
@ -27,7 +27,7 @@ class PostSearchParser extends AbstractSearchParser
if (getContext()->user->hasEnabledHidingDislikedPosts() and !$this->showDisliked)
$this->processComplexToken('special', 'disliked', true);
if (!PrivilegesHelper::confirm(Privilege::ListPosts, 'hidden') or !$this->showHidden)
if (!Access::check(Privilege::ListPosts, 'hidden') or !$this->showHidden)
$this->processComplexToken('special', 'hidden', true);
foreach ($this->tags as $item)

View file

@ -5,7 +5,7 @@ class TagSearchParser extends AbstractSearchParser
{
protected function processSetup(&$tokens)
{
$allowedSafety = PrivilegesHelper::getAllowedSafety();
$allowedSafety = Access::getAllowedSafety();
$this->statement
->addInnerJoin('post_tag', new Sql\EqualsFunctor('tag.id', 'post_tag.tag_id'))
->addInnerJoin('post', new Sql\EqualsFunctor('post.id', 'post_tag.post_id'))

View file

@ -34,9 +34,9 @@ Assets::addScript('comment-edit.js');
<?= TextHelper::formatDate($this->context->comment->commentDate, false) ?>
</span>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::EditComment,
PrivilegesHelper::getIdentitySubPrivilege($commenter))): ?>
Access::getIdentity($commenter))): ?>
<span class="edit">
<a href="<?= \Chibi\Router::linkTo(['CommentController', 'editAction'], ['id' => $this->context->comment->id]) ?>">
edit
@ -45,8 +45,8 @@ Assets::addScript('comment-edit.js');
<?php endif ?>
<?php if (
PrivilegesHelper::confirm(Privilege::DeleteComment,
PrivilegesHelper::getIdentitySubPrivilege($commenter))): ?>
Access::check(Privilege::DeleteComment,
Access::getIdentity($commenter))): ?>
<span class="delete">
<a href="<?= \Chibi\Router::linkTo(['CommentController', 'deleteAction'], ['id' => $this->context->comment->id]) ?>"
class="simple-action confirmable"

View file

@ -42,7 +42,7 @@ Assets::addScript('core.js');
<span>Load:&nbsp;<?= sprintf('%.05f', microtime(true) - $this->context->startTime) ?>s</span>
<span>Queries:&nbsp;<?= count(\Chibi\Database::getLogs()) ?></span>
<span><a href="<?= SZURU_LINK ?>">szurubooru&nbsp;v<?= SZURU_VERSION ?></a></span>
<?php if (PrivilegesHelper::confirm(Privilege::ListLogs)): ?>
<?php if (Access::check(Privilege::ListLogs)): ?>
<span><a href="<?= \Chibi\Router::linkTo(['LogController', 'listAction']) ?>">Logs</a></span>
<?php endif ?>
<hr>

View file

@ -10,9 +10,9 @@
id="edit-token"
value="<?= htmlspecialchars($this->context->transport->post->getEditToken()) ?>"/>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::EditPostSafety,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
Access::getIdentity($this->context->transport->post->getUploader()))): ?>
<div class="form-row safety">
<label>Safety:</label>
@ -32,9 +32,9 @@
</div>
<?php endif ?>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::EditPostTags,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
Access::getIdentity($this->context->transport->post->getUploader()))): ?>
<div class="form-row tags">
<label for="tags">Tags:</label>
@ -51,8 +51,8 @@
<?php endif ?>
<?php if (
PrivilegesHelper::confirm(Privilege::EditPostSource,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
Access::check(Privilege::EditPostSource,
Access::getIdentity($this->context->transport->post->getUploader()))): ?>
<div class="form-row source">
<label for="source">Source:</label>
@ -66,8 +66,8 @@
<?php endif ?>
<?php if (
PrivilegesHelper::confirm(Privilege::EditPostRelations,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
Access::check(Privilege::EditPostRelations,
Access::getIdentity($this->context->transport->post->getUploader()))): ?>
<div class="form-row thumb">
<label for="relations">Relations:</label>
@ -84,8 +84,8 @@
<?php endif ?>
<?php if (
PrivilegesHelper::confirm(Privilege::EditPostFile,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
Access::check(Privilege::EditPostFile,
Access::getIdentity($this->context->transport->post->getUploader()))): ?>
<div class="form-row url">
<label for="url">File:</label>
@ -103,8 +103,8 @@
<?php endif ?>
<?php if (
PrivilegesHelper::confirm(Privilege::EditPostThumb,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
Access::check(Privilege::EditPostThumb,
Access::getIdentity($this->context->transport->post->getUploader()))): ?>
<div class="form-row thumb">
<label for="thumb">Thumb:</label>

View file

@ -3,31 +3,31 @@ Assets::setSubTitle('posts');
$tabs = [];
$activeTab = 0;
if (PrivilegesHelper::confirm(Privilege::ListPosts))
if (Access::check(Privilege::ListPosts))
$tabs []= ['All posts', \Chibi\Router::linkTo(['PostController', 'listAction'])];
if (PrivilegesHelper::confirm(Privilege::ListPosts))
if (Access::check(Privilege::ListPosts))
{
$tabs []= ['Random', \Chibi\Router::linkTo(['PostController', 'randomAction'])];
if ($this->context->simpleActionName == 'random')
$activeTab = count($tabs) - 1;
}
if (PrivilegesHelper::confirm(Privilege::ListPosts))
if (Access::check(Privilege::ListPosts))
{
$tabs []= ['Favorites', \Chibi\Router::linkTo(['PostController', 'favoritesAction'])];
if ($this->context->simpleActionName == 'favorites')
$activeTab = count($tabs) - 1;
}
if (PrivilegesHelper::confirm(Privilege::ListPosts))
if (Access::check(Privilege::ListPosts))
{
$tabs []= ['Upvoted', \Chibi\Router::linkTo(['PostController', 'upvotedAction'])];
if ($this->context->simpleActionName == 'upvoted')
$activeTab = count($tabs) - 1;
}
if (PrivilegesHelper::confirm(Privilege::MassTag))
if (Access::check(Privilege::MassTag))
{
$tabs []= ['Mass tag', \Chibi\Router::linkTo(['PostController', 'listAction'], [
'source' => 'mass-tag',

View file

@ -5,7 +5,7 @@ Assets::addScript('post-list.js');
<?php if (isset($this->context->source)
and $this->context->source == 'mass-tag'
and PrivilegesHelper::confirm(Privilege::MassTag)): ?>
and Access::check(Privilege::MassTag)): ?>
<?php \Chibi\View::render('tag-mass-tag', $this->context) ?>

View file

@ -17,9 +17,9 @@ $editPostPrivileges = [
$editPostPrivileges = array_fill_keys($editPostPrivileges, false);
foreach (array_keys($editPostPrivileges) as $privilege)
{
if (PrivilegesHelper::confirm(
if (Access::check(
$privilege,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader())))
Access::getIdentity($this->context->transport->post->getUploader())))
$editPostPrivileges[$privilege] = true;
}
@ -136,7 +136,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?= $this->context->transport->post->score ?>
<?php $scoreLink = function($score) { return \Chibi\Router::linkTo(['PostController', 'scoreAction'], ['id' => $this->context->transport->post->id, 'score' => $score]); } ?>
<?php if (PrivilegesHelper::confirm(Privilege::ScorePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
<?php if (Access::check(Privilege::ScorePost, Access::getIdentity($this->context->transport->post->getUploader()))): ?>
<?php if ($this->context->score === 1): ?>
<a class="simple-action selected" href="<?= $scoreLink(0) ?>">
<?php else: ?>
@ -176,7 +176,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
</div>
<?php endif ?>
<?php if (PrivilegesHelper::confirm(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
<?php if (Access::check(Privilege::FavoritePost, Access::getIdentity($this->context->transport->post->getUploader()))): ?>
<div class="hl-option">
<?php if (!$this->context->favorite): ?>
<a class="add-fav icon simple-action" href="<?= \Chibi\Router::linkTo(['PostController', 'addFavoriteAction'], ['id' => $this->context->transport->post->id]) ?>">
@ -235,7 +235,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php
$options = [];
if (PrivilegesHelper::confirm(Privilege::FeaturePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader())))
if (Access::check(Privilege::FeaturePost, Access::getIdentity($this->context->transport->post->getUploader())))
{
$options []=
[
@ -247,7 +247,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
];
}
if (PrivilegesHelper::confirm(Privilege::FlagPost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader())))
if (Access::check(Privilege::FlagPost, Access::getIdentity($this->context->transport->post->getUploader())))
{
if ($this->context->flagged)
{
@ -270,7 +270,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
}
}
if (PrivilegesHelper::confirm(Privilege::HidePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader())))
if (Access::check(Privilege::HidePost, Access::getIdentity($this->context->transport->post->getUploader())))
{
if ($this->context->transport->post->hidden)
{
@ -292,7 +292,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
}
}
if (PrivilegesHelper::confirm(Privilege::DeletePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader())))
if (Access::check(Privilege::DeletePost, Access::getIdentity($this->context->transport->post->getUploader())))
{
$options []=
[
@ -338,7 +338,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php endif ?>
</div>
<?php if (PrivilegesHelper::confirm(Privilege::AddComment)): ?>
<?php if (Access::check(Privilege::AddComment)): ?>
<div class="unit comment-add">
<?php \Chibi\View::render('comment-add', $this->context) ?>
</div>

View file

@ -3,10 +3,10 @@ Assets::setSubTitle('tags');
Assets::addStylesheet('tag-list.css');
$tabs = [];
if (PrivilegesHelper::confirm(Privilege::ListTags)) $tabs['list'] = ['List', 'listAction'];
if (PrivilegesHelper::confirm(Privilege::RenameTags)) $tabs['rename'] = ['Rename', 'renameAction'];
if (PrivilegesHelper::confirm(Privilege::MergeTags)) $tabs['merge'] = ['Merge', 'mergeAction'];
if (PrivilegesHelper::confirm(Privilege::MassTag)) $tabs['mass-tag-redirect'] = ['Mass tag', 'massTagRedirectAction'];
if (Access::check(Privilege::ListTags)) $tabs['list'] = ['List', 'listAction'];
if (Access::check(Privilege::RenameTags)) $tabs['rename'] = ['Rename', 'renameAction'];
if (Access::check(Privilege::MergeTags)) $tabs['merge'] = ['Merge', 'mergeAction'];
if (Access::check(Privilege::MassTag)) $tabs['mass-tag-redirect'] = ['Mass tag', 'massTagRedirectAction'];
$showTabs = count($tabs) > 1;
?>

View file

@ -18,7 +18,7 @@
\Chibi\Router::linkTo(['IndexController', 'indexAction']),
$activeController == 'index' and $activeAction == 'index');
if (PrivilegesHelper::confirm(Privilege::ListPosts))
if (Access::check(Privilege::ListPosts))
{
$registerNavItem(
'Browse',
@ -26,7 +26,7 @@
$activeController == 'post' and $activeAction != 'upload');
}
if (PrivilegesHelper::confirm(Privilege::UploadPost))
if (Access::check(Privilege::UploadPost))
{
$registerNavItem(
'Upload',
@ -34,7 +34,7 @@
$activeController == 'post' and $activeAction == 'upload');
}
if (PrivilegesHelper::confirm(Privilege::ListComments))
if (Access::check(Privilege::ListComments))
{
$registerNavItem(
'Comments',
@ -42,7 +42,7 @@
$activeController == 'comment');
}
if (PrivilegesHelper::confirm(Privilege::ListTags))
if (Access::check(Privilege::ListTags))
{
$registerNavItem(
'Tags',
@ -50,7 +50,7 @@
$activeController == 'tag');
}
if (PrivilegesHelper::confirm(Privilege::ListUsers))
if (Access::check(Privilege::ListUsers))
{
$registerNavItem(
'Users',
@ -104,11 +104,11 @@
}
?>
<?php if (PrivilegesHelper::confirm(Privilege::ChangeUserSettings, PrivilegesHelper::getIdentitySubPrivilege($this->context->user))): ?>
<?php if (Access::check(Privilege::ChangeUserSettings, Access::getIdentity($this->context->user))): ?>
<li class="safety">
<ul>
<?php foreach (PostSafety::getAll() as $safety): ?>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::ListPosts,
PostSafety::toString($safety))): ?>

View file

@ -13,9 +13,9 @@
<hr>
<?php endif ?>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::ChangeUserName,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
Access::getIdentity($this->context->transport->user))): ?>
<div class="form-row nickname">
<label for="name">Name:</label>
@ -30,9 +30,9 @@
</div>
<?php endif ?>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::ChangeUserEmail,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
Access::getIdentity($this->context->transport->user))): ?>
<div class="form-row email">
<label for="name">E-mail:</label>
@ -48,8 +48,8 @@
<?php endif ?>
<?php if (
PrivilegesHelper::confirm(Privilege::ChangeUserPassword,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
Access::check(Privilege::ChangeUserPassword,
Access::getIdentity($this->context->transport->user))): ?>
<div class="form-row password1">
<label for="password1">New password:</label>
@ -75,9 +75,9 @@
</div>
<?php endif ?>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::ChangeUserAccessRank,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
Access::getIdentity($this->context->transport->user))): ?>
<div class="form-row access-rank">
<label for="access-rank">Access rank:</label>

View file

@ -3,7 +3,7 @@
<label>Safety:</label>
<div class="input-wrapper">
<?php foreach (PostSafety::getAll() as $safety): ?>
<?php if (PrivilegesHelper::confirm(Privilege::ListPosts, PostSafety::toString($safety))): ?>
<?php if (Access::check(Privilege::ListPosts, PostSafety::toString($safety))): ?>
<label>
<?php
$attrs = [];

View file

@ -49,9 +49,9 @@ Assets::addStylesheet('user-view.css');
</span>
</div>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::ViewUserEmail,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
Access::getIdentity($this->context->transport->user))): ?>
<div class="key-value email">
<span class="key">E-mail:</span>
@ -76,9 +76,9 @@ Assets::addStylesheet('user-view.css');
foreach (array_keys($userModificationPrivileges) as $privilege)
{
if (PrivilegesHelper::confirm(
if (Access::check(
$privilege,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user)))
Access::getIdentity($this->context->transport->user)))
{
$userModificationPrivileges[$privilege] = true;
}
@ -98,7 +98,7 @@ Assets::addStylesheet('user-view.css');
];
}
if (PrivilegesHelper::confirm(Privilege::AcceptUserRegistration)
if (Access::check(Privilege::AcceptUserRegistration)
and !$this->context->transport->user->staffConfirmed
and getConfig()->registration->staffActivation)
{
@ -111,9 +111,9 @@ Assets::addStylesheet('user-view.css');
];
}
if (PrivilegesHelper::confirm(
if (Access::check(
Privilege::FlagUser,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user)))
Access::getIdentity($this->context->transport->user)))
{
if ($this->context->flagged)
{
@ -137,9 +137,9 @@ Assets::addStylesheet('user-view.css');
}
}
if (PrivilegesHelper::confirm(
if (Access::check(
Privilege::BanUser,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user)))
Access::getIdentity($this->context->transport->user)))
{
if (!$this->context->transport->user->banned)
{
@ -165,9 +165,9 @@ Assets::addStylesheet('user-view.css');
}
}
if (PrivilegesHelper::confirm(
if (Access::check(
Privilege::DeleteUser,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user)))
Access::getIdentity($this->context->transport->user)))
{
$options []=
[
@ -212,9 +212,9 @@ Assets::addStylesheet('user-view.css');
</a>
</li>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::ChangeUserSettings,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
Access::getIdentity($this->context->transport->user))): ?>
<?php if ($this->context->transport->tab == 'settings'): ?>
<li class="selected settings">
@ -241,9 +241,9 @@ Assets::addStylesheet('user-view.css');
</li>
<?php endif ?>
<?php if (PrivilegesHelper::confirm(
<?php if (Access::check(
Privilege::DeleteUser,
PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
Access::getIdentity($this->context->transport->user))): ?>
<?php if ($this->context->transport->tab == 'delete'): ?>
<li class="selected delete">
<?php else: ?>