Skip to content

Commit

Permalink
!!![TASK] change dependencies and fix some stuff
Browse files Browse the repository at this point in the history
* drop TYPO3 v11 Support
* add TYPO3 v13 Support
* Provide Tests
* Provide CI
* add limit to language Support
* fix PageTS Settings Support
* fix some array access
* adapt README
  • Loading branch information
achimfritz committed Jan 22, 2025
1 parent a180a7a commit 87ed382
Show file tree
Hide file tree
Showing 36 changed files with 641 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/.gitattributes export-ignore
/Tests/ export-ignore
/Build/ export-ignore
/.gitignore export-ignore
/.github export-ignore
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI

on: [push, pull_request]

jobs:
testsuite:

runs-on: ubuntu-latest
strategy:
matrix:
TYPO3: ['12', '13']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer:v2

- name: Start MySQL
run: sudo /etc/init.d/mysql start

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Install composer dependencies TYPO3 13
if: matrix.TYPO3 == '13'
run: |
composer install --no-progress --no-interaction
- name: Install composer dependencies TYPO3 12
if: matrix.TYPO3 == '12'
run: |
composer require typo3/cms-core:^12.4 --no-progress --no-interaction --dev -W
- name: Phpstan
run: .Build/bin/phpstan analyze -c Build/phpstan.neon

- name: Phpcsfix
run: .Build/bin/php-cs-fixer fix --config=Build/php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no

- name: Functional Tests
run: |
export typo3DatabaseName="typo3";
export typo3DatabaseHost="127.0.0.1";
export typo3DatabaseUsername="root";
export typo3DatabasePassword="root";
.Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml Tests/Functional
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.Build/
/composer.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label: Allow all MFA Providers
mfa_providers: ['*']
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
label: Allow all web modules
modules:
web: "*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label: Allow all widgets
widgets: ['*']
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
label: clear all cache
settings:
TCEMAIN:
clearCache: all
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
label: Allow doktype sysfilder
resources:
pages:
types:
- 254
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
label: Allow to site
sites:
- main
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label: Allow language de
languages: ["de-DE"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
label: Allow to non existing site
sites:
- foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
label: Allow to site
sites:
- 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
label: Allow reading files-
files:
- readFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
label: Allow reading of page title
resources:
pages:
permissions: ['read']
fields:
- title
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
label: Allow all widgets
widgets:
- t3news
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
label: Allow totp MFA Providers
mfa_providers:
- totp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
label: Allow web_info modules
modules:
web_list: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
label: Allow writing of page title
resources:
pages:
permissions: ['write']
fields:
- title
12 changes: 12 additions & 0 deletions Build/Packages/permission-sets-examples/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "b13/permission-sets-examples",
"type": "typo3-cms-extension",
"description": "Examples for testing",
"license": "GPL-2.0-or-later",
"version": "1.0.0",
"extra": {
"typo3/cms": {
"extension-key": "permission_sets_examples"
}
}
}
4 changes: 4 additions & 0 deletions Build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

- run ``php -d memory_limit=2G .Build/bin/phpstan analyse -c Build/phpstan.neon``
- run ``php -d memory_limit=2G .Build/bin/php-cs-fixer fix --config=Build/php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no``
- run ``php -d memory_limit=2G .Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml Tests/Functional``
18 changes: 18 additions & 0 deletions Build/php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/../Classes')
->in(__DIR__ . '/../Tests')
->in(__DIR__ . '/../Configuration');

return \TYPO3\CodingStandards\CsFixerConfig::create()
->setFinder($finder)
->addRules([
'nullable_type_declaration' => [
'syntax' => 'question_mark',
],
'nullable_type_declaration_for_default_null_value' => true,
'declare_strict_types' => true,
])
->setUsingCache(false);

5 changes: 5 additions & 0 deletions Build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 5

paths:
- %currentWorkingDirectory%/Classes
30 changes: 30 additions & 0 deletions Build/phpunit/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="FunctionalTestsBootstrap.php"
cacheDirectory=".phpunit.cache"
cacheResult="false"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnDeprecation="true"
failOnNotice="true"
failOnRisky="true"
failOnWarning="true"
requireCoverageMetadata="false"
>
<testsuites>
<testsuite name="Functional tests">
<directory>../../Tests/Functional/</directory>
</testsuite>
</testsuites>
<php>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
21 changes: 21 additions & 0 deletions Build/phpunit/FunctionalTestsBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

(static function () {
$testbase = new \TYPO3\TestingFramework\Core\Testbase();
$testbase->defineOriginalRootPath();
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests');
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
})();
23 changes: 23 additions & 0 deletions Build/sites/main/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
base: '/'
baseVariants: { }
errorHandling: { }
languages:
-
title: english
enabled: true
base: /
locale: en_US.UTF-8
flag: global
languageId: '0'
websiteTitle: ''
-
title: german
enabled: true
base: /de/
locale: de_DE.UTF-8
flag: de
languageId: '1'

rootPageId: 1
routes: { }
websiteTitle: 'Testing'
79 changes: 43 additions & 36 deletions Classes/AttachPermissionsToGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use TYPO3\CMS\Core\Authentication\Event\AfterGroupsResolvedEvent;
use TYPO3\CMS\Core\Authentication\Mfa\MfaProviderRegistry;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
Expand Down Expand Up @@ -84,7 +84,11 @@ private function expandGroupPermissionsWithPermissionSet(array $group, Permissio
if (MathUtility::canBeInterpretedAsInteger($siteOrPage)) {
$finalSitesAndPages[] = $siteOrPage;
} else {
$finalSitesAndPages[] = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByIdentifier($siteOrPage)->getRootPageId();
try {
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByIdentifier($siteOrPage);
$finalSitesAndPages[] = $site->getRootPageId();
} catch (SiteNotFoundException $e) {
}
}
}
$group['db_mountpoints'] .= ',' . implode(',', $finalSitesAndPages);
Expand Down Expand Up @@ -141,58 +145,57 @@ private function expandGroupPermissionsWithPermissionSet(array $group, Permissio
$allowedContentTypes = $contentTypeLimitation['types'];
}
foreach ($allowedContentTypes as $allowedContentType) {
if ((new Typo3Version())->getMajorVersion() > 11) {
// needs to be like tt_content:CType:db_content_keyvisual
// @todo: add support for list_type
$finishedData[] = 'tt_content:CType:' . $allowedContentType;
} else {
// needs to be like tt_content:CType:db_content_keyvisual:ALLOW
// @todo: add support for list_type
$finishedData[] = 'tt_content:CType:' . $allowedContentType . ':ALLOW';
}
// needs to be like tt_content:CType:db_content_keyvisual
// @todo: add support for list_type
$finishedData[] = 'tt_content:CType:' . $allowedContentType;
}
$group['explicit_allowdeny'] .= ',' . implode(',', $finishedData);
}

// @todo: $group['allowed_languages'] .= ',' . $languages;
$languages = $permissionSet->getAllowedLanguages();
if ($languages) {
$group['allowed_languages'] .= ',' . implode(',', $this->expandLanguageInstruction($languages));
}
// @todo: add userTsConfig
$settings = $permissionSet->getSettings();
if ($settings !== null) {
$settings = (new TypoScriptService())->convertPlainArrayToTypoScriptArray($settings);
$settings = ArrayUtility::flatten($settings, '', true);
$group['TSconfig'] .= "\n\r" . implode("\n\r", $settings);
foreach ($settings as $key => $value) {
$group['TSconfig'] .= "\n\r" . $key . ' = ' . $value;
}
}
return $group;
}

private function expandLanguageInstruction(array $languages): array
{
$languageIds = [];
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$sites = $siteFinder->getAllSites();
foreach ($sites as $site) {
$siteLanguages = $site->getLanguages();
foreach ($siteLanguages as $siteLanguage) {
if (in_array((string)$siteLanguage->getLocale(), $languages, true)) {
$languageIds[] = $siteLanguage->getLanguageId();
}
}
}
return $languageIds;
}

private function expandModuleInstruction(array $allowedModules): array
{
$finalModules = [];
foreach ($allowedModules as $moduleName => $allowedModule) {
if ($allowedModule === '*' || $allowedModule === ['*']) {
// Fetch all submodules of a module
if ((new Typo3Version())->getMajorVersion() > 11) {
$subModuleList = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Module\ModuleProvider::class)->getModule($moduleName)->getSubmodules();
foreach ($subModuleList as $subModuleName) {
$finalModules[] = $subModuleName->getIdentifier();
}
} else {
$subModuleList = $GLOBALS['TBE_MODULES'][$moduleName] ?? '';
$subModuleList = explode(',', $subModuleList);
foreach ($subModuleList as $subModuleName) {
$finalModules[] = $moduleName . '_' . $subModuleName;
}
$subModuleList = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Module\ModuleProvider::class)->getModule($moduleName)->getSubmodules();
foreach ($subModuleList as $subModuleName) {
$finalModules[] = $subModuleName->getIdentifier();
}
} else if ((bool)$allowedModule === true) {
if ((new Typo3Version())->getMajorVersion() > 11) {
if (GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Module\ModuleProvider::class)->isModuleRegistered($moduleName)) {
$finalModules[] = $moduleName;
}
} else {
[$module, $subModule] = GeneralUtility::trimExplode('_', $moduleName, true);
if (array_key_exists($module, $GLOBALS['TBE_MODULES']) && str_contains($GLOBALS['TBE_MODULES'][$module], $subModule)) {
$finalModules[] = $moduleName;
}
} elseif ((bool)$allowedModule === true) {
if (GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Module\ModuleProvider::class)->isModuleRegistered($moduleName)) {
$finalModules[] = $moduleName;
}
}
}
Expand All @@ -201,7 +204,11 @@ private function expandModuleInstruction(array $allowedModules): array

private function expandWidgetInstruction(array $allowedDashboardWidgets): array
{
if ($allowedDashboardWidgets === '*' || $allowedDashboardWidgets === ['*']) {
$packageManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
if ($packageManager->isPackageActive('dashboard') === false) {
return [];
}
if ($allowedDashboardWidgets === ['*']) {
$finalDashboardWidgets = [];
$dashboardWidgets = GeneralUtility::makeInstance(WidgetRegistry::class)->getAllWidgets();
foreach ($dashboardWidgets as $dashboardWidget) {
Expand Down
Loading

0 comments on commit 87ed382

Please sign in to comment.