hasBackendUser()) { return false; } return $this->tcaSchemaFactory->has(FormDefinitionRepository::TABLE_NAME) && $this->hasTableReadAccess() && $this->hasPageAccess($pageId); } /** * Assert that the current backend user has read permissions for the page * a given form record is stored on. * * @throws PersistenceManagerException */ public function assertReadAccessForRecord(int $uid, ?array $record): void { $pid = (int)($record['pid'] ?? throw new PersistenceManagerException( sprintf('The form with uid "%d" has no valid pid.', $uid), 1774364028 )); if (!$this->hasReadPermission($pid)) { throw new PersistenceManagerException( sprintf('Access denied: You do not have permission to access forms on page "%d".', $pid), 1774364031 ); } } /** * Check if the current backend user has write permissions for the given page */ public function hasWritePermission(int $pageId): bool { if (!$this->hasBackendUser()) { return false; } return $this->tcaSchemaFactory->has(FormDefinitionRepository::TABLE_NAME) && $this->hasTableWriteAccess() && $this->hasPageAccess($pageId); } /** * Assert that the current backend user has write permissions for the page * a given form record is stored on. * * @throws PersistenceManagerException */ public function assertWriteAccessForRecord(int $uid, ?array $record): void { $pid = (int)($record['pid'] ?? throw new PersistenceManagerException( sprintf('The form with uid "%d" has no valid pid.', $uid), 1767199436 )); if (!$this->hasWritePermission($pid)) { throw new PersistenceManagerException( sprintf('Access denied: You do not have permission to persist forms on page "%d".', $pid), 1767199442 ); } } private function hasPageAccess(int $pageId): bool { $backendUser = $this->getBackendUser(); if ($backendUser->isAdmin()) { return true; } if ($pageId <= 0) { return true; } $pageRow = BackendUtility::getRecord('pages', $pageId); if ($pageRow === null) { return false; } // For all other pages, check web mount and page permissions if ($backendUser->isInWebMount($pageId) === null) { return false; } return $backendUser->doesUserHaveAccess($pageRow, Permission::PAGE_SHOW); } private function hasTableReadAccess(): bool { return $this->getBackendUser()->check('tables_select', FormDefinitionRepository::TABLE_NAME); } private function hasTableWriteAccess(): bool { return $this->getBackendUser()->check('tables_modify', FormDefinitionRepository::TABLE_NAME); } private function hasBackendUser(): bool { return ($GLOBALS['BE_USER'] ?? null) instanceof BackendUserAuthentication; } private function getBackendUser(): BackendUserAuthentication { return $GLOBALS['BE_USER']; } }