From 396ea97cada701e3765e9a0ba00aa5a6cf3400cb Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 29 Apr 2014 23:52:17 +0200 Subject: [PATCH] PrivilegesHelper shortened to Access Methods are shorter, too --- .../PrivilegesHelper.php => Access.php} | 19 +++--- src/Controllers/AuthController.php | 2 +- src/Controllers/CommentController.php | 14 ++--- src/Controllers/LogController.php | 4 +- src/Controllers/PostController.php | 58 +++++++++--------- src/Controllers/TagController.php | 12 ++-- src/Controllers/UserController.php | 60 +++++++++---------- src/Models/Entities/PostEntity.php | 17 ------ .../SearchParsers/CommentSearchParser.php | 4 +- src/Models/SearchParsers/PostSearchParser.php | 4 +- src/Models/SearchParsers/TagSearchParser.php | 2 +- src/Views/comment-small.phtml | 8 +-- src/Views/layout-normal.phtml | 2 +- src/Views/post-edit.phtml | 24 ++++---- src/Views/post-list-wrapper.phtml | 10 ++-- src/Views/post-list.phtml | 2 +- src/Views/post-view.phtml | 18 +++--- src/Views/tag-list-wrapper.phtml | 8 +-- src/Views/top-navigation.phtml | 14 ++--- src/Views/user-edit.phtml | 16 ++--- src/Views/user-settings.phtml | 2 +- src/Views/user-view.phtml | 30 +++++----- 22 files changed, 157 insertions(+), 173 deletions(-) rename src/{Helpers/PrivilegesHelper.php => Access.php} (81%) diff --git a/src/Helpers/PrivilegesHelper.php b/src/Access.php similarity index 81% rename from src/Helpers/PrivilegesHelper.php rename to src/Access.php index 9d0c9611..48d64fa7 100644 --- a/src/Helpers/PrivilegesHelper.php +++ b/src/Access.php @@ -1,5 +1,5 @@ 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(); diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index 0731e76a..7117fc44 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -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(); diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php index 096d803a..a66b4872 100644 --- a/src/Controllers/CommentController.php +++ b/src/Controllers/CommentController.php @@ -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); diff --git a/src/Controllers/LogController.php b/src/Controllers/LogController.php index 888a5542..51872e3d 100644 --- a/src/Controllers/LogController.php +++ b/src/Controllers/LogController.php @@ -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)); diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 05946e03..e6db8fdd 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -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); diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 20109e87..3d2e2f87 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -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')); diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index ef3ddb2a..843e7557 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -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'); diff --git a/src/Models/Entities/PostEntity.php b/src/Models/Entities/PostEntity.php index c8251d4a..acd58898 100644 --- a/src/Models/Entities/PostEntity.php +++ b/src/Models/Entities/PostEntity.php @@ -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 = []; diff --git a/src/Models/SearchParsers/CommentSearchParser.php b/src/Models/SearchParsers/CommentSearchParser.php index cdef5f40..9df1f472 100644 --- a/src/Models/SearchParsers/CommentSearchParser.php +++ b/src/Models/SearchParsers/CommentSearchParser.php @@ -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); diff --git a/src/Models/SearchParsers/PostSearchParser.php b/src/Models/SearchParsers/PostSearchParser.php index fc097242..2ee3e6b3 100644 --- a/src/Models/SearchParsers/PostSearchParser.php +++ b/src/Models/SearchParsers/PostSearchParser.php @@ -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) diff --git a/src/Models/SearchParsers/TagSearchParser.php b/src/Models/SearchParsers/TagSearchParser.php index 3b826b6b..6b348655 100644 --- a/src/Models/SearchParsers/TagSearchParser.php +++ b/src/Models/SearchParsers/TagSearchParser.php @@ -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')) diff --git a/src/Views/comment-small.phtml b/src/Views/comment-small.phtml index f248957a..15017f0e 100644 --- a/src/Views/comment-small.phtml +++ b/src/Views/comment-small.phtml @@ -34,9 +34,9 @@ Assets::addScript('comment-edit.js'); context->comment->commentDate, false) ?> - + Access::getIdentity($commenter))): ?> edit @@ -45,8 +45,8 @@ Assets::addScript('comment-edit.js'); + Access::check(Privilege::DeleteComment, + Access::getIdentity($commenter))): ?> Load: context->startTime) ?>s Queries:  szurubooru v - + Logs
diff --git a/src/Views/post-edit.phtml b/src/Views/post-edit.phtml index c2a85654..22a3cec9 100644 --- a/src/Views/post-edit.phtml +++ b/src/Views/post-edit.phtml @@ -10,9 +10,9 @@ id="edit-token" value="context->transport->post->getEditToken()) ?>"/> - context->transport->post->getUploader()))): ?> + Access::getIdentity($this->context->transport->post->getUploader()))): ?>
@@ -32,9 +32,9 @@
- context->transport->post->getUploader()))): ?> + Access::getIdentity($this->context->transport->post->getUploader()))): ?>
@@ -51,8 +51,8 @@ context->transport->post->getUploader()))): ?> + Access::check(Privilege::EditPostSource, + Access::getIdentity($this->context->transport->post->getUploader()))): ?>
@@ -66,8 +66,8 @@ context->transport->post->getUploader()))): ?> + Access::check(Privilege::EditPostRelations, + Access::getIdentity($this->context->transport->post->getUploader()))): ?>
@@ -84,8 +84,8 @@ context->transport->post->getUploader()))): ?> + Access::check(Privilege::EditPostFile, + Access::getIdentity($this->context->transport->post->getUploader()))): ?>
@@ -103,8 +103,8 @@ context->transport->post->getUploader()))): ?> + Access::check(Privilege::EditPostThumb, + Access::getIdentity($this->context->transport->post->getUploader()))): ?>
diff --git a/src/Views/post-list-wrapper.phtml b/src/Views/post-list-wrapper.phtml index d4d81d99..0b9815a8 100644 --- a/src/Views/post-list-wrapper.phtml +++ b/src/Views/post-list-wrapper.phtml @@ -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', diff --git a/src/Views/post-list.phtml b/src/Views/post-list.phtml index ee0e7e30..12c8c9f2 100644 --- a/src/Views/post-list.phtml +++ b/src/Views/post-list.phtml @@ -5,7 +5,7 @@ Assets::addScript('post-list.js'); context->source) and $this->context->source == 'mass-tag' - and PrivilegesHelper::confirm(Privilege::MassTag)): ?> + and Access::check(Privilege::MassTag)): ?> context) ?> diff --git a/src/Views/post-view.phtml b/src/Views/post-view.phtml index 80a5fcb4..446d6b30 100644 --- a/src/Views/post-view.phtml +++ b/src/Views/post-view.phtml @@ -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; context->transport->post->score ?> $this->context->transport->post->id, 'score' => $score]); } ?> - context->transport->post->getUploader()))): ?> + context->transport->post->getUploader()))): ?> context->score === 1): ?> @@ -176,7 +176,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
- context->transport->post->getUploader()))): ?> + context->transport->post->getUploader()))): ?>
context->favorite): ?> @@ -235,7 +235,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0; 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;
- +
context) ?>
diff --git a/src/Views/tag-list-wrapper.phtml b/src/Views/tag-list-wrapper.phtml index 969a4062..3863c515 100644 --- a/src/Views/tag-list-wrapper.phtml +++ b/src/Views/tag-list-wrapper.phtml @@ -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; ?> diff --git a/src/Views/top-navigation.phtml b/src/Views/top-navigation.phtml index c4bf8c02..fc4791a4 100644 --- a/src/Views/top-navigation.phtml +++ b/src/Views/top-navigation.phtml @@ -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 @@ } ?> - context->user))): ?> + context->user))): ?>