‪TYPO3CMS  ‪main
RecordAccessVoter.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\EventDispatcher\EventDispatcherInterface;
22 
29 {
30  public function ‪__construct(
31  protected readonly EventDispatcherInterface $eventDispatcher
32  ) {}
33 
44  public function ‪accessGranted(string $table, array ‪$record, ‪Context $context): bool
45  {
46  $event = new ‪RecordAccessGrantedEvent($table, ‪$record, $context);
47  $this->eventDispatcher->dispatch($event);
48  if ($event->isPropagationStopped()) {
49  return $event->accessGranted();
50  }
51  ‪$record = $event->getRecord();
52 
53  $configuration = $this->‪getEnableFieldsConfigurationForTable($table);
54  $visibilityAspect = $context->‪getAspect('visibility');
55  $includeHidden = $table === 'pages'
56  ? $visibilityAspect->includeHiddenPages()
57  : $visibilityAspect->includeHiddenContent();
58 
59  // Hidden field is active and hidden records should not be included
60  if ((‪$record[$configuration['disabled'] ?? null] ?? false) && !$includeHidden) {
61  return false;
62  }
63  // Records' starttime set AND is HIGHER than the current access time
64  if (isset($configuration['starttime'], ‪$record[$configuration['starttime']])
65  && (int)‪$record[$configuration['starttime']] > ‪$GLOBALS['SIM_ACCESS_TIME']
66  ) {
67  return false;
68  }
69  // Records' endtime is set AND NOT "0" AND LOWER than the current access time
70  if (isset($configuration['endtime'], ‪$record[$configuration['endtime']])
71  && ((int)‪$record[$configuration['endtime']] !== 0)
72  && ((int)‪$record[$configuration['endtime']] < ‪$GLOBALS['SIM_ACCESS_TIME'])
73  ) {
74  return false;
75  }
76  // Insufficient group access
77  if ($this->‪groupAccessGranted($table, ‪$record, $context) === false) {
78  return false;
79  }
80  // Record is available
81  return true;
82  }
83 
92  public function ‪groupAccessGranted(string $table, array ‪$record, ‪Context $context): bool
93  {
94  $configuration = $this->‪getEnableFieldsConfigurationForTable($table);
95  if (!isset($configuration['fe_group']) || !(‪$record[$configuration['fe_group']] ?? false)) {
96  return true;
97  }
98  // No frontend user, but 'fe_group' is not empty, so shut this down.
99  if (!$context->‪hasAspect('frontend.user')) {
100  return false;
101  }
102  $pageGroupList = explode(',', (string)‪$record[$configuration['fe_group']]);
103  return count(array_intersect($context->‪getAspect('frontend.user')->getGroupIds(), $pageGroupList)) > 0;
104  }
105 
114  public function ‪accessGrantedForPageInRootLine(array $pageRecord, ‪Context $context): bool
115  {
116  return !($pageRecord['extendToSubpages'] ?? false) || $this->‪accessGranted('pages', $pageRecord, $context);
117  }
118 
119  protected function ‪getEnableFieldsConfigurationForTable(string $table): array
120  {
121  return ‪$GLOBALS['TCA'][$table]['ctrl']['enablecolumns'] ?? [];
122  }
123 }
‪TYPO3\CMS\Core\Domain\Access\RecordAccessVoter\accessGranted
‪bool accessGranted(string $table, array $record, Context $context)
Definition: RecordAccessVoter.php:44
‪TYPO3\CMS\Core\Context\Context\getAspect
‪getAspect(string $name)
Definition: Context.php:76
‪TYPO3\CMS\Core\Domain\Access\RecordAccessVoter\__construct
‪__construct(protected readonly EventDispatcherInterface $eventDispatcher)
Definition: RecordAccessVoter.php:30
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Core\Domain\Access\RecordAccessVoter\groupAccessGranted
‪bool groupAccessGranted(string $table, array $record, Context $context)
Definition: RecordAccessVoter.php:92
‪TYPO3\CMS\Core\Context\Context\hasAspect
‪hasAspect(string $name)
Definition: Context.php:63
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Core\Domain\Access\RecordAccessVoter\accessGrantedForPageInRootLine
‪accessGrantedForPageInRootLine(array $pageRecord, Context $context)
Definition: RecordAccessVoter.php:114
‪TYPO3\CMS\Core\Domain\Access\RecordAccessGrantedEvent
Definition: RecordAccessGrantedEvent.php:29
‪TYPO3\CMS\Core\Domain\Access\RecordAccessVoter\getEnableFieldsConfigurationForTable
‪getEnableFieldsConfigurationForTable(string $table)
Definition: RecordAccessVoter.php:119
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Domain\Access
Definition: RecordAccessGrantedEvent.php:18
‪TYPO3\CMS\Core\Domain\Access\RecordAccessVoter
Definition: RecordAccessVoter.php:29