mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #1049 from hamaka/fix/attachments_respecting_hideformdata
This commit is contained in:
commit
ce18179d49
@ -323,7 +323,7 @@ JS
|
||||
// Merge fields are used for CMS authors to reference specific form fields in email content
|
||||
$mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
|
||||
|
||||
if ($attachments) {
|
||||
if ($attachments && (bool) $recipient->HideFormData === false) {
|
||||
foreach ($attachments as $file) {
|
||||
/** @var File $file */
|
||||
if ((int) $file->ID === 0) {
|
||||
|
@ -7,7 +7,6 @@ use SilverStripe\Assets\File;
|
||||
use SilverStripe\Assets\Folder;
|
||||
use SilverStripe\Assets\Storage\AssetStore;
|
||||
use SilverStripe\Assets\Upload_Validator;
|
||||
use InvalidArgumentException;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Control\Session;
|
||||
@ -20,7 +19,6 @@ use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Security\InheritedPermissions;
|
||||
use SilverStripe\UserForms\Control\UserDefinedFormController;
|
||||
use SilverStripe\UserForms\Model\EditableFormField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
|
||||
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
|
||||
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
||||
@ -28,6 +26,7 @@ use SilverStripe\UserForms\Model\Submission\SubmittedFormField;
|
||||
use SilverStripe\UserForms\Model\UserDefinedForm;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\SSViewer;
|
||||
use function filesize;
|
||||
|
||||
/**
|
||||
* @package userforms
|
||||
@ -434,4 +433,38 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
||||
$store = Injector::inst()->get(AssetStore::class);
|
||||
$this->assertTrue($store->exists($image->getFilename(), $image->getHash(), 'FitMaxWzM1MiwyNjRd'));
|
||||
}
|
||||
|
||||
public function testRecipientAttachment()
|
||||
{
|
||||
Config::modify()->set(Upload_Validator::class, 'use_is_uploaded_file', false);
|
||||
|
||||
$userForm = $this->setupFormFrontend('upload-form');
|
||||
$controller = UserDefinedFormController::create($userForm);
|
||||
$field = $this->objFromFixture(EditableFileField::class, 'file-field-1');
|
||||
|
||||
$path = realpath(__DIR__ . '/fixtures/testfile.jpg');
|
||||
$data = [
|
||||
$field->Name => [
|
||||
'name' => 'testfile.jpg',
|
||||
'type' => 'image/jpeg',
|
||||
'tmp_name' => $path,
|
||||
'error' => 0,
|
||||
'size' => filesize($path),
|
||||
]
|
||||
];
|
||||
$_FILES[$field->Name] = $data[$field->Name];
|
||||
|
||||
$controller->getRequest()->setSession(new Session([]));
|
||||
$controller->process($data, $controller->Form());
|
||||
|
||||
// check emails
|
||||
$this->assertEmailSent('test@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$email = $this->findEmail('test@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$this->assertNotEmpty($email['AttachedFiles'], 'Recipients receive attachment by default');
|
||||
|
||||
// no data
|
||||
$this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$nodata = $this->findEmail('nodata@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$this->assertEmpty($nodata['AttachedFiles'], 'Recipients with HideFormData do not receive attachment');
|
||||
}
|
||||
}
|
||||
|
@ -372,6 +372,17 @@ SilverStripe\UserForms\Model\Recipient\EmailRecipient:
|
||||
EmailSubject: Test Email
|
||||
EmailFrom: test3@example.com, test4@example.com
|
||||
|
||||
upload-recipient:
|
||||
EmailAddress: test@example.com
|
||||
EmailSubject: Email Subject
|
||||
EmailFrom: no-reply@example.com
|
||||
|
||||
upload-no-data:
|
||||
EmailAddress: nodata@example.com
|
||||
EmailSubject: Email Subject
|
||||
EmailFrom: no-reply@example.com
|
||||
HideFormData: true
|
||||
|
||||
SilverStripe\UserForms\Model\UserDefinedForm:
|
||||
basic-form-page:
|
||||
Content: '<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>'
|
||||
@ -480,6 +491,9 @@ SilverStripe\UserForms\Model\UserDefinedForm:
|
||||
Title: 'Form with upload field'
|
||||
Fields:
|
||||
- =>SilverStripe\UserForms\Model\EditableFormField\EditableFileField.file-field-1
|
||||
EmailRecipients:
|
||||
- =>SilverStripe\UserForms\Model\Recipient\EmailRecipient.upload-recipient
|
||||
- =>SilverStripe\UserForms\Model\Recipient\EmailRecipient.upload-no-data
|
||||
|
||||
SilverStripe\UserForms\Model\EditableCustomRule:
|
||||
rule1:
|
||||
@ -500,3 +514,4 @@ SilverStripe\UserForms\Model\EditableCustomRule:
|
||||
FieldValue: 'Show more'
|
||||
ConditionField: =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.conditional-required-text-2
|
||||
Parent: =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.conditional-required-text-3
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user