Commit 6397490c authored by Benni Mack's avatar Benni Mack Committed by Susanne Moog
Browse files

[BUGFIX] Re-enable caching and centralize UserTSconfig in BE_USER

In order to continue sorting out various places when UserTSconfig
should be used, and how to properly use caching and condition
matching, compiling of UserTSconfig is now centralized into one method.

In addition, this patch actually now caches the UserTSconfig
again, in the "hash" cache, which wasn't the case before in v10.0+.

Resolves: #89755
Releases: master
Change-Id: Icf6e8d7a199fb234336b4bd557627d254ff4e6e3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62419


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
parent fe520c3f
......@@ -34,6 +34,7 @@ use TYPO3\CMS\Core\SysLog\Type as SystemLogType;
use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException;
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Service\SessionService;
......@@ -131,16 +132,6 @@ class BackendUserAuthentication extends AbstractUserAuthentication
*/
public $includeGroupArray = [];
/**
* @var array Accumulated, unparsed TSconfig data array of the user
*/
protected $TSdataArray = [];
/**
* @var string Accumulated, unparsed TSconfig data string of the user
*/
protected $userTS_text = '';
/**
* @var array Parsed user TSconfig
*/
......@@ -1327,19 +1318,7 @@ class BackendUserAuthentication extends AbstractUserAuthentication
$this->dataLists['filemount_list'] = $this->user['file_mountpoints'];
// Fileoperation permissions
$this->dataLists['file_permissions'] = $this->user['file_permissions'];
// Setting default User TSconfig:
$this->TSdataArray[] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'];
// Default TSconfig for admin-users
if ($this->isAdmin()) {
$this->TSdataArray[] = 'admPanel.enable.all = 1';
if (ExtensionManagementUtility::isLoaded('sys_note')) {
$this->TSdataArray[] = '
// Setting defaults for sys_note author / email...
TCAdefaults.sys_note.author = ' . $this->user['realName'] . '
TCAdefaults.sys_note.email = ' . $this->user['email'] . '
';
}
}
// BE_GROUPS:
// Get the groups...
if (!empty($this->user[$this->usergroup_column])) {
......@@ -1356,21 +1335,8 @@ class BackendUserAuthentication extends AbstractUserAuthentication
$this->groupList = implode(',', $this->userGroupsUID);
$this->setCachedList($this->groupList);
// Add the TSconfig for this specific user:
$this->TSdataArray[] = $this->user['TSconfig'];
// Check include lines.
$this->TSdataArray = \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines_array($this->TSdataArray);
// Imploding with "[global]" will make sure that non-ended confinements with braces are ignored.
$this->userTS_text = implode(LF . '[GLOBAL]' . LF, $this->TSdataArray);
// Parsing the user TSconfig (or getting from cache)
$hash = md5('userTS:' . $this->userTS_text);
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('hash');
$parseObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
$parseObj->parse($this->userTS_text);
$this->userTS = $parseObj->setup;
$cache->set($hash, $this->userTS, ['ident_BE_USER_TSconfig'], 0);
// Update UC:
$this->userTSUpdated = true;
$this->prepareUserTsConfig();
// Processing webmounts
// Admin's always have the root mounted
if ($this->isAdmin() && !($this->getTSConfig()['options.']['dontMountAdminMounts'] ?? false)) {
......@@ -1428,6 +1394,47 @@ class BackendUserAuthentication extends AbstractUserAuthentication
}
}
/**
* This method parses the UserTSconfig from the current user and all their groups.
* If the contents are the same, parsing is skipped. No matching is applied here currently.
*/
protected function prepareUserTsConfig(): void
{
$collectedUserTSconfig = [
'default' => $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig']
];
// Default TSconfig for admin-users
if ($this->isAdmin()) {
$collectedUserTSconfig[] = 'admPanel.enable.all = 1';
}
// Setting defaults for sys_note author / email
$collectedUserTSconfig[] = '
TCAdefaults.sys_note.author = ' . $this->user['realName'] . '
TCAdefaults.sys_note.email = ' . $this->user['email'];
// Loop through all groups and add their 'TSconfig' fields
foreach ($this->includeGroupArray as $groupId) {
$collectedUserTSconfig['group_' . $groupId] = $this->userGroups[$groupId]['TSconfig'] ?? '';
}
$collectedUserTSconfig[] = $this->user['TSconfig'];
// Check external files
$collectedUserTSconfig = TypoScriptParser::checkIncludeLines_array($collectedUserTSconfig);
// Imploding with "[global]" will make sure that non-ended confinements with braces are ignored.
$userTS_text = implode("\n[GLOBAL]\n", $collectedUserTSconfig);
// Parsing the user TSconfig (or getting from cache)
$hash = md5('userTS:' . $userTS_text);
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('hash');
if (!($this->userTS = $cache->get($hash))) {
$parseObj = GeneralUtility::makeInstance(TypoScriptParser::class);
$parseObj->parse($userTS_text);
$this->userTS = $parseObj->setup;
$cache->set($hash, $this->userTS, ['UserTSconfig'], 0);
// Ensure to update UC later
$this->userTSUpdated = true;
}
}
/**
* Fetches the group records, subgroups and fills internal arrays.
* Function is called recursively to fetch subgroups
......@@ -1490,9 +1497,8 @@ class BackendUserAuthentication extends AbstractUserAuthentication
// Call recursively, pass along list of already processed groups so they are not recursed again.
$this->fetchGroups($theList, $idList . ',' . $uid);
}
// Add the group uid, current list, TSconfig to the internal arrays.
// Add the group uid, current list to the internal arrays.
$this->includeGroupArray[] = $uid;
$this->TSdataArray[] = $row['TSconfig'];
// Mount group database-mounts
if (($this->user['options'] & Permission::PAGE_SHOW) == 1) {
$this->dataLists['webmount_list'] .= ',' . $row['db_mountpoints'];
......
......@@ -1048,7 +1048,7 @@ The following class properties have changed visibility:
* :php:`TYPO3\CMS\Core\Authentication\BackendUserAuthentication->TSdataArray` changed from public to protected
* :php:`TYPO3\CMS\Core\Authentication\BackendUserAuthentication->userTS` changed from public to protected
* :php:`TYPO3\CMS\Core\Authentication\BackendUserAuthentication->userTSUpdated` changed from public to protected
* :php:`TYPO3\CMS\Core\Authentication\BackendUserAuthentication->userTS_text` changed from public to protected
* :php:`TYPO3\CMS\Core\Authentication\BackendUserAuthentication->userTS_text` has been removed
* :php:`TYPO3\CMS\Core\Charset\CharsetConverter->eucBasedSets` changed from public to protected
* :php:`TYPO3\CMS\Core\Charset\CharsetConverter->noCharByteVal` changed from public to protected
* :php:`TYPO3\CMS\Core\Charset\CharsetConverter->parsedCharsets` changed from public to protected
......
......@@ -72,4 +72,22 @@ class BackendUserAuthenticationTest extends FunctionalTestCase
$result = $this->subject->isInWebMount(2);
self::assertNotNull($result);
}
/**
* @test
*/
public function userTsConfigIsResolvedProperlyWithPrioritization(): void
{
$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUserTSconfig'] = "custom.generic = installation-wide-configuration\ncustom.property = from configuration";
$this->subject->user['realName'] = 'Test user';
$this->subject->user['TSconfig'] = 'custom.property = from user';
$this->subject->includeGroupArray[] = 13;
$this->subject->userGroups[13]['TSconfig'] = "custom.property = from group\ncustom.groupProperty = 13";
$this->subject->fetchGroupData();
$result = $this->subject->getTSConfig();
self::assertEquals($this->subject->user['realName'], $result['TCAdefaults.']['sys_note.']['author']);
self::assertEquals('from user', $result['custom.']['property']);
self::assertEquals('13', $result['custom.']['groupProperty']);
self::assertEquals('installation-wide-configuration', $result['custom.']['generic']);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment