Skip to content

Commit

Permalink
[BUGFIX] Add feature flag for allowed translation
Browse files Browse the repository at this point in the history
The PR #361 added the feature setting restirctions to backend users and
groups. This feature introduced accidentally a breaking change setting
the user and group permissions required.

With this commit, a feature is added allowing set up of translation
restrictions after enabling the feature in LocalConfiguration.

Changed behaviour:

* Added feature toggle `deeplTranslationUserConfigured`

If you want to use this new feature, enable
`$GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['deeplTranslationUserConfigured']`
in your `LocalConfiguration` or `config/system/settings.php`.
  • Loading branch information
calien666 committed Dec 11, 2024
1 parent 8c4cd47 commit 414bbf4
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Classes/Event/Listener/GlossarySyncButtonProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use TYPO3\CMS\Backend\Template\Components\ModifyButtonBarEvent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
Expand Down Expand Up @@ -59,7 +60,10 @@ public function __invoke(ModifyButtonBarEvent $event): void
return;
}

if (!$this->getBackendUserAuthentication()->check('custom_options', AllowedGlossarySyncAccess::ALLOWED_GLOSSARY_SYNC)) {
if (
GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('deeplTranslationUserConfigured')
&& !$this->getBackendUserAuthentication()->check('custom_options', AllowedGlossarySyncAccess::ALLOWED_GLOSSARY_SYNC)
) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion Classes/Hooks/ButtonBarHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
Expand Down Expand Up @@ -49,7 +50,10 @@ public function getButtons(array $params, ButtonBar $buttonBar): array
return $buttons;
}

if (!$this->getBackendUserAuthentication()->check('custom_options', AllowedGlossarySyncAccess::ALLOWED_GLOSSARY_SYNC)) {
if (
GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('deeplTranslationUserConfigured')
&& !$this->getBackendUserAuthentication()->check('custom_options', AllowedGlossarySyncAccess::ALLOWED_GLOSSARY_SYNC)
) {
return $buttons;
}

Expand Down
7 changes: 6 additions & 1 deletion Classes/Override/Core11/DatabaseRecordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace WebVision\WvDeepltranslate\Override\Core11;

use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\WvDeepltranslate\Access\AllowedTranslateAccess;
use WebVision\WvDeepltranslate\Utility\DeeplBackendUtility;

Expand Down Expand Up @@ -34,7 +36,10 @@ public function makeLocalizationPanel($table, $row, array $translations): string
return $out;
}

if (!$this->getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)) {
if (
GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('deeplTranslationUserConfigured')
&& !$this->getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)
) {
return $out;
}

Expand Down
11 changes: 9 additions & 2 deletions Classes/Override/Core11/DeeplRecordListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Exception;
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
Expand Down Expand Up @@ -42,7 +43,10 @@ protected function languageSelector(string $requestUri, $_forwardCore12CombatAnd
return $originalOutput;
}

if (!$this->getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)) {
if (
GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('deeplTranslationUserConfigured')
&& !$this->getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)
) {
return $originalOutput;
}

Expand Down Expand Up @@ -81,7 +85,10 @@ private function buildGlossaryTranslationOptionDropdown(string $requestUri): str
return '';
}

if (!$this->getBackendUserAuthentication()->check('custom_options', AllowedGlossarySyncAccess::ALLOWED_GLOSSARY_SYNC)) {
if (
GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('deeplTranslationUserConfigured')
&& !$this->getBackendUserAuthentication()->check('custom_options', AllowedGlossarySyncAccess::ALLOWED_GLOSSARY_SYNC)
) {
return '';
}

Expand Down
7 changes: 6 additions & 1 deletion Classes/Override/Core12/DatabaseRecordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace WebVision\WvDeepltranslate\Override\Core12;

use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\WvDeepltranslate\Access\AllowedTranslateAccess;
use WebVision\WvDeepltranslate\Utility\DeeplBackendUtility;

Expand Down Expand Up @@ -33,7 +35,10 @@ public function makeLocalizationPanel($table, $row, array $translations): string
return $out;
}

if (!$this->getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)) {
if (
GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('deeplTranslationUserConfigured')
&& !$this->getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)
) {
return $out;
}

Expand Down
11 changes: 9 additions & 2 deletions Classes/Override/Core12/DeeplRecordListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Driver\Exception;
use TYPO3\CMS\Backend\Controller\RecordListController;
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
Expand Down Expand Up @@ -46,7 +47,10 @@ protected function languageSelector(array $siteLanguages, string $requestUri): s
return $originalOutput;
}

if (!$this->getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)) {
if (
GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('deeplTranslationUserConfigured')
&& !$this->getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)
) {
return $originalOutput;
}

Expand Down Expand Up @@ -84,7 +88,10 @@ private function buildGlossaryTranslationOptionDropdown(array $siteLanguages, st
return '';
}

if (!$this->getBackendUserAuthentication()->check('custom_options', AllowedGlossarySyncAccess::ALLOWED_GLOSSARY_SYNC)) {
if (
GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('deeplTranslationUserConfigured')
&& !$this->getBackendUserAuthentication()->check('custom_options', AllowedGlossarySyncAccess::ALLOWED_GLOSSARY_SYNC)
) {
return '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace WebVision\WvDeepltranslate\ViewHelpers\Be\Access;

use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use WebVision\WvDeepltranslate\Access\AllowedTranslateAccess;
Expand All @@ -18,7 +20,10 @@ public function initializeArguments(): void

public static function verdict(array $arguments, RenderingContextInterface $renderingContext): bool
{
if (self::getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)) {
if (
!GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('deeplTranslationUserConfigured')
|| self::getBackendUserAuthentication()->check('custom_options', AllowedTranslateAccess::ALLOWED_TRANSLATE_OPTION_VALUE)
) {
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['wvdeepltranslate']['backend']
??= \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class;

$GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['deeplTranslationUserConfigured'] ??= false;

$accessRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\WebVision\WvDeepltranslate\Access\AccessRegistry::class);
$accessRegistry->addAccess((new \WebVision\WvDeepltranslate\Access\AllowedTranslateAccess()));
$accessRegistry->addAccess((new \WebVision\WvDeepltranslate\Access\AllowedGlossarySyncAccess()));
Expand Down

0 comments on commit 414bbf4

Please sign in to comment.