‪TYPO3CMS  ‪main
NoteRenderer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
26 
33 {
34  protected array ‪$pagePermissionCache = [];
35 
36  public function ‪__construct(
37  protected readonly ‪SysNoteRepository $sysNoteRepository,
38  protected readonly ‪BackendViewFactory $backendViewFactory,
39  ) {}
40 
49  public function ‪renderList(ServerRequestInterface $request, int $pid, int $position = null, string $returnUrl = ''): string
50  {
51  $backendUser = $this->‪getBackendUser();
52  if ($pid <= 0
53  || empty($backendUser->getUserId())
54  || !$backendUser->check('tables_select', 'sys_note')
55  ) {
56  return '';
57  }
58 
59  $notes = $this->sysNoteRepository->findByPidAndAuthorId($pid, (int)$backendUser->getUserId(), $position);
60  if (!$notes) {
61  return '';
62  }
63  $view = $this->backendViewFactory->create($request, ['typo3/cms-sys-note']);
64  $view->assignMultiple([
65  'notes' => $this->‪enrichWithEditPermissions($notes),
66  'returnUrl' => $returnUrl,
67  ]);
68  return $view->render('List');
69  }
70 
71  protected function ‪enrichWithEditPermissions(array $notes): array
72  {
73  $backendUser = $this->‪getBackendUser();
74  $hasEditAccess = $backendUser->isAdmin() || $backendUser->check('tables_modify', 'sys_note');
75 
76  foreach ($notes as &$note) {
77  if (!$hasEditAccess) {
78  // If no edit access, disable edit and delete options for all notes
79  $note['canBeEdited'] = false;
80  $note['canBeDeleted'] = false;
81  continue;
82  }
83  // Check content edit permissions for the note
84  $pid = (int)($note['pid'] ?? 0);
85  if (!isset($this->pagePermissionCache[$pid])) {
86  // Calculate and cache the content edit permissions for this $pid
87  $permissionClause = $backendUser->getPagePermsClause(‪Permission::PAGE_SHOW);
88  $pageRow = BackendUtility::readPageAccess($pid, $permissionClause) ?: [];
89  $this->pagePermissionCache[$pid] = $backendUser->doesUserHaveAccess($pageRow, ‪Permission::CONTENT_EDIT);
90  }
91  $note['canBeEdited'] = $this->pagePermissionCache[$pid];
92  // For delete, also take user TSconfig into account
93  $note['canBeDeleted'] = $this->pagePermissionCache[$pid]
94  && !(bool)trim($backendUser->getTSConfig()['options.']['disableDelete.']['sys_note'] ?? $backendUser->getTSConfig()['options.']['disableDelete'] ?? '');
95  }
96 
97  return $notes;
98  }
99 
101  {
102  return ‪$GLOBALS['BE_USER'];
103  }
104 }
‪TYPO3\CMS\Backend\View\BackendViewFactory
Definition: BackendViewFactory.php:35
‪TYPO3\CMS\SysNote\Renderer\NoteRenderer\$pagePermissionCache
‪array $pagePermissionCache
Definition: NoteRenderer.php:34
‪TYPO3\CMS\SysNote\Renderer\NoteRenderer\getBackendUser
‪getBackendUser()
Definition: NoteRenderer.php:100
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\SysNote\Renderer\NoteRenderer\enrichWithEditPermissions
‪enrichWithEditPermissions(array $notes)
Definition: NoteRenderer.php:71
‪TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository
Definition: SysNoteRepository.php:29
‪TYPO3\CMS\SysNote\Renderer\NoteRenderer\renderList
‪renderList(ServerRequestInterface $request, int $pid, int $position=null, string $returnUrl='')
Definition: NoteRenderer.php:49
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:35
‪TYPO3\CMS\SysNote\Renderer\NoteRenderer
Definition: NoteRenderer.php:33
‪TYPO3\CMS\SysNote\Renderer\NoteRenderer\__construct
‪__construct(protected readonly SysNoteRepository $sysNoteRepository, protected readonly BackendViewFactory $backendViewFactory,)
Definition: NoteRenderer.php:36
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:55
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\SysNote\Renderer
Definition: NoteRenderer.php:18