From 792807af0b1d37adc7f412feb106229d5a3acfb5 Mon Sep 17 00:00:00 2001
From: Georg Ringer <georg.ringer@gmail.com>
Date: Tue, 28 Nov 2017 07:49:52 +0100
Subject: [PATCH] [BUGFIX] Show information if access is not allowed in element
 information

If the access to the element information is not allowed, show some
information to the user instead of returning an empty string.

Resolves: #83067
Releases: master, 8.7
Change-Id: Ie4ca3ba41556813a44802fc60befe164a17c4178
Reviewed-on: https://review.typo3.org/54811
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Henning Liebe <h.liebe@neusta.de>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
---
 .../ElementInformationController.php          |  59 +++---
 .../ContentElement/ElementInformation.html    | 200 +++++++++---------
 2 files changed, 135 insertions(+), 124 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php b/typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php
index 00313ed4aeb4..0b1ca8c46ea3 100644
--- a/typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php
+++ b/typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php
@@ -203,41 +203,44 @@ class ElementInformationController
      */
     public function main()
     {
-        if (!$this->access) {
-            return;
-        }
-
         $content = '';
 
-        // render type by user func
-        $typeRendered = false;
-        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] ?? [] as $className) {
-            $typeRenderObj = GeneralUtility::makeInstance($className);
-            if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
-                if ($typeRenderObj->isValid($this->type, $this)) {
-                    $content .= $typeRenderObj->render($this->type, $this);
-                    $typeRendered = true;
-                    break;
+        // Rendering of the output via fluid
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
+        $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+            'EXT:backend/Resources/Private/Templates/ContentElement/ElementInformation.html'
+        ));
+
+        if ($this->access) {
+            // render type by user func
+            $typeRendered = false;
+            foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] ?? [] as $className) {
+                $typeRenderObj = GeneralUtility::makeInstance($className);
+                if (is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render')) {
+                    if ($typeRenderObj->isValid($this->type, $this)) {
+                        $content .= $typeRenderObj->render($this->type, $this);
+                        $typeRendered = true;
+                        break;
+                    }
                 }
             }
-        }
 
-        if (!$typeRendered) {
-            // Rendering of the output via fluid
-            $view = GeneralUtility::makeInstance(StandaloneView::class);
-            $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
-            $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
-            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
-                'EXT:backend/Resources/Private/Templates/ContentElement/ElementInformation.html'
-            ));
-            $view->assignMultiple($this->getPageTitle());
-            $view->assignMultiple($this->getPreview());
-            $view->assignMultiple($this->getPropertiesForTable());
-            $view->assignMultiple($this->getReferences());
-            $view->assignMultiple($this->getBackButton());
-            $view->assign('maxTitleLength', $this->getBackendUser()->uc['titleLen'] ?? 20);
+            if (!$typeRendered) {
+                $view->assign('accessAllowed', true);
+                $view->assignMultiple($this->getPageTitle());
+                $view->assignMultiple($this->getPreview());
+                $view->assignMultiple($this->getPropertiesForTable());
+                $view->assignMultiple($this->getReferences());
+                $view->assignMultiple($this->getBackButton());
+                $view->assign('maxTitleLength', $this->getBackendUser()->uc['titleLen'] ?? 20);
+                $content .=  $view->render();
+            }
+        } else {
             $content .=  $view->render();
         }
+
         $this->moduleTemplate->setContent($content);
     }
 
diff --git a/typo3/sysext/backend/Resources/Private/Templates/ContentElement/ElementInformation.html b/typo3/sysext/backend/Resources/Private/Templates/ContentElement/ElementInformation.html
index 1c1884ead6c1..2137fd7ef833 100644
--- a/typo3/sysext/backend/Resources/Private/Templates/ContentElement/ElementInformation.html
+++ b/typo3/sysext/backend/Resources/Private/Templates/ContentElement/ElementInformation.html
@@ -1,102 +1,110 @@
-<h1>
-    <f:if condition="{table}">
-      <small>{table}</small><br />{icon -> f:format.raw()}
-      <span title="{title}">{title -> f:format.crop(maxCharacters: maxTitleLength)}</span>
-    </f:if>
-</h1>
-<f:if condition="{missingFile}">
-    <f:be.infobox title="{f:translate(key:'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing')}" state="1">{missingFile}</f:be.infobox>
-</f:if>
-<f:if condition="{fileRenderer}">
-    <p>
-        {fileRenderer -> f:format.raw()}
-    </p>
-</f:if>
-<f:if condition="{fileObject}">
-    <p>
-        <f:media file="{fileObject}"
-                 width="{width}"
-                 height="{height}"
-        />
-    </p>
-</f:if>
-<f:if condition="{url}">
-    <p>
-        <a class="btn btn-default" href="{url}" target="_blank">
-            <core:icon identifier="actions-document-view" size="small" alternativeMarkupIdentifier="inline" />
-            <f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.show" />
-        </a>
-    </p>
-</f:if>
-<div class="table-fit table-fit-wrap">
-    <table class="table table-striped table-hover">
-        <f:for each="{extraFields}" as="extraField">
-            <f:render section="extraFieldRow" arguments="{row: extraField}" />
-        </f:for>
-        <f:for each="{fields}" as="field">
-            <f:render section="fieldRow" arguments="{row: field}" />
-        </f:for>
-    </table>
-</div>
-<f:if condition="{returnUrl}">
-    <a class="btn btn-primary" href="{returnUrl}">
-        <core:icon identifier="actions-view-go-back" size="small" />
-        <f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:back" />
-    </a>
-</f:if>
-<f:if condition="{refLines}">
-    <h3><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.referencesToThisItem" /></h3>
-    <div class="table-fit">
-        <table class="table table-striped table-hover">
-            <thead>
-                <tr>
-                    <th class="col-icon"></th>
-                    <th class="col-title"><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.title" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.table" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.uid" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.field" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.flexpointer" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.softrefKey" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.sorting" /></th>
-                    <th class="col-control"></th>
-                </tr>
-            </thead>
-            <tbody>
-                <f:for each="{refLines}" as="refLine">
-                    <f:render section="refLineRow" arguments="{line: refLine, maxTitleLength: maxTitleLength}" />
-                </f:for>
-            </tbody>
-        </table>
-    </div>
-</f:if>
-<f:if condition="{refFromLines}">
-    <h3><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.referencesFromThisItem" /></h3>
-    <div class="table-fit">
-        <table class="table table-striped table-hover">
-            <thead>
-                <tr>
-                    <th class="col-icon"></th>
-                    <th class="col-title"><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.title" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.table" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.uid" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.field" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.flexpointer" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.softrefKey" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.sorting" /></th>
-                    <th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.refString" /></th>
-                    <th class="col-control"></th>
-                </tr>
-            </thead>
-            <tbody>
-                <f:for each="{refFromLines}" as="refFromLine">
-                    <f:render section="refFromLineRow" arguments="{line: refFromLine, maxTitleLength: maxTitleLength}" />
-                </f:for>
-            </tbody>
-        </table>
-    </div>
+<f:if condition="{accessAllowed}">
+	<f:then>
+		<h1>
+			<f:if condition="{table}">
+				<small>{table}</small><br />{icon -> f:format.raw()}
+				<span title="{title}">{title -> f:format.crop(maxCharacters: maxTitleLength)}</span>
+			</f:if>
+		</h1>
+		<f:if condition="{missingFile}">
+			<f:be.infobox title="{f:translate(key:'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing')}" state="1">{missingFile}</f:be.infobox>
+		</f:if>
+		<f:if condition="{fileRenderer}">
+			<p>
+				{fileRenderer -> f:format.raw()}
+			</p>
+		</f:if>
+		<f:if condition="{fileObject}">
+			<p>
+				<f:media file="{fileObject}"
+								 width="{width}"
+								 height="{height}"
+				/>
+			</p>
+		</f:if>
+		<f:if condition="{url}">
+			<p>
+				<a class="btn btn-default" href="{url}" target="_blank">
+					<core:icon identifier="actions-document-view" size="small" alternativeMarkupIdentifier="inline" />
+					<f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.show" />
+				</a>
+			</p>
+		</f:if>
+		<div class="table-fit table-fit-wrap">
+			<table class="table table-striped table-hover">
+				<f:for each="{extraFields}" as="extraField">
+					<f:render section="extraFieldRow" arguments="{row: extraField}" />
+				</f:for>
+				<f:for each="{fields}" as="field">
+					<f:render section="fieldRow" arguments="{row: field}" />
+				</f:for>
+			</table>
+		</div>
+		<f:if condition="{returnUrl}">
+			<a class="btn btn-primary" href="{returnUrl}">
+				<core:icon identifier="actions-view-go-back" size="small" />
+				<f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:back" />
+			</a>
+		</f:if>
+		<f:if condition="{refLines}">
+			<h3><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.referencesToThisItem" /></h3>
+			<div class="table-fit">
+				<table class="table table-striped table-hover">
+					<thead>
+					<tr>
+						<th class="col-icon"></th>
+						<th class="col-title"><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.title" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.table" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.uid" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.field" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.flexpointer" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.softrefKey" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.sorting" /></th>
+						<th class="col-control"></th>
+					</tr>
+					</thead>
+					<tbody>
+					<f:for each="{refLines}" as="refLine">
+						<f:render section="refLineRow" arguments="{line: refLine, maxTitleLength: maxTitleLength}" />
+					</f:for>
+					</tbody>
+				</table>
+			</div>
+		</f:if>
+		<f:if condition="{refFromLines}">
+			<h3><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.referencesFromThisItem" /></h3>
+			<div class="table-fit">
+				<table class="table table-striped table-hover">
+					<thead>
+					<tr>
+						<th class="col-icon"></th>
+						<th class="col-title"><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.title" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.table" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.uid" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.field" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.flexpointer" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.softrefKey" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.sorting" /></th>
+						<th><f:translate key="LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:show_item.php.refString" /></th>
+						<th class="col-control"></th>
+					</tr>
+					</thead>
+					<tbody>
+					<f:for each="{refFromLines}" as="refFromLine">
+						<f:render section="refFromLineRow" arguments="{line: refFromLine, maxTitleLength: maxTitleLength}" />
+					</f:for>
+					</tbody>
+				</table>
+			</div>
+		</f:if>
+	</f:then>
+	<f:else>
+		<f:be.infobox state="2">{f:translate(key: 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.noEditPermission')}</f:be.infobox>
+	</f:else>
 </f:if>
 
 
+
 <f:section name="extraFieldRow">
     <tr>
         <th class="col-nowrap">{row.fieldLabel}</th>
-- 
GitLab