Fa005 submissions file link in notifications (#298)
* fix: unsigned url in form email * fix: signed file link in email * fix: use limit function for file label name * feat: use signed url for files in email and csv export --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -37,7 +37,8 @@ class FormSubmissionController extends Controller
|
||||
$formatter = (new FormSubmissionFormatter($form, $row['data']))
|
||||
->outputStringsOnly()
|
||||
->setEmptyForNoValue()
|
||||
->showRemovedFields();
|
||||
->showRemovedFields()
|
||||
->useSignedUrlForFiles();
|
||||
$tmp = $formatter->getCleanKeyValue();
|
||||
$tmp['Create Date'] = date("Y-m-d H:i", strtotime($row['created_at']));
|
||||
$allRows[] = $tmp;
|
||||
|
||||
@@ -35,7 +35,8 @@ class SubmissionConfirmationMail extends OpenFormMail implements ShouldQueue
|
||||
|
||||
$formatter = (new FormSubmissionFormatter($form, $this->event->data))
|
||||
->createLinks()
|
||||
->outputStringsOnly();
|
||||
->outputStringsOnly()
|
||||
->useSignedUrlForFiles();
|
||||
|
||||
return $this
|
||||
->replyTo($this->getReplyToEmail($form->creator->email))
|
||||
|
||||
@@ -49,7 +49,8 @@ class FormSubmissionNotification extends Notification implements ShouldQueue
|
||||
$formatter = (new FormSubmissionFormatter($this->event->form, $this->event->data))
|
||||
->showHiddenFields()
|
||||
->createLinks()
|
||||
->outputStringsOnly();
|
||||
->outputStringsOnly()
|
||||
->useSignedUrlForFiles();
|
||||
|
||||
return (new MailMessage)
|
||||
->replyTo($this->getReplyToEmail($notifiable->routes['mail']))
|
||||
|
||||
@@ -29,6 +29,8 @@ class FormSubmissionFormatter
|
||||
|
||||
private $showRemovedFields = false;
|
||||
|
||||
private $useSignedUrlForFiles = false;
|
||||
|
||||
/**
|
||||
* Logic resolver needs an array id => value, so we create it here
|
||||
*/
|
||||
@@ -69,6 +71,12 @@ class FormSubmissionFormatter
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function useSignedUrlForFiles()
|
||||
{
|
||||
$this->useSignedUrlForFiles = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a nice "FieldName": "Field Response" array
|
||||
* - If createLink enabled, returns html link for emails and links
|
||||
@@ -117,14 +125,14 @@ class FormSubmissionFormatter
|
||||
$formId = $this->form->id;
|
||||
$returnArray[$field['name']] = implode(', ',
|
||||
collect($data[$field['id']])->map(function ($file) use ($formId) {
|
||||
return route('open.forms.submissions.file', [$formId, $file]);
|
||||
return $this->getFileUrl($formId, $file);
|
||||
})->toArray()
|
||||
);
|
||||
} else {
|
||||
$formId = $this->form->id;
|
||||
$returnArray[$field['name']] = collect($data[$field['id']])->map(function ($file) use ($formId) {
|
||||
return [
|
||||
'file_url' => route('open.forms.submissions.file', [$formId, $file]),
|
||||
'file_url' => $this->getFileUrl($formId, $file),
|
||||
'file_name' => $file,
|
||||
];
|
||||
});
|
||||
@@ -185,14 +193,22 @@ class FormSubmissionFormatter
|
||||
$formId = $this->form->id;
|
||||
$field['value'] = implode(', ',
|
||||
collect($data[$field['id']])->map(function ($file) use ($formId) {
|
||||
return route('open.forms.submissions.file', [$formId, $file]);
|
||||
return $this->getFileUrl($formId, $file);
|
||||
})->toArray()
|
||||
);
|
||||
$field['email_data'] = collect($data[$field['id']])->map(function ($file) use ($formId) {
|
||||
$splitText = explode('.', $file);
|
||||
return [
|
||||
"unsigned_url" => route('open.forms.submissions.file', [$formId, $file]),
|
||||
"signed_url" => $this->getFileUrl($formId, $file),
|
||||
"label" => \Str::limit($file, 20, '[...].'.end($splitText))
|
||||
];
|
||||
})->toArray();
|
||||
} else {
|
||||
$formId = $this->form->id;
|
||||
$field['value'] = collect($data[$field['id']])->map(function ($file) use ($formId) {
|
||||
return [
|
||||
'file_url' => route('open.forms.submissions.file', [$formId, $file]),
|
||||
'file_url' => $this->getFileUrl($formId, $file),
|
||||
'file_name' => $file,
|
||||
];
|
||||
});
|
||||
@@ -222,4 +238,11 @@ class FormSubmissionFormatter
|
||||
}
|
||||
}
|
||||
|
||||
private function getFileUrl($formId, $file)
|
||||
{
|
||||
return $this->useSignedUrlForFiles ? \URL::signedRoute(
|
||||
'open.forms.submissions.file',
|
||||
[$formId, $file]) : route('open.forms.submissions.file', [$formId, $file]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user