diff --git a/Classes/Cache/PermissionCache.php b/Classes/Cache/PermissionCache.php index 55b96e7..1ff7874 100644 --- a/Classes/Cache/PermissionCache.php +++ b/Classes/Cache/PermissionCache.php @@ -1,4 +1,5 @@ permissionCacheFirstLevel = array(); + $this->permissionCacheFirstLevel = []; $this->timestampUtility->updateTimestamp(); } /** - * Returns the stored permissions clause cache entry if one is found + * Returns the stored permissions clause cache entry if one is found. * * @param string $requestedPermissions + * * @return string|null If a cache entry is found the permissions clause will be returned, otherwise NULL */ public function getPermissionsClause($requestedPermissions) { - if (!isset($this->backendUser)) { return null; } @@ -117,16 +116,15 @@ public function getPermissionsClause($requestedPermissions) if ($this->isValidCacheData($cacheData)) { return $cacheData->getPermissionClause($requestedPermissions); - } else { - return null; } + return null; } /** * Sets the Backend user for which the cache entries will be managed. * * @param \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUser The Backend user for which the - * cache is managed + * cache is managed */ public function setBackendUser($backendUser) { @@ -147,11 +145,9 @@ public function setPermissionCache($permissionCache) * * @param string $requestedPermissions * @param string $permissionsClause - * @return void */ public function setPermissionsClause($requestedPermissions, $permissionsClause) { - if (!isset($this->backendUser)) { return; } @@ -164,7 +160,7 @@ public function setPermissionsClause($requestedPermissions, $permissionsClause) $cacheData = $this->getCacheDataForCurrentUser(); if (!$this->isValidCacheData($cacheData)) { - $cacheData = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('JBartels\\BeAcl\\Cache\\PermissionCacheData'); + $cacheData = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(PermissionCacheData::class); } $cacheData->setPermissionClause($requestedPermissions, $permissionsClause); @@ -188,7 +184,6 @@ public function setTimestampUtility($timestampUtility) */ protected function getCacheDataForCurrentUser() { - $cacheIdentifier = $this->getCacheIdentifier(); if ($this->permissionCacheSecondLevel->has($cacheIdentifier)) { return $this->permissionCacheSecondLevel->get($cacheIdentifier); @@ -202,21 +197,22 @@ protected function getCacheDataForCurrentUser() * cache in the users session data. * * @param string $requestedPermissions + * * @return string + * * @throws \JBartels\BeAcl\Exception\RuntimeException */ protected function getCacheIdentifier($requestedPermissions = '') { - if (!isset($this->backendUser)) { throw new \JBartels\BeAcl\Exception\RuntimeException('The Backend user needs to be initializes before the cache identifier can be generated.'); } - $usergroup_cached_list = str_replace( ',', '_', $this->backendUser->user['usergroup_cached_list'] ); + $usergroup_cached_list = str_replace(',', '_', $this->backendUser->user['usergroup_cached_list']); $identifier = static::CACHE_IDENTIFIER_PERMISSIONS . '_' . $this->backendUser->user['uid'] . '_' . $usergroup_cached_list; $requestedPermissions = trim($requestedPermissions); - if ($requestedPermissions !== '') { + if ('' !== $requestedPermissions) { $identifier .= '_' . $requestedPermissions; } @@ -229,22 +225,22 @@ protected function getCacheIdentifier($requestedPermissions = '') protected function initializeRequiredClasses() { /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */ - $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager'); + $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(CacheManager::class); $this->setPermissionCache($cacheManager->getCache('tx_be_acl_permissions')); /** @var TimestampUtility $timestampUtility */ - $timestampUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('JBartels\\BeAcl\\Cache\\TimestampUtility'); + $timestampUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(TimestampUtility::class); $this->setTimestampUtility($timestampUtility); } /** - * Returns TRUE if the given cache data is valid + * Returns TRUE if the given cache data is valid. * * @param PermissionCacheData $cacheData + * * @return bool */ protected function isValidCacheData($cacheData) { - if (!isset($cacheData)) { return false; } diff --git a/Classes/Cache/PermissionCacheData.php b/Classes/Cache/PermissionCacheData.php index f77cbb6..5014972 100644 --- a/Classes/Cache/PermissionCacheData.php +++ b/Classes/Cache/PermissionCacheData.php @@ -1,4 +1,5 @@ timestamp = time(); - $this->permissionClauseCache = array(); + $this->permissionClauseCache = []; } /** * Returns the matching permissions clause or NULL if none is stored. * * @param $requestedPermissions + * * @return string|null */ public function getPermissionClause($requestedPermissions) { - if (array_key_exists($requestedPermissions, $this->permissionClauseCache)) { $permissionsClause = $this->permissionClauseCache[$requestedPermissions]; if (!empty($permissionsClause)) { diff --git a/Classes/Cache/TimestampUtility.php b/Classes/Cache/TimestampUtility.php index 8d89efe..564ebed 100644 --- a/Classes/Cache/TimestampUtility.php +++ b/Classes/Cache/TimestampUtility.php @@ -1,4 +1,5 @@ initializeCache(); $lastPermissionChangeTimestamp = $this->getLastPermissionChangeTimestampFromCache(); $timestamp = intval($timestamp); - return ($lastPermissionChangeTimestamp < $timestamp); + return $lastPermissionChangeTimestamp < $timestamp; } /** @@ -77,10 +78,9 @@ public function setTimestampCache($timestampCache) } /** - * Updates the timestamp in the cache with the current timestamp + * Updates the timestamp in the cache with the current timestamp. * * @param int $offset - * @return void */ public function updateTimestamp($offset = 0) { @@ -97,7 +97,6 @@ public function updateTimestamp($offset = 0) */ protected function getLastPermissionChangeTimestampFromCache() { - // Return directly if timestamp is found in the first level cache. if (isset($this->timestampCacheFirstLevel)) { return $this->timestampCacheFirstLevel; @@ -107,6 +106,7 @@ protected function getLastPermissionChangeTimestampFromCache() if ($this->timestampCache->has(static::CACHE_IDENTIFIER_TIMESTAMP)) { $timestamp = (int)$this->timestampCache->get(static::CACHE_IDENTIFIER_TIMESTAMP); $this->timestampCacheFirstLevel = $timestamp; + return $timestamp; } @@ -114,19 +114,16 @@ protected function getLastPermissionChangeTimestampFromCache() } /** - * Initializes the timestamp cache - * - * @return void + * Initializes the timestamp cache. */ protected function initializeCache() { - if (isset($this->timestampCache)) { return; } /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */ - $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\Core\\Cache\\CacheManager'); + $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(CacheManager::class); $this->setTimestampCache($cacheManager->getCache('tx_be_acl_timestamp')); } } diff --git a/Classes/Controller/PermissionAjaxController.php b/Classes/Controller/PermissionAjaxController.php index 4acb240..12e89ae 100644 --- a/Classes/Controller/PermissionAjaxController.php +++ b/Classes/Controller/PermissionAjaxController.php @@ -1,4 +1,5 @@ view = GeneralUtility::makeInstance(StandaloneView::class); - $this->view->setPartialRootPaths(array('default' => $this->extPath . 'Resources/Private/Partials')); + $this->view->setPartialRootPaths(['default' => $this->extPath . 'Resources/Private/Partials']); $this->view->assign('pageId', $this->conf['page']); } @@ -74,7 +75,8 @@ protected function initializeView() * The main dispatcher function. Collect data and prepare HTML output. * * @param ServerRequestInterface $request - * @param ResponseInterface $response + * @param ResponseInterface $response + * * @return ResponseInterface */ public function dispatch(ServerRequestInterface $request, ResponseInterface $response) @@ -87,20 +89,19 @@ public function dispatch(ServerRequestInterface $request, ResponseInterface $res if ($this->conf['page'] > 0 && in_array($action, $handledActions)) { return $this->handleAction($request, $response, $action); } // Action handled by parent - else { - return parent::dispatch($request, $response); - } + + return parent::dispatch($request, $response); } protected function handleAction(ServerRequestInterface $request, ResponseInterface $response, $action) { $methodName = GeneralUtility::underscoredToLowerCamelCase($action); if (method_exists($this, $methodName)) { - return call_user_func_array(array($this, $methodName), [$request, $response]); - } else { - $response->getBody()->write('Action method not found'); - return $response->withStatus(400); + return call_user_func_array([$this, $methodName], [$request, $response]); } + $response->getBody()->write('Action method not found'); + + return $response->withStatus(400); } protected function deleteAcl(ServerRequestInterface $request, ResponseInterface $response) @@ -118,15 +119,15 @@ protected function deleteAcl(ServerRequestInterface $request, ResponseInterface // Prepare command map $cmdMap = [ $this->table => [ - $aclUid => ['delete' => 1] - ] + $aclUid => ['delete' => 1], + ], ]; try { // Process command map $tce = GeneralUtility::makeInstance(DataHandler::class); $tce->stripslashes_values = 0; - $tce->start(array(), $cmdMap); + $tce->start([], $cmdMap); $this->checkModifyAccess($this->table, $aclUid, $tce); $tce->process_cmdmap(); } catch (\Exception $ex) { @@ -135,10 +136,11 @@ protected function deleteAcl(ServerRequestInterface $request, ResponseInterface $body = [ 'title' => $GLOBALS['LANG']->getLL('aclSuccess'), - 'message' => $GLOBALS['LANG']->getLL('aclDeleted') + 'message' => $GLOBALS['LANG']->getLL('aclDeleted'), ]; // Return result $response->getBody()->write(json_encode($body)); + return $response; } diff --git a/Classes/Controller/PermissionController.php b/Classes/Controller/PermissionController.php index feb7baa..1ef465f 100644 --- a/Classes/Controller/PermissionController.php +++ b/Classes/Controller/PermissionController.php @@ -1,4 +1,5 @@ Access" + * Backend ACL - Replacement for "web->Access". * * @author Sebastian Kurfuerst * @@ -44,7 +42,6 @@ */ class PermissionController extends \TYPO3\CMS\Beuser\Controller\PermissionController { - protected $defaultViewObjectName = BackendTemplateView::class; protected $aclList = []; @@ -60,27 +57,24 @@ class PermissionController extends \TYPO3\CMS\Beuser\Controller\PermissionContro *****************************/ /** - * Initialize action - * - * @return void + * Initialize action. */ protected function initializeAction() { parent::initializeAction(); - if(empty($this->returnUrl)) { + if (empty($this->returnUrl)) { $this->returnUrl = $this->uriBuilder->reset()->setArguments([ 'action' => 'index', - 'id' => $this->id + 'id' => $this->id, ])->buildBackendUri(); } } /** - * Initializes view + * Initializes view. * * @param ViewInterface $view The view to be initialized - * @return void */ protected function initializeView(ViewInterface $view) { @@ -92,9 +86,7 @@ protected function initializeView(ViewInterface $view) } /** - * Index action - * - * @return void + * Index action. */ public function indexAction() { @@ -121,7 +113,7 @@ public function indexAction() return !empty($var['selected']); }); } - // No filter enabled, so show all user ACLs + // No filter enabled, so show all user ACLs else { $usersSelected = $userAcls; } @@ -131,7 +123,7 @@ public function indexAction() $this->view->assign('userFilterOptions', [ 'options' => $userAcls, 'title' => $GLOBALS['LANG']->getLL('aclUsers'), - 'id' => 'userAclFilter' + 'id' => 'userAclFilter', ]); /* @@ -154,7 +146,7 @@ public function indexAction() $this->view->assign('groupFilterOptions', [ 'options' => $groupAcls, 'title' => $GLOBALS['LANG']->getLL('aclGroups'), - 'id' => 'groupAclFilter' + 'id' => 'groupAclFilter', ]); /* @@ -165,9 +157,7 @@ public function indexAction() } /** - * Edit action - * - * @return void + * Edit action. */ public function editAction() { @@ -185,18 +175,20 @@ public function editAction() // ACL CODE $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_beacl_acl', 'pid=' . (int)$this->id); - $pageAcls = array(); + $pageAcls = []; while ($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $pageAcls[] = $result; } - $userGroupSelectorOptions = array(); - foreach (array(1 => 'Group', 0 => 'User') as $type => $label) { + $userGroupSelectorOptions = []; + foreach ([1 => 'Group', 0 => 'User'] as $type => $label) { $option = new \stdClass(); $option->key = $type; - $option->value = LocalizationUtility::translate('LLL:EXT:be_acl/Resources/Private/Languages/locallang_perm.xlf:acl' . $label, - 'be_acl'); + $option->value = LocalizationUtility::translate( + 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_perm.xlf:acl' . $label, + 'be_acl' + ); $userGroupSelectorOptions[] = $option; } $this->view->assign('userGroupSelectorOptions', $userGroupSelectorOptions); @@ -204,18 +196,17 @@ public function editAction() } /** - * Update action + * Update action. * * @param array $data * @param array $mirror - * @return void */ protected function updateAction(array $data, array $mirror) { // Process data map - $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler'); + $tce = GeneralUtility::makeInstance(DataHandler::class); $tce->stripslashes_values = 0; - $tce->start($data, array()); + $tce->start($data, []); $tce->process_datamap(); parent::updateAction($data, $mirror); @@ -241,14 +232,16 @@ protected function getCurrentAction() if (is_null($this->currentAction)) { $this->currentAction = $this->request->getControllerActionName(); } + return $this->currentAction; } /** - * * @global array $BE_USER - * @param int $type + * + * @param int $type * @param array $conf + * * @return array */ protected function aclObjects($type, $conf) @@ -272,10 +265,10 @@ protected function aclObjects($type, $conf) // If filter selector is enabled, then determine currently selected items if ($conf['enableFilterSelector']) { // get current selection from UC, merge data, write it back to UC - $currentSelection = is_array($BE_USER->uc['moduleData']['txbeacl_aclSelector'][$type]) ? $BE_USER->uc['moduleData']['txbeacl_aclSelector'][$type] : array(); + $currentSelection = is_array($BE_USER->uc['moduleData']['txbeacl_aclSelector'][$type]) ? $BE_USER->uc['moduleData']['txbeacl_aclSelector'][$type] : []; $currentSelectionOverride_raw = GeneralUtility::_GP('tx_beacl_objsel'); - $currentSelectionOverride = array(); + $currentSelectionOverride = []; if (is_array($currentSelectionOverride_raw[$type])) { foreach ($currentSelectionOverride_raw[$type] as $tmp) { $currentSelectionOverride[$tmp] = $tmp; @@ -304,16 +297,16 @@ protected function aclObjects($type, $conf) * 'permissions' => 31 * 'recursive' => 1, * 'pid' => 10 - * ]; + * ];. * - * @param array $users - user ID list + * @param array $users - user ID list * @param array $groups - group ID list */ protected function buildACLtree($users, $groups) { $startPerms = [ 0 => [], - 1 => [] + 1 => [], ]; // get permissions in the starting point for users and groups @@ -324,12 +317,15 @@ protected function buildACLtree($users, $groups) foreach ($rootLine as $level => $values) { $recursive = ' AND recursive=1'; - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid, type, object_id, permissions, recursive', - 'tx_beacl_acl', 'pid=' . intval($values['uid']) . $recursive); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( + 'uid,pid, type, object_id, permissions, recursive', + 'tx_beacl_acl', + 'pid=' . intval($values['uid']) . $recursive + ); while ($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // User type ACLs - if ($result['type'] == 0 + if (0 == $result['type'] && in_array($result['object_id'], $users) && !array_key_exists($result['object_id'], $startPerms[0]) ) { @@ -337,11 +333,11 @@ protected function buildACLtree($users, $groups) 'uid' => $result['uid'], 'permissions' => $result['permissions'], 'recursive' => $result['recursive'], - 'pid' => $result['pid'] + 'pid' => $result['pid'], ]; } // Group type ACLs - elseif ($result['type'] == 1 + elseif (1 == $result['type'] && in_array($result['object_id'], $groups) && !array_key_exists($result['object_id'], $startPerms[1]) ) { @@ -349,7 +345,7 @@ protected function buildACLtree($users, $groups) 'uid' => $result['uid'], 'permissions' => $result['permissions'], 'recursive' => $result['recursive'], - 'pid' => $result['pid'] + 'pid' => $result['pid'], ]; } } @@ -362,12 +358,13 @@ protected function getDefaultAclMetaData() { return array_fill_keys($this->aclTypes, [ 'acls' => 0, - 'inherited' => 0 + 'inherited' => 0, ]); } /** - * Adds count meta data to the page ACL list + * Adds count meta data to the page ACL list. + * * @param array $pageData */ protected function addAclMetaData(&$pageData) @@ -384,33 +381,36 @@ protected function addAclMetaData(&$pageData) /** * Finds ACL permissions for specified page and its children recursively, given * the parent ACLs. + * * @param array $parentACLs - * @param int $pageId + * @param int $pageId */ protected function traversePageTree_acl($parentACLs, $pageId) { // Fetch ACLs aasigned to given page - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid, type, object_id, permissions, recursive', - 'tx_beacl_acl', 'pid=' . intval($pageId)); - $hasNoRecursive = array(); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( + 'uid,pid, type, object_id, permissions, recursive', + 'tx_beacl_acl', + 'pid=' . intval($pageId) + ); + $hasNoRecursive = []; $this->aclList[$pageId] = $parentACLs; $this->addAclMetaData($this->aclList[$pageId]); while ($result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - $aclData = array( + $aclData = [ 'uid' => $result['uid'], 'permissions' => $result['permissions'], 'recursive' => $result['recursive'], - 'pid' => $result['pid'] - ); + 'pid' => $result['pid'], + ]; // Non-recursive ACL - if ($result['recursive'] == 0) { + if (0 == $result['recursive']) { $this->aclList[$pageId][$result['type']][$result['object_id']] = $aclData; $hasNoRecursive[$pageId][$result['type']][$result['object_id']] = $aclData; - } - else { + } else { // Recursive ACL // Add to parent ACLs for sub-pages $parentACLs[$result['type']][$result['object_id']] = $aclData; @@ -424,7 +424,7 @@ protected function traversePageTree_acl($parentACLs, $pageId) } // Increment ACL count - $this->aclList[$pageId]['meta'][$result['type']]['acls'] += 1; + ++$this->aclList[$pageId]['meta'][$result['type']]['acls']; } // Find child pages and their ACL permissions @@ -433,6 +433,4 @@ protected function traversePageTree_acl($parentACLs, $pageId) $this->traversePageTree_acl($parentACLs, $result['uid']); } } - } - diff --git a/Classes/Exception/RuntimeException.php b/Classes/Exception/RuntimeException.php index f724600..9b113c0 100644 --- a/Classes/Exception/RuntimeException.php +++ b/Classes/Exception/RuntimeException.php @@ -1,4 +1,5 @@ flushPermissionCache(); + return; } // If a ACL is modified or created we also flush the cache - if ($table == 'tx_beacl_acl') { + if ('tx_beacl_acl' == $table) { $this->flushPermissionCache(); } } @@ -65,12 +66,11 @@ public function processDatamap_afterDatabaseOperations($status, $table, $recordI * This hook is called when a record is moved or deleted. * It flushes the permission cache when a tx_beacl_acl has changed. * - * @param string $command The TCE command. - * @param string $table The record's table. - * @param integer $recordId The record's uid. - * @param array $commandValue The commands value, typically an array with more detailed command information. - * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tceMain The TCEmain parent object. - * @return void + * @param string $command the TCE command + * @param string $table the record's table + * @param int $recordId the record's uid + * @param array $commandValue the commands value, typically an array with more detailed command information + * @param \TYPO3\CMS\Core\DataHandling\DataHandler $tceMain the TCEmain parent object */ public function processCmdmap_postProcess( $command, @@ -79,9 +79,8 @@ public function processCmdmap_postProcess( $commandValue, \TYPO3\CMS\Core\DataHandling\DataHandler $tceMain ) { - // This is required to take care of deleted ACLs. - if ($table == 'tx_beacl_acl') { + if ('tx_beacl_acl' == $table) { $this->flushPermissionCache(); } } @@ -92,8 +91,7 @@ public function processCmdmap_postProcess( protected function flushPermissionCache() { /** @var \JBartels\BeAcl\Cache\PermissionCache $permissionCache */ - $permissionCache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('JBartels\\BeAcl\\Cache\\PermissionCache'); + $permissionCache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(PermissionCache::class); $permissionCache->flushCache(); } - } diff --git a/Classes/Utility/ObjectSelection.php b/Classes/Utility/ObjectSelection.php index a50a68f..3778284 100644 --- a/Classes/Utility/ObjectSelection.php +++ b/Classes/Utility/ObjectSelection.php @@ -1,4 +1,5 @@ array( + $PA['items'] = [ + 0 => [ 0 => '', 1 => '', - ), - ); + ], + ]; $type = isset($PA['row']['type'][0]) ? $PA['row']['type'][0] : null; // Get users or groups - The function copies functionality of the method acl_objectSelector() // of ux_SC_mod_web_perm_index class as for non-admins it returns only: // 1) Users which are members of the groups of the current user. // 2) Groups that the current user is a member of. switch ($type) { - // In case users shall be returned case '0': $items = BackendUtility::getUserNames(); @@ -73,10 +70,10 @@ function select($PA, $fobj) } foreach ($items as $row) { - $PA['items'][] = array( + $PA['items'][] = [ 0 => $row['username'], 1 => $row['uid'], - ); + ]; } break; @@ -88,10 +85,10 @@ function select($PA, $fobj) } foreach ($items as $row) { - $PA['items'][] = array( + $PA['items'][] = [ 0 => $row['title'], 1 => $row['uid'], - ); + ]; } break; diff --git a/Classes/Utility/UserAuthGroup.php b/Classes/Utility/UserAuthGroup.php index 25697be..623647e 100644 --- a/Classes/Utility/UserAuthGroup.php +++ b/Classes/Utility/UserAuthGroup.php @@ -1,4 +1,5 @@ */ class UserAuthGroup { - /** * @var array */ @@ -62,15 +63,15 @@ public function __construct() * Returns a combined binary representation of the current users permissions for the page-record, $row. * The perms for user, group and everybody is OR'ed together (provided that the page-owner is the user and for the * groups that the user is a member of the group If the user is admin, 31 is returned (full permissions for all - * five flags) + * five flags). * - * @param array $params Input page row with all perms_* fields available. - * @param \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $that BE User Object - * @return integer Bitwise representation of the users permissions in relation to input page row, $row + * @param array $params input page row with all perms_* fields available + * @param \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $that BE User Object + * + * @return int Bitwise representation of the users permissions in relation to input page row, $row */ public function calcPerms($params, $that) { - $row = $params['row']; $beAclConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['be_acl']); @@ -84,25 +85,30 @@ public function calcPerms($params, $that) $i = 0; $takeUserIntoAccount = 1; - $groupIdsAlreadyUsed = Array(); + $groupIdsAlreadyUsed = []; foreach ($rootLine as $values) { - if ($i != 0) { + if (0 != $i) { $recursive = ' AND recursive=1'; } else { $recursive = ''; } - $res = $this->db->exec_SELECTquery('*', 'tx_beacl_acl', 'pid=' . intval($values['uid']) . $recursive, '', - 'recursive ASC'); + $res = $this->db->exec_SELECTquery( + '*', + 'tx_beacl_acl', + 'pid=' . intval($values['uid']) . $recursive, + '', + 'recursive ASC' + ); while ($result = $this->db->sql_fetch_assoc($res)) { - if ($result['type'] == 0 + if (0 == $result['type'] && ($that->user['uid'] == $result['object_id']) && $takeUserIntoAccount ) { // user has to be taken into account $out |= $result['permissions']; $takeUserIntoAccount = 0; - } elseif ($result['type'] == 1 + } elseif (1 == $result['type'] && $that->isMemberOfGroup($result['object_id']) && !in_array($result['object_id'], $groupIdsAlreadyUsed) ) { @@ -110,7 +116,7 @@ public function calcPerms($params, $that) $groupIdsAlreadyUsed[] = $result['object_id']; } } - $i++; + ++$i; } return $out; @@ -129,15 +135,15 @@ public function calcPerms($params, $that) * at all) The 95% use of this function is "->getPagePermsClause(1)" which will return WHERE clauses for * *selecting* pages in backend listings - in other words will this check read permissions. * - * @param integer $params Permission mask to use, see function description - * @param \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $that BE User Object + * @param int $params Permission mask to use, see function description + * @param \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $that BE User Object + * * @return string Part of where clause. Prefix " AND " to this. */ public function getPagePermsClause($params, $that) { - /** @var \JBartels\BeAcl\Cache\PermissionCache $permissionCache */ - $permissionCache = GeneralUtility::makeInstance('JBartels\\BeAcl\\Cache\\PermissionCache'); + $permissionCache = GeneralUtility::makeInstance(PermissionCache::class); $permissionCache->setBackendUser($that); $cachedPermissions = $permissionCache->getPermissionsClause($params['perms']); @@ -155,7 +161,7 @@ public function getPagePermsClause($params, $that) // get some basic variables $perms = $params['perms']; - $this->aclPageList = array(); + $this->aclPageList = []; // get allowed IDs for user $this->getPagePermsClause_single(0, $that->user['uid'], $perms); @@ -168,15 +174,16 @@ public function getPagePermsClause($params, $that) } } if (!empty($this->aclPageList)) { - // put all page IDs together to the final SQL string $str = '( ' . $str . ' ) OR ( pages.uid IN (' . implode(',', $this->aclPageList) . ') )'; // if the user is in a workspace, that has to be taken into account // see t3lib_BEfunc::getWorkspaceVersionOfRecord() for the source of this query if ($that->workspace) { - $str .= ' OR ( pages.t3ver_wsid=' . intval($that->workspace) . ' AND pages.t3ver_oid IN (' . implode(',', - $this->aclPageList) . ') )'; + $str .= ' OR ( pages.t3ver_wsid=' . intval($that->workspace) . ' AND pages.t3ver_oid IN (' . implode( + ',', + $this->aclPageList + ) . ') )'; } } @@ -190,23 +197,21 @@ public function getPagePermsClause($params, $that) } /** - * adds allowed pages to $this->aclPageList for a certain user/group + * adds allowed pages to $this->aclPageList for a certain user/group. * * most of the code found here was before in getPagePermsClause of be_acl * * @param $type int Type of the ACL record (0 - User, 1 - Group) * @param $object_id int ID of the group / user * @param $perms int permission mask to use - * @return void fills $this->aclPageList **/ protected function getPagePermsClause_single($type, $object_id, $perms) { - // reset aclDisallowed - $this->aclDisallowed = array(); + $this->aclDisallowed = []; // 1. fetch all ACLs relevant for the current user/group - $aclAllowed = Array(); + $aclAllowed = []; $where = ' ( (type = ' . intval($type) . ' AND object_id = ' . intval($object_id) . ')'; $whereAllow = ') AND (permissions & ' . $perms . ' = ' . $perms . ')'; @@ -223,7 +228,6 @@ protected function getPagePermsClause_single($type, $object_id, $perms) } if ($aclAllowed) { - // get all "deny" acls if there are allow ACLs $res = $this->db->exec_SELECTquery( 'pid, recursive', @@ -231,14 +235,13 @@ protected function getPagePermsClause_single($type, $object_id, $perms) $where . $whereDeny ); while ($result = $this->db->sql_fetch_assoc($res)) { - // only one ACL per group/user per page is allowed, that's why this line imposes no problem. It rather increases speed. $this->aclDisallowed[$result['pid']] = $result['recursive']; } // go through all allowed ACLs, if it is not recursive, add the page to the aclPageList, if recursive, call recursion function foreach ($aclAllowed as $singleAllow) { - if ($singleAllow['recursive'] == 0) { + if (0 == $singleAllow['recursive']) { $this->aclPageList[$singleAllow['pid']] = $singleAllow['pid']; } else { $this->aclTraversePageTree($singleAllow['pid']); @@ -248,20 +251,17 @@ protected function getPagePermsClause_single($type, $object_id, $perms) } /** - * traverses page tree and handles "disallow" ACLs + * traverses page tree and handles "disallow" ACLs. * * is a recursive function. * * @param int $pid Page ID where to start traversing the tree - * @return void fills $this->aclPageList **/ protected function aclTraversePageTree($pid) { - // if there is a disallow ACL for the current page, don't add the page to the aclPageList if (array_key_exists($pid, $this->aclDisallowed)) { - if ($this->aclDisallowed[$pid] == 1) { - + if (1 == $this->aclDisallowed[$pid]) { // if recursive, stop processing return; } diff --git a/Classes/View/BackendTemplateView.php b/Classes/View/BackendTemplateView.php index 450fe79..f2860c7 100644 --- a/Classes/View/BackendTemplateView.php +++ b/Classes/View/BackendTemplateView.php @@ -1,4 +1,5 @@ templateRootPathPattern - * @see \TYPO3\CMS\Fluid\View\TemplateView::setTemplateRootPaths() + * If set, overrides the one determined from $this->templateRootPathPattern. * - * @return void + * @see \TYPO3\CMS\Fluid\View\TemplateView::setTemplateRootPaths() */ public function setTemplateRootPaths(array $templateRootPaths) { @@ -55,6 +55,7 @@ public function setTemplateRootPaths(array $templateRootPaths) /** * Resolves the partial root to be used inside other paths. + * * @see \TYPO3\CMS\Fluid\View\TemplateView::getPartialRootPaths() * * @return array Path(s) to partial root directory @@ -66,14 +67,12 @@ protected function getPartialRootPaths() /** * Set the root path(s) to the partials. - * If set, overrides the one determined from $this->partialRootPathPattern - * @see \TYPO3\CMS\Fluid\View\TemplateView::setPartialRootPaths() + * If set, overrides the one determined from $this->partialRootPathPattern. * - * @return void + * @see \TYPO3\CMS\Fluid\View\TemplateView::setPartialRootPaths() */ public function setPartialRootPaths(array $partialRootPaths) { $this->templateView->setPartialRootPaths($partialRootPaths); } - } diff --git a/Classes/ViewHelpers/ArrayElementViewHelper.php b/Classes/ViewHelpers/ArrayElementViewHelper.php index ecfc1cb..601e5af 100644 --- a/Classes/ViewHelpers/ArrayElementViewHelper.php +++ b/Classes/ViewHelpers/ArrayElementViewHelper.php @@ -1,4 +1,5 @@ [ 'path' => '/users/access/permissions', - 'target' => \JBartels\BeAcl\Controller\PermissionAjaxController::class . '::dispatch' - ] + 'target' => \JBartels\BeAcl\Controller\PermissionAjaxController::class . '::dispatch', + ], ]; diff --git a/Configuration/TCA/tx_beacl_acl.php b/Configuration/TCA/tx_beacl_acl.php index 5dab838..e454b19 100644 --- a/Configuration/TCA/tx_beacl_acl.php +++ b/Configuration/TCA/tx_beacl_acl.php @@ -1,82 +1,81 @@ Array( - "title" => "LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl", - "label" => "uid", - "tstamp" => "tstamp", - "crdate" => "crdate", - "cruser_id" => "cruser_id", - "type" => "type", - "default_sortby" => "ORDER BY type", - "iconfile" => "EXT:be_acl/Resources/Public/Icons/icon_tx_beacl_acl.gif", - ), - "feInterface" => array( - "fe_admin_fieldList" => "type, object_id, permissions, recursive", - ), - 'interface' => Array ( - 'showRecordFieldList' => 'type,object_id,permissions,recursive' - ), - 'columns' => Array ( - 'type' => Array ( - 'exclude' => 1, - 'label' => 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.type', - 'config' => Array ( - 'type' => 'select', - 'renderType' => 'selectSingle', - 'items' => Array ( - Array('LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.type.I.0', '0'), - Array('LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.type.I.1', '1'), - ), - 'size' => 1, - 'maxitems' => 1, - ) - ), - 'object_id' => Array ( - 'exclude' => 1, - 'label' => 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.object_id', - 'config' => Array ( - 'type' => 'select', - 'renderType' => 'selectSingle', - 'itemsProcFunc' => 'JBartels\BeAcl\Utility\ObjectSelection->select', - 'size' => 1, - 'minitems' => 0, - 'maxitems' => 1, - ) - ), - 'permissions' => Array ( - 'exclude' => 1, - 'label' => 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions', - 'config' => Array ( - 'type' => 'check', - 'cols' => 5, - 'items' => Array ( - Array('LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.0', ''), - Array('LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.1', ''), - Array('LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.2', ''), - Array('LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.3', ''), - Array('LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.4', ''), - ), - ) - ), - 'recursive' => Array ( - 'exclude' => 1, - 'label' => 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.recursive', - 'config' => Array ( - 'type' => 'check' - ) - ), - ), - 'types' => Array ( - '0' => Array('showitem' => 'type, object_id, permissions, recursive'), - '1' => Array('showitem' => 'type, object_id, permissions, recursive') - ), - 'palettes' => Array ( - '1' => Array('showitem' => '') - ) -); +if (!defined('TYPO3_MODE')) { + die('Access denied.'); +} -?> +return [ + 'ctrl' => [ + 'title' => 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl', + 'label' => 'uid', + 'tstamp' => 'tstamp', + 'crdate' => 'crdate', + 'cruser_id' => 'cruser_id', + 'type' => 'type', + 'default_sortby' => 'ORDER BY type', + 'iconfile' => 'EXT:be_acl/Resources/Public/Icons/icon_tx_beacl_acl.gif', + ], + 'feInterface' => [ + 'fe_admin_fieldList' => 'type, object_id, permissions, recursive', + ], + 'interface' => [ + 'showRecordFieldList' => 'type,object_id,permissions,recursive', + ], + 'columns' => [ + 'type' => [ + 'exclude' => 1, + 'label' => 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.type', + 'config' => [ + 'type' => 'select', + 'renderType' => 'selectSingle', + 'items' => [ + ['LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.type.I.0', '0'], + ['LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.type.I.1', '1'], + ], + 'size' => 1, + 'maxitems' => 1, + ], + ], + 'object_id' => [ + 'exclude' => 1, + 'label' => 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.object_id', + 'config' => [ + 'type' => 'select', + 'renderType' => 'selectSingle', + 'itemsProcFunc' => 'JBartels\BeAcl\Utility\ObjectSelection->select', + 'size' => 1, + 'minitems' => 0, + 'maxitems' => 1, + ], + ], + 'permissions' => [ + 'exclude' => 1, + 'label' => 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions', + 'config' => [ + 'type' => 'check', + 'cols' => 5, + 'items' => [ + ['LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.0', ''], + ['LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.1', ''], + ['LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.2', ''], + ['LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.3', ''], + ['LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.permissions.I.4', ''], + ], + ], + ], + 'recursive' => [ + 'exclude' => 1, + 'label' => 'LLL:EXT:be_acl/Resources/Private/Languages/locallang_db.xlf:tx_beacl_acl.recursive', + 'config' => [ + 'type' => 'check', + ], + ], + ], + 'types' => [ + '0' => ['showitem' => 'type, object_id, permissions, recursive'], + '1' => ['showitem' => 'type, object_id, permissions, recursive'], + ], + 'palettes' => [ + '1' => ['showitem' => ''], + ], +]; diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt index 41e2e5c..4dc6a81 100644 --- a/Configuration/TypoScript/setup.txt +++ b/Configuration/TypoScript/setup.txt @@ -1,10 +1,11 @@ module.tx_beuser { - view.templateRootPaths { - 10 = EXT:beuser/Resources/Private/Templates/ - 20 = EXT:be_acl/Resources/Private/Templates/ - } - view.partialRootPaths { - 10 = EXT:beuser/Resources/Private/Partials/ - 20 = EXT:be_acl/Resources/Private/Partials/ - } -} \ No newline at end of file + view.templateRootPaths { + 10 = EXT:beuser/Resources/Private/Templates/ + 20 = EXT:be_acl/Resources/Private/Templates/ + } + + view.partialRootPaths { + 10 = EXT:beuser/Resources/Private/Partials/ + 20 = EXT:be_acl/Resources/Private/Partials/ + } +} diff --git a/Tests/Unit/Cache/PermissionCacheTest.php b/Tests/Unit/Cache/PermissionCacheTest.php index 2604f62..101c20e 100644 --- a/Tests/Unit/Cache/PermissionCacheTest.php +++ b/Tests/Unit/Cache/PermissionCacheTest.php @@ -1,4 +1,5 @@ backendUser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication'); - } - - /** - * @test - */ - public function flushingCacheInvalidatesPreviouslySetFirstLevelCache() { - $this->initializePermissionCacheMock(array('initializeRequiredClasses')); - - /** @var \JBartels\BeAcl\Cache\TimestampUtility|\PHPUnit_Framework_MockObject_MockObject $timestampUtility */ - $timestampUtility = $this->getMock('JBartels\\BeAcl\\Cache\\TimestampUtility', array('updateTimestamp', 'permissionTimestampIsValid')); - $timestampUtility->expects($this->once())->method('updateTimestamp'); - $timestampUtility->expects($this->once())->method('permissionTimestampIsValid')->will($this->returnValue(FALSE)); - $this->permissionCache->setTimestampUtility($timestampUtility); - - $this->permissionCache->setPermissionsClause($this->permissionsClauseCacheKey, $this->permissionsClauseCacheValue); - $this->permissionCache->flushCache(); - $cachedValue = $this->permissionCache->getPermissionsClause($this->permissionsClauseCacheKey); - $this->assertNull($cachedValue); - } - - /** - * @test - */ - public function flushingCacheInvalidatesPreviouslySetSecondLevelCache() { - - $this->initializePermissionCacheMock(array('initializeRequiredClasses')); - $this->permissionCache->disableFirstLevelCache(); - - /** @var \JBartels\BeAcl\Cache\TimestampUtility|\PHPUnit_Framework_MockObject_MockObject $timestampUtility */ - $timestampUtility = $this->getMock('JBartels\\BeAcl\\Cache\\TimestampUtility', array('updateTimestamp', 'permissionTimestampIsValid')); - $timestampUtility->expects($this->once())->method('updateTimestamp'); - $timestampUtility->expects($this->once())->method('permissionTimestampIsValid')->will($this->returnValue(FALSE)); - $this->permissionCache->setTimestampUtility($timestampUtility); - - $this->permissionCache->setPermissionsClause($this->permissionsClauseCacheKey, $this->permissionsClauseCacheValue); - $this->permissionCache->flushCache(); - $cachedValue = $this->permissionCache->getPermissionsClause($this->permissionsClauseCacheKey); - $this->assertNull($cachedValue); - } - - /** - * @test - */ - public function previouslySetCacheValueIsReturnedByFirstLevelCache() { - $this->initializePermissionCacheMock(array('initializeRequiredClasses')); - $this->permissionCache->setPermissionsClause($this->permissionsClauseCacheKey, $this->permissionsClauseCacheValue); - $cachedValue = $this->permissionCache->getPermissionsClause($this->permissionsClauseCacheKey); - $this->assertEquals($this->permissionsClauseCacheValue, $cachedValue); - } - - /** - * @test - */ - public function previouslySetCacheValueIsReturnedBySecondLevelCache() { - - $this->initializePermissionCacheMock(array('initializeRequiredClasses')); - - /** @var \JBartels\BeAcl\Cache\TimestampUtility|\PHPUnit_Framework_MockObject_MockObject $timestampUtility */ - $timestampUtility = $this->getMock('JBartels\\BeAcl\\Cache\\TimestampUtility', array('permissionTimestampIsValid')); - $timestampUtility->expects($this->once())->method('permissionTimestampIsValid')->will($this->returnValue(TRUE)); - $this->permissionCache->setTimestampUtility($timestampUtility); - - $this->permissionCache->disableFirstLevelCache(); - $this->permissionCache->setPermissionsClause($this->permissionsClauseCacheKey, $this->permissionsClauseCacheValue); - $cachedValue = $this->permissionCache->getPermissionsClause($this->permissionsClauseCacheKey); - $this->assertEquals($this->permissionsClauseCacheValue, $cachedValue); - } - - /** - * @param array $mockedMethods - */ - protected function initializePermissionCacheMock($mockedMethods) { - - /** @var \JBartels\BeAcl\Cache\PermissionCache $permissionCache */ - $permissionCache = $this->getMock('JBartels\\BeAcl\\Cache\\PermissionCache', $mockedMethods); - $permissionCache->setBackendUser($this->backendUser); - - $cacheBackend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing'); - $cacheFrontend = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('tx_be_acl_permissions', $cacheBackend); - - $permissionCache->setPermissionCache($cacheFrontend); - - $this->permissionCache = $permissionCache; - } -} \ No newline at end of file +class PermissionCacheTest extends UnitTestCase +{ + /** + * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication + */ + protected $backendUser; + + /** + * @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $cacheMock; + + /** + * @var \JBartels\BeAcl\Cache\PermissionCache|\PHPUnit_Framework_MockObject_MockObject + */ + protected $permissionCache; + + /** + * The key used for the test cache entry. + * + * @var string + */ + protected $permissionsClauseCacheKey = 'testCachekey'; + + /** + * The value used for the test cache entry. + * + * @var string + */ + protected $permissionsClauseCacheValue = 'testCacheValue'; + + /** + * Initializes the permission cache. + */ + public function setUp() + { + /* @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUser */ + $this->backendUser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(BackendUserAuthentication::class); + } + + /** + * @test + */ + public function flushingCacheInvalidatesPreviouslySetFirstLevelCache() + { + $this->initializePermissionCacheMock(['initializeRequiredClasses']); + + /** @var \JBartels\BeAcl\Cache\TimestampUtility|\PHPUnit_Framework_MockObject_MockObject $timestampUtility */ + $timestampUtility = $this->getMock(TimestampUtility::class, ['updateTimestamp', 'permissionTimestampIsValid']); + $timestampUtility->expects($this->once())->method('updateTimestamp'); + $timestampUtility->expects($this->once())->method('permissionTimestampIsValid')->will($this->returnValue(false)); + $this->permissionCache->setTimestampUtility($timestampUtility); + + $this->permissionCache->setPermissionsClause($this->permissionsClauseCacheKey, $this->permissionsClauseCacheValue); + $this->permissionCache->flushCache(); + $cachedValue = $this->permissionCache->getPermissionsClause($this->permissionsClauseCacheKey); + $this->assertNull($cachedValue); + } + + /** + * @test + */ + public function flushingCacheInvalidatesPreviouslySetSecondLevelCache() + { + $this->initializePermissionCacheMock(['initializeRequiredClasses']); + $this->permissionCache->disableFirstLevelCache(); + + /** @var \JBartels\BeAcl\Cache\TimestampUtility|\PHPUnit_Framework_MockObject_MockObject $timestampUtility */ + $timestampUtility = $this->getMock(TimestampUtility::class, ['updateTimestamp', 'permissionTimestampIsValid']); + $timestampUtility->expects($this->once())->method('updateTimestamp'); + $timestampUtility->expects($this->once())->method('permissionTimestampIsValid')->will($this->returnValue(false)); + $this->permissionCache->setTimestampUtility($timestampUtility); + + $this->permissionCache->setPermissionsClause($this->permissionsClauseCacheKey, $this->permissionsClauseCacheValue); + $this->permissionCache->flushCache(); + $cachedValue = $this->permissionCache->getPermissionsClause($this->permissionsClauseCacheKey); + $this->assertNull($cachedValue); + } + + /** + * @test + */ + public function previouslySetCacheValueIsReturnedByFirstLevelCache() + { + $this->initializePermissionCacheMock(['initializeRequiredClasses']); + $this->permissionCache->setPermissionsClause($this->permissionsClauseCacheKey, $this->permissionsClauseCacheValue); + $cachedValue = $this->permissionCache->getPermissionsClause($this->permissionsClauseCacheKey); + $this->assertEquals($this->permissionsClauseCacheValue, $cachedValue); + } + + /** + * @test + */ + public function previouslySetCacheValueIsReturnedBySecondLevelCache() + { + $this->initializePermissionCacheMock(['initializeRequiredClasses']); + + /** @var \JBartels\BeAcl\Cache\TimestampUtility|\PHPUnit_Framework_MockObject_MockObject $timestampUtility */ + $timestampUtility = $this->getMock(TimestampUtility::class, ['permissionTimestampIsValid']); + $timestampUtility->expects($this->once())->method('permissionTimestampIsValid')->will($this->returnValue(true)); + $this->permissionCache->setTimestampUtility($timestampUtility); + + $this->permissionCache->disableFirstLevelCache(); + $this->permissionCache->setPermissionsClause($this->permissionsClauseCacheKey, $this->permissionsClauseCacheValue); + $cachedValue = $this->permissionCache->getPermissionsClause($this->permissionsClauseCacheKey); + $this->assertEquals($this->permissionsClauseCacheValue, $cachedValue); + } + + /** + * @param array $mockedMethods + */ + protected function initializePermissionCacheMock($mockedMethods) + { + /** @var \JBartels\BeAcl\Cache\PermissionCache $permissionCache */ + $permissionCache = $this->getMock(PermissionCache::class, $mockedMethods); + $permissionCache->setBackendUser($this->backendUser); + + $cacheBackend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing'); + $cacheFrontend = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('tx_be_acl_permissions', $cacheBackend); + + $permissionCache->setPermissionCache($cacheFrontend); + + $this->permissionCache = $permissionCache; + } +} diff --git a/Tests/Unit/Cache/TimestampUtilityTest.php b/Tests/Unit/Cache/TimestampUtilityTest.php index 02bef36..3c25a85 100644 --- a/Tests/Unit/Cache/TimestampUtilityTest.php +++ b/Tests/Unit/Cache/TimestampUtilityTest.php @@ -1,4 +1,5 @@ timestampUtility = $this->getMock('JBartels\\BeAcl\\Cache\\TimestampUtility', array('initializeCache')); - $this->initializeTimestampCache(); - } + /** + * Initializes the timestamp utility. + */ + public function setUp() + { + $this->timestampUtility = $this->getMock(TimestampUtility::class, ['initializeCache']); + $this->initializeTimestampCache(); + } - /** - * @test - */ - public function newerTimestampThanInCacheIsInvalid() { - $this->timestampUtility->updateTimestamp(); - $isValid = $this->timestampUtility->permissionTimestampIsValid(time() + 100); - $this->assertTrue($isValid); - } + /** + * @test + */ + public function newerTimestampThanInCacheIsInvalid() + { + $this->timestampUtility->updateTimestamp(); + $isValid = $this->timestampUtility->permissionTimestampIsValid(time() + 100); + $this->assertTrue($isValid); + } - /** - * @test - */ - public function olderTimestampThanInCacheIsInvalid() { - $this->timestampUtility->updateTimestamp(); - $isValid = $this->timestampUtility->permissionTimestampIsValid(time() - 100); - $this->assertFalse($isValid); - } + /** + * @test + */ + public function olderTimestampThanInCacheIsInvalid() + { + $this->timestampUtility->updateTimestamp(); + $isValid = $this->timestampUtility->permissionTimestampIsValid(time() - 100); + $this->assertFalse($isValid); + } - /** - * Initializes the cache mock in the timestamp utility. - */ - protected function initializeTimestampCache() { - /** @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cacheMock */ - $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE); - $this->timestampUtility->setTimestampCache($cacheMock); - } -} \ No newline at end of file + /** + * Initializes the cache mock in the timestamp utility. + */ + protected function initializeTimestampCache() + { + /** @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cacheMock */ + $cacheMock = $this->getMock(FrontendInterface::class, [], [], '', false); + $this->timestampUtility->setTimestampCache($cacheMock); + } +} diff --git a/ext_emconf.php b/ext_emconf.php index 065cbca..a615c93 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -10,32 +10,30 @@ * writing. "version" and "dependencies" must not be touched! ***************************************************************/ -$EM_CONF[$_EXTKEY] = array( - 'title' => 'Backend ACLs', - 'description' => 'Backend Access Control Lists', - 'category' => 'be', - 'version' => '1.7.3', - 'state' => 'stable', - 'uploadfolder' => 0, - 'createDirs' => '', - 'modify_tables' => '', - 'clearcacheonload' => 0, - 'lockType' => '', - 'author' => 'Sebastian Kurfuerst', - 'author_email' => 'sebastian@garbage-group.de', - 'author_company' => '', - 'CGLcompliance' => '', - 'CGLcompliance_note' => '', - 'constraints' => array( - 'depends' => array( - 'php' => '5.5.0-7.1.99', - 'typo3' => '7.6.0-8.9.99', - ), - 'conflicts' => array( - ), - 'suggests' => array( - ), - ), -); - -?> +$EM_CONF[$_EXTKEY] = [ + 'title' => 'Backend ACLs', + 'description' => 'Backend Access Control Lists', + 'category' => 'be', + 'version' => '1.7.3', + 'state' => 'stable', + 'uploadfolder' => 0, + 'createDirs' => '', + 'modify_tables' => '', + 'clearcacheonload' => 0, + 'lockType' => '', + 'author' => 'Sebastian Kurfuerst', + 'author_email' => 'sebastian@garbage-group.de', + 'author_company' => '', + 'CGLcompliance' => '', + 'CGLcompliance_note' => '', + 'constraints' => [ + 'depends' => [ + 'php' => '5.5.0-7.2.99', + 'typo3' => '7.6.0-8.9.99', + ], + 'conflicts' => [ + ], + 'suggests' => [ + ], + ], +]; diff --git a/ext_localconf.php b/ext_localconf.php index a40395a..dc2df0f 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,53 +1,54 @@ -calcPerms'; -$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['getPagePermsClause'][] = 'JBartels\\BeAcl\\Utility\\UserAuthGroup->getPagePermsClause'; - -$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Beuser\\Controller\\PermissionController'] = array( - 'className' => 'JBartels\\BeAcl\\Controller\\PermissionController', -); - -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'JBartels\\BeAcl\\Hook\\DataHandlerHook'; -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] = 'JBartels\\BeAcl\\Hook\\DataHandlerHook'; - - -$redisLoaded = extension_loaded('redis'); - -// set tx_be_acl_timestamp-cache -if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['frontend'])) { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['frontend'] = 'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend'; -} -if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['backend'])) { - if ( $redisLoaded ) - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\RedisBackend'; - else - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\SimpleFileBackend'; -} - -// set tx_be_acl_permissions-cache -if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['frontend'])) { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['frontend'] = 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend'; -} -if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['backend'])) { - if ( $redisLoaded ) - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\RedisBackend'; - else - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\SimpleFileBackend'; -} - -$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class); -$iconRegistry->registerIcon( - 'tx_beacl-object-info', - \TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider::class, - [ - 'name' => 'info' - ] -); \ No newline at end of file +calcPerms'; +$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['getPagePermsClause'][] = 'JBartels\\BeAcl\\Utility\\UserAuthGroup->getPagePermsClause'; + +$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Beuser\\Controller\\PermissionController'] = [ + 'className' => \JBartels\BeAcl\Controller\PermissionController::class, +]; + +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = \JBartels\BeAcl\Hook\DataHandlerHook::class; +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] = \JBartels\BeAcl\Hook\DataHandlerHook::class; + +$redisLoaded = extension_loaded('redis'); + +// set tx_be_acl_timestamp-cache +if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['frontend'])) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['frontend'] = \TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class; +} +if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['backend'])) { + if ($redisLoaded) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['backend'] = \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class; + } else { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_timestamp']['backend'] = \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class; + } +} + +// set tx_be_acl_permissions-cache +if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['frontend'])) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['frontend'] = \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class; +} +if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['backend'])) { + if ($redisLoaded) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['backend'] = \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class; + } else { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_be_acl_permissions']['backend'] = \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class; + } +} + +$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class); +$iconRegistry->registerIcon( + 'tx_beacl-object-info', + \TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider::class, + [ + 'name' => 'info', + ] +); diff --git a/ext_tables.php b/ext_tables.php index e3688c6..ede0d65 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -1,6 +1,7 @@ -