From 2b59736b2592a01ee880f0cc4439622b437acd85 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 2 Sep 2014 17:50:21 +0200 Subject: [PATCH] Add optional User parameter to Category::getPermission() --- .../lib/data/category/Category.class.php | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/lib/data/category/Category.class.php b/wcfsetup/install/files/lib/data/category/Category.class.php index bf42a494c0..16fc69422d 100644 --- a/wcfsetup/install/files/lib/data/category/Category.class.php +++ b/wcfsetup/install/files/lib/data/category/Category.class.php @@ -1,5 +1,6 @@ */ protected $permissions = null; + /** + * acl permissions of this category grouped by the id of the user they + * belong to + * @var array + */ + protected $userPermissions = array(); + /** * fallback return value used in Category::getPermission() * @var boolean @@ -153,17 +162,25 @@ class Category extends ProcessibleDatabaseObject implements IPermissionObject, I /** * @see \wcf\data\IPermissionObject::getPermission() */ - public function getPermission($permission) { - if ($this->permissions === null) { - $this->permissions = CategoryPermissionHandler::getInstance()->getPermissions($this); + public function getPermission($permission, User $user = null) { + if ($user === null) { + $user = WCF::getUser(); + } + + if (!isset($this->userPermissions[$user->userID])) { + $this->userPermissions[$user->userID] = CategoryPermissionHandler::getInstance()->getPermissions($this, $user); + + if ($user->userID == WCF::getUser()->userID) { + $this->permissions = $this->userPermissions[$user->userID]; + } } - if (isset($this->permissions[$permission])) { - return $this->permissions[$permission]; + if (isset($this->userPermissions[$user->userID][$permission])) { + return $this->userPermissions[$user->userID][$permission]; } if ($this->getParentCategory()) { - return $this->getParentCategory()->getPermission($permission); + return $this->getParentCategory()->getPermission($permission, $user); } if ($this->getObjectType()->defaultpermission !== null) { -- 2.20.1