From 728a20a755fe9b3c281f772ed76ae31d87e637db Mon Sep 17 00:00:00 2001 From: Oliver Bartsch <bo@cedev.de> Date: Mon, 11 Jul 2022 17:03:08 +0200 Subject: [PATCH] [TASK] Centralize user debug information display condition A couple of debug information, e.g. the field- and tablenames in FormEngine, are displayed depending on the user status and the debug settings. To simplify the codebase, this condition is now centralized in BackendUserAuthentication. Resolves: #97894 Releases: main, 11.5 Change-Id: I5173c48180fbf96f7408c008eeb3c71c25686d0d Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75102 Tested-by: core-ci <typo3@b13.com> Tested-by: Jochen <rothjochen@gmail.com> Tested-by: Oliver Hader <oliver.hader@typo3.org> Reviewed-by: Jochen <rothjochen@gmail.com> Reviewed-by: Oliver Hader <oliver.hader@typo3.org> --- .../Form/Container/FlexFormElementContainer.php | 2 +- .../Classes/Form/Container/InlineRecordContainer.php | 3 +-- .../Classes/Form/Container/OuterWrapContainer.php | 2 +- .../Form/Container/PaletteAndSingleContainer.php | 2 +- .../Classes/Form/Element/AbstractFormElement.php | 2 +- .../Classes/Preview/StandardContentPreviewRenderer.php | 2 +- typo3/sysext/backend/Classes/View/PageLayoutView.php | 2 +- .../Form/Container/PaletteAndSingleContainerTest.php | 3 +++ .../Authentication/BackendUserAuthentication.php | 10 ++++++++++ .../Resource/Service/UserFileInlineLabelService.php | 2 +- .../lowlevel/Classes/Database/QueryGenerator.php | 3 +-- .../Classes/Controller/RecyclerAjaxController.php | 2 +- 12 files changed, 23 insertions(+), 12 deletions(-) diff --git a/typo3/sysext/backend/Classes/Form/Container/FlexFormElementContainer.php b/typo3/sysext/backend/Classes/Form/Container/FlexFormElementContainer.php index f2cc890ad766..5835c0e91b03 100644 --- a/typo3/sysext/backend/Classes/Form/Container/FlexFormElementContainer.php +++ b/typo3/sysext/backend/Classes/Form/Container/FlexFormElementContainer.php @@ -45,7 +45,7 @@ class FlexFormElementContainer extends AbstractContainer $languageService = $this->getLanguageService(); $resultArray = $this->initializeResultArray(); - $showFieldName = $GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->getBackendUserAuthentication()->isAdmin(); + $showFieldName = $this->getBackendUserAuthentication()->shallDisplayDebugInformation(); foreach ($flexFormDataStructureArray as $flexFormFieldName => $flexFormFieldArray) { if ( diff --git a/typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php b/typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php index 9033c59b6908..0e2e61461939 100644 --- a/typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php +++ b/typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php @@ -348,8 +348,7 @@ class InlineRecordContainer extends AbstractContainer // In case the record title is not generated by a formattedLabel_userFunc, which already // contains custom markup, and we are in debug mode, add the inline record table name. if (empty($data['processedTca']['ctrl']['formattedLabel_userFunc']) - && ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] ?? false) - && $this->getBackendUserAuthentication()->isAdmin() + && $this->getBackendUserAuthentication()->shallDisplayDebugInformation() ) { $recordTitle .= ' <code class="m-0">[' . htmlspecialchars($foreignTable) . ']</code>'; } diff --git a/typo3/sysext/backend/Classes/Form/Container/OuterWrapContainer.php b/typo3/sysext/backend/Classes/Form/Container/OuterWrapContainer.php index b854486cba3a..7d6541e9338e 100644 --- a/typo3/sysext/backend/Classes/Form/Container/OuterWrapContainer.php +++ b/typo3/sysext/backend/Classes/Form/Container/OuterWrapContainer.php @@ -146,7 +146,7 @@ class OuterWrapContainer extends AbstractContainer 'fieldWizardHtml' => $fieldWizardHtml, 'childHtml' => $childHtml, 'icon' => $icon, - 'tableName' => ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] ?? false) && $backendUser->isAdmin() ? $table : '', + 'tableName' => $backendUser->shallDisplayDebugInformation() ? $table : '', 'tableTitle' => $tableTitle, 'newOrUid' => $newOrUid, 'isNewRecord' => $this->data['command'] === 'new', diff --git a/typo3/sysext/backend/Classes/Form/Container/PaletteAndSingleContainer.php b/typo3/sysext/backend/Classes/Form/Container/PaletteAndSingleContainer.php index f41787c82753..8f671fbfb4bf 100644 --- a/typo3/sysext/backend/Classes/Form/Container/PaletteAndSingleContainer.php +++ b/typo3/sysext/backend/Classes/Form/Container/PaletteAndSingleContainer.php @@ -394,7 +394,7 @@ class PaletteAndSingleContainer extends AbstractContainer $label = htmlspecialchars($element['fieldLabel']); - if ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->getBackendUser()->isAdmin()) { + if ($this->getBackendUser()->shallDisplayDebugInformation()) { $label .= '<code>[' . htmlspecialchars($fieldName) . ']</code>'; } diff --git a/typo3/sysext/backend/Classes/Form/Element/AbstractFormElement.php b/typo3/sysext/backend/Classes/Form/Element/AbstractFormElement.php index 4e84056b71d8..0f47c8193952 100644 --- a/typo3/sysext/backend/Classes/Form/Element/AbstractFormElement.php +++ b/typo3/sysext/backend/Classes/Form/Element/AbstractFormElement.php @@ -445,7 +445,7 @@ abstract class AbstractFormElement extends AbstractNode */ protected function appendValueToLabelInDebugMode($label, $value): string { - if ($value !== '' && $GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->getBackendUser()->isAdmin()) { + if ($value !== '' && $this->getBackendUser()->shallDisplayDebugInformation()) { return $label . ' [' . $value . ']'; } diff --git a/typo3/sysext/backend/Classes/Preview/StandardContentPreviewRenderer.php b/typo3/sysext/backend/Classes/Preview/StandardContentPreviewRenderer.php index 0a94e1acd1cc..f13bed96d5da 100644 --- a/typo3/sysext/backend/Classes/Preview/StandardContentPreviewRenderer.php +++ b/typo3/sysext/backend/Classes/Preview/StandardContentPreviewRenderer.php @@ -316,7 +316,7 @@ class StandardContentPreviewRenderer implements PreviewRendererInterface, Logger 'exception' => $e, ]); - if ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->getBackendUser()->isAdmin()) { + if ($this->getBackendUser()->shallDisplayDebugInformation()) { $view = GeneralUtility::makeInstance(StandaloneView::class); $view->assign('error', [ 'message' => str_replace(Environment::getProjectPath(), '', $e->getMessage()), diff --git a/typo3/sysext/backend/Classes/View/PageLayoutView.php b/typo3/sysext/backend/Classes/View/PageLayoutView.php index f530e2232dac..55e533671407 100644 --- a/typo3/sysext/backend/Classes/View/PageLayoutView.php +++ b/typo3/sysext/backend/Classes/View/PageLayoutView.php @@ -1177,7 +1177,7 @@ class PageLayoutView implements LoggerAwareInterface $e->getMessage(), ]); - if ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->getBackendUser()->isAdmin()) { + if ($this->getBackendUser()->shallDisplayDebugInformation()) { $view = GeneralUtility::makeInstance(StandaloneView::class); $view->assign('error', [ 'message' => str_replace(Environment::getProjectPath(), '', $e->getMessage()), diff --git a/typo3/sysext/backend/Tests/Unit/Form/Container/PaletteAndSingleContainerTest.php b/typo3/sysext/backend/Tests/Unit/Form/Container/PaletteAndSingleContainerTest.php index f4f616a1b5d1..5ff2792bceb0 100644 --- a/typo3/sysext/backend/Tests/Unit/Form/Container/PaletteAndSingleContainerTest.php +++ b/typo3/sysext/backend/Tests/Unit/Form/Container/PaletteAndSingleContainerTest.php @@ -73,6 +73,7 @@ class PaletteAndSingleContainerTest extends UnitTestCase $languageService = $this->prophesize(LanguageService::class); $GLOBALS['LANG'] = $languageService->reveal(); $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class); + $backendUserAuthentication->shallDisplayDebugInformation()->willReturn(true); $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal(); // Expect translation call to the label reference and empty description @@ -132,6 +133,7 @@ class PaletteAndSingleContainerTest extends UnitTestCase $languageService = $this->prophesize(LanguageService::class); $GLOBALS['LANG'] = $languageService->reveal(); $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class); + $backendUserAuthentication->shallDisplayDebugInformation()->willReturn(true); $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal(); // Expect translation call to the label and description references @@ -193,6 +195,7 @@ class PaletteAndSingleContainerTest extends UnitTestCase $languageService = $this->prophesize(LanguageService::class); $GLOBALS['LANG'] = $languageService->reveal(); $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class); + $backendUserAuthentication->shallDisplayDebugInformation()->willReturn(true); $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal(); // Expect translation call to the label and description references diff --git a/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php b/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php index 8986f8c8ec28..21aacc4e219d 100644 --- a/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php +++ b/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php @@ -2311,4 +2311,14 @@ TCAdefaults.sys_note.email = ' . $this->user['email']; return $this->isAdmin() || ($this->getTSConfig()['options.']['impexp.']['enableExportForNonAdminUser'] ?? false); } + + /** + * Returns whether debug information shall be displayed to the user + * + * @internal + */ + public function shallDisplayDebugInformation(): bool + { + return ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] ?? false) && $this->isAdmin(); + } } diff --git a/typo3/sysext/core/Classes/Resource/Service/UserFileInlineLabelService.php b/typo3/sysext/core/Classes/Resource/Service/UserFileInlineLabelService.php index acc4bfe67b6b..9bed91c9ccc1 100644 --- a/typo3/sysext/core/Classes/Resource/Service/UserFileInlineLabelService.php +++ b/typo3/sysext/core/Classes/Resource/Service/UserFileInlineLabelService.php @@ -82,7 +82,7 @@ class UserFileInlineLabelService $labelText = (string)LocalizationUtility::translate('LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file.' . $field); $title = '<dt class="col text-truncate">' . htmlspecialchars($labelText) . '</dt><dd class="col">' . $value . '</dd>'; // In debug mode, add the table name to the record title - if (($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] ?? false) && $this->getBackendUserAuthentication()->isAdmin()) { + if ($this->getBackendUserAuthentication()->shallDisplayDebugInformation()) { $title .= '<div class="col"><code class="m-0">[' . htmlspecialchars($params['table']) . ']</code></div>'; } } diff --git a/typo3/sysext/lowlevel/Classes/Database/QueryGenerator.php b/typo3/sysext/lowlevel/Classes/Database/QueryGenerator.php index 8599fe117e76..614895d73da0 100644 --- a/typo3/sysext/lowlevel/Classes/Database/QueryGenerator.php +++ b/typo3/sysext/lowlevel/Classes/Database/QueryGenerator.php @@ -294,8 +294,7 @@ class QueryGenerator $this->settings = $settings; $this->menuItems = $menuItems; $this->moduleName = $moduleName; - $this->showFieldAndTableNames = ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] ?? false) - && $this->getBackendUserAuthentication()->isAdmin(); + $this->showFieldAndTableNames = $this->getBackendUserAuthentication()->shallDisplayDebugInformation(); } /** diff --git a/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php b/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php index 3dcf618f8cd6..4ff19b383099 100644 --- a/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php +++ b/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php @@ -102,7 +102,7 @@ class RecyclerAjaxController $view = $this->backendViewFactory->create($request); $view->assign('showTableHeader', empty($this->conf['table'])); - $view->assign('showTableName', $GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->getBackendUser()->isAdmin()); + $view->assign('showTableName', $this->getBackendUser()->shallDisplayDebugInformation()); $view->assign('allowDelete', $allowDelete); $view->assign('groupedRecords', $this->transform($deletedRowsArray)); $content = [ -- GitLab