Skip to content

Commit

Permalink
[FEATURE] Allow editors to choose whether attachments are sent
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwemer committed Nov 5, 2024
1 parent 0e815d9 commit b0ed084
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .project/tests/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3405,6 +3405,11 @@ parameters:
count: 1
path: ../../Classes/UserFunc/DateConverter.php

-
message: "#^Method In2code\\\\Powermail\\\\UserFunc\\\\TestForFeature\\:\\:isFeatureEnabled\\(\\) has parameter \\$arguments with no value type specified in iterable type array\\.$#"
count: 1
path: ../../Classes/UserFunc/TestForFeature.php

-
message: "#^Method In2code\\\\Powermail\\\\Utility\\\\ArrayUtility\\:\\:arrayMergeRecursiveOverrule\\(\\) has parameter \\$firstArray with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
3 changes: 3 additions & 0 deletions .project/typo3/additional.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
'sitename' => 'LOKAL: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],
'displayErrors' => 1,
'enableDeprecationLog' => 'file',
'features' => [
'powermailEditorsAreAllowedToSendAttachments' => true,
],
'systemLogLevel' => 0,
'devIPmask' => '*',
'clearCacheSystem' => 1,
Expand Down
20 changes: 20 additions & 0 deletions Classes/UserFunc/TestForFeature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace In2code\Powermail\UserFunc;

use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class TestForFeature
{
public function isFeatureEnabled(array $arguments = []): bool
{
$features = GeneralUtility::makeInstance(Features::class);
if ($features->isFeatureEnabled($arguments['conditionParameters'][0])) {
return true;
}
return false;
}
}
12 changes: 12 additions & 0 deletions Classes/Utility/ConfigurationUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\ArrayUtility as CoreArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -211,13 +212,24 @@ public static function testGdExtension(): void
*/
public static function mergeTypoScript2FlexForm(array $settings, string $typoScriptLevel = 'setup'): array
{
$originalSettings = $settings;
if (array_key_exists($typoScriptLevel, $settings) && array_key_exists('flexform', $settings)) {
$settings = ArrayUtility::arrayMergeRecursiveOverrule(
(array)$settings[$typoScriptLevel],
(array)$settings['flexform'],
false,
false
);

$features = GeneralUtility::makeInstance(Features::class);
if ($features->isFeatureEnabled('powermailEditorsAreAllowedToSendAttachments')) {
if (isset($originalSettings['flexform']['receiver']['attachment'])) {
$settings['receiver']['attachment'] = $originalSettings['flexform']['receiver']['attachment'];
}
if (isset($originalSettings['flexform']['sender']['attachment'])) {
$settings['sender']['attachment'] = $originalSettings['flexform']['sender']['attachment'];
}
}
}
return $settings;
}
Expand Down
22 changes: 20 additions & 2 deletions Configuration/FlexForms/FlexformPi1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,16 @@
<enableRichtext>1</enableRichtext>
</config>
</settings.flexform.receiver.body>
</el>
<settings.flexform.receiver.attachment>
<displayCond>USER:In2code\Powermail\UserFunc\TestForFeature->isFeatureEnabled:powermailEditorsAreAllowedToSendAttachments</displayCond>
<exclude>1</exclude>
<label>LLL:EXT:powermail/Resources/Private/Language/locallang_db.xlf:flexform.receiver.attachment</label>
<config>
<type>check</type>
<default>0</default>
</config>
</settings.flexform.receiver.attachment>
</el>
</ROOT>
</receiver>
<sender>
Expand Down Expand Up @@ -252,7 +261,16 @@
<enableRichtext>1</enableRichtext>
</config>
</settings.flexform.sender.body>
</el>
<settings.flexform.sender.attachment>
<displayCond>USER:In2code\Powermail\UserFunc\TestForFeature->isFeatureEnabled:powermailEditorsAreAllowedToSendAttachments</displayCond>
<exclude>1</exclude>
<label>LLL:EXT:powermail/Resources/Private/Language/locallang_db.xlf:flexform.sender.attachment</label>
<config>
<type>check</type>
<default>0</default>
</config>
</settings.flexform.sender.attachment>
</el>
</ROOT>
</sender>
<thx>
Expand Down
18 changes: 18 additions & 0 deletions Configuration/TSConfig/EditorsSendAttachments.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
TCEFORM {
tt_content {
pi_flexform {
powermail_pi1 {
sender {
settings\.flexform\.sender\.attachment {
disabled = 1
}
}
receiver {
settings\.flexform\.receiver\.attachment {
disabled = 1
}
}
}
}
}
}
57 changes: 57 additions & 0 deletions Documentation/ForAdministrators/BestPractice/SendAttachments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# How to send attachments

## Defined by TypoScript

In versions < 12.5 it was only possible to define, whether attachments are sent or not, via TypoScript. This setting
was used for all forms and plugins (unless you used conditions or set the value in the database).

```typo3_typoscript
plugin.tx_powermail.settings.setup {
reciever {
attachment = {$plugin.tx_powermail.settings.receiver.attachment}
}
sender {
attachment = {$plugin.tx_powermail.settings.sender.attachment}
}
}
```

## Defined by editors

Since version 12.5 it is possible, that editors define, whether attachments should be sent or not. This feature is
"hidden" behind a feature toggle and restrictive page tsconfig settings.

### Steps for activation

1) Activate the feature toggle in site settings

```php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['powermailEditorsAreAllowedToSendAttachments'] = true;
```

2) Activate the fields in PageTSconfig

Due to security reasons these fields are hidden by default, so that the admin must take an additional step. Editors
should not get more permissions, than necessary by a feature release. ;-)

```typo3_typoscript
TCEFORM {
tt_content {
pi_flexform {
powermail_pi1 {
sender {
settings\.flexform\.sender\.attachment {
disabled = 0
}
}
receiver {
settings\.flexform\.receiver\.attachment {
disabled = 0
}
}
}
}
}
}
```

6 changes: 6 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@
<trans-unit id="flexform.receiver.body" resname="flexform.receiver.body">
<source>Bodytext for Email to Receiver</source>
</trans-unit>
<trans-unit id="flexform.receiver.attachment" resname="flexform.receiver.attachment">
<source>Send uploaded files to receiver</source>
</trans-unit>
<trans-unit id="flexform.sender" resname="flexform.sender">
<source>Mail to User</source>
</trans-unit>
Expand All @@ -504,6 +507,9 @@
<trans-unit id="flexform.sender.body" resname="flexform.sender.body">
<source>Bodytext for Email to Sender</source>
</trans-unit>
<trans-unit id="flexform.sender.attachment" resname="flexform.sender.attachment">
<source>Send uploaded files to sender</source>
</trans-unit>
<trans-unit id="flexform.thx" resname="flexform.thx">
<source>Submit Page</source>
</trans-unit>
Expand Down
15 changes: 10 additions & 5 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,17 @@
);

/**
* ContentElementWizard for Pi1
* Include PageTSconfig
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
'@import \'EXT:powermail/Configuration/TSConfig/ContentElementWizard.typoscript\''
);

/**
* PageTSConfig for backend mod list
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
'@import \'EXT:powermail/Configuration/TSConfig/WebList.typoscript\''
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
'@import \'EXT:powermail/Configuration/TSConfig/EditorsSendAttachments.typoscript\''
);

/**
* Hook for initially filling the marker field in backend
Expand Down Expand Up @@ -141,4 +140,10 @@
= \In2code\Powermail\Update\PowermailPermissionUpdater::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['powermailPermissionSubmodulesUpdater']
= \In2code\Powermail\Update\PowermailPermissionSubmoduleUpdater::class;

/**
* Feature toggle
*/

$GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['powermailEditorsAreAllowedToSendAttachments'] ??= false;
});

0 comments on commit b0ed084

Please sign in to comment.