Skip to content

Commit 480420a

Browse files
authored
Merge branch 'main' into crisp-migration
2 parents 1316e9a + de3e2d6 commit 480420a

File tree

7 files changed

+68
-22
lines changed

7 files changed

+68
-22
lines changed

app/Http/Controllers/Forms/FormSubmissionController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function export(string $id)
3737
$formatter = (new FormSubmissionFormatter($form, $row['data']))
3838
->outputStringsOnly()
3939
->setEmptyForNoValue()
40-
->showRemovedFields();
40+
->showRemovedFields()
41+
->useSignedUrlForFiles();
4142
$tmp = $formatter->getCleanKeyValue();
4243
$tmp['Create Date'] = date("Y-m-d H:i", strtotime($row['created_at']));
4344
$allRows[] = $tmp;

app/Mail/Forms/SubmissionConfirmationMail.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function build()
3535

3636
$formatter = (new FormSubmissionFormatter($form, $this->event->data))
3737
->createLinks()
38-
->outputStringsOnly();
38+
->outputStringsOnly()
39+
->useSignedUrlForFiles();
3940

4041
return $this
4142
->replyTo($this->getReplyToEmail($form->creator->email))

app/Notifications/Forms/FormSubmissionNotification.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public function toMail($notifiable)
4949
$formatter = (new FormSubmissionFormatter($this->event->form, $this->event->data))
5050
->showHiddenFields()
5151
->createLinks()
52-
->outputStringsOnly();
52+
->outputStringsOnly()
53+
->useSignedUrlForFiles();
5354

5455
return (new MailMessage)
5556
->replyTo($this->getReplyToEmail($notifiable->routes['mail']))

app/Service/Forms/FormSubmissionFormatter.php

+27-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class FormSubmissionFormatter
2929

3030
private $showRemovedFields = false;
3131

32+
private $useSignedUrlForFiles = false;
33+
3234
/**
3335
* Logic resolver needs an array id => value, so we create it here
3436
*/
@@ -69,6 +71,12 @@ public function showRemovedFields()
6971
return $this;
7072
}
7173

74+
public function useSignedUrlForFiles()
75+
{
76+
$this->useSignedUrlForFiles = true;
77+
return $this;
78+
}
79+
7280
/**
7381
* Return a nice "FieldName": "Field Response" array
7482
* - If createLink enabled, returns html link for emails and links
@@ -117,14 +125,14 @@ public function getCleanKeyValue()
117125
$formId = $this->form->id;
118126
$returnArray[$field['name']] = implode(', ',
119127
collect($data[$field['id']])->map(function ($file) use ($formId) {
120-
return route('open.forms.submissions.file', [$formId, $file]);
128+
return $this->getFileUrl($formId, $file);
121129
})->toArray()
122130
);
123131
} else {
124132
$formId = $this->form->id;
125133
$returnArray[$field['name']] = collect($data[$field['id']])->map(function ($file) use ($formId) {
126134
return [
127-
'file_url' => route('open.forms.submissions.file', [$formId, $file]),
135+
'file_url' => $this->getFileUrl($formId, $file),
128136
'file_name' => $file,
129137
];
130138
});
@@ -185,14 +193,22 @@ public function getFieldsWithValue()
185193
$formId = $this->form->id;
186194
$field['value'] = implode(', ',
187195
collect($data[$field['id']])->map(function ($file) use ($formId) {
188-
return route('open.forms.submissions.file', [$formId, $file]);
196+
return $this->getFileUrl($formId, $file);
189197
})->toArray()
190198
);
199+
$field['email_data'] = collect($data[$field['id']])->map(function ($file) use ($formId) {
200+
$splitText = explode('.', $file);
201+
return [
202+
"unsigned_url" => route('open.forms.submissions.file', [$formId, $file]),
203+
"signed_url" => $this->getFileUrl($formId, $file),
204+
"label" => \Str::limit($file, 20, '[...].'.end($splitText))
205+
];
206+
})->toArray();
191207
} else {
192208
$formId = $this->form->id;
193209
$field['value'] = collect($data[$field['id']])->map(function ($file) use ($formId) {
194210
return [
195-
'file_url' => route('open.forms.submissions.file', [$formId, $file]),
211+
'file_url' => $this->getFileUrl($formId, $file),
196212
'file_name' => $file,
197213
];
198214
});
@@ -222,4 +238,11 @@ private function initIdFormData() {
222238
}
223239
}
224240

241+
private function getFileUrl($formId, $file)
242+
{
243+
return $this->useSignedUrlForFiles ? \URL::signedRoute(
244+
'open.forms.submissions.file',
245+
[$formId, $file]) : route('open.forms.submissions.file', [$formId, $file]);
246+
}
247+
225248
}

client/components/forms/PhoneInput.vue

+21-11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ export default {
9393
}
9494
}
9595
},
96+
compVal(newVal, oldVal){
97+
this.initState()
98+
},
9699
selectedCountryCode (newVal, oldVal) {
97100
if (this.compVal && newVal && oldVal) {
98101
this.compVal = this.compVal.replace(oldVal.code + oldVal.dial_code, newVal.code + newVal.dial_code)
@@ -102,17 +105,7 @@ export default {
102105
103106
mounted () {
104107
if (this.compVal) {
105-
if (!this.compVal.startsWith('+')) {
106-
this.selectedCountryCode = this.getCountryBy(this.compVal.substring(2, 0))
107-
}
108-
109-
const phoneObj = parsePhoneNumber(this.compVal)
110-
if (phoneObj !== undefined && phoneObj) {
111-
if (!this.selectedCountryCode && phoneObj.country !== undefined && phoneObj.country) {
112-
this.selectedCountryCode = this.getCountryBy(phoneObj.country)
113-
}
114-
this.inputVal = phoneObj.nationalNumber
115-
}
108+
this.initState()
116109
}
117110
if (!this.selectedCountryCode) {
118111
this.selectedCountryCode = this.getCountryBy()
@@ -131,6 +124,7 @@ export default {
131124
},
132125
onInput (event) {
133126
this.inputVal = event?.target?.value.replace(/[^0-9]/g, '')
127+
134128
},
135129
onChangeCountryCode () {
136130
if (!this.selectedCountryCode && this.countries.length > 0) {
@@ -139,6 +133,22 @@ export default {
139133
if (this.canOnlyCountry && (this.inputVal === null || this.inputVal === '' || !this.inputVal)) {
140134
this.compVal = this.selectedCountryCode.code + this.selectedCountryCode.dial_code
141135
}
136+
},
137+
initState() {
138+
if(this.compVal === null){
139+
return;
140+
}
141+
if (!this.compVal.startsWith('+')) {
142+
this.selectedCountryCode = this.getCountryBy(this.compVal.substring(2, 0))
143+
}
144+
145+
const phoneObj = parsePhoneNumber(this.compVal)
146+
if (phoneObj !== undefined && phoneObj) {
147+
if (!this.selectedCountryCode && phoneObj.country !== undefined && phoneObj.country) {
148+
this.selectedCountryCode = this.getCountryBy(phoneObj.country)
149+
}
150+
this.inputVal = phoneObj.nationalNumber
151+
}
142152
}
143153
}
144154
}

resources/views/mail/form/confirmation-submission-notification.blade.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
--------------------------------------------------------------------------------
1818

1919
**{{$field['name']}}**
20-
20+
@if($field['type'] == 'files')
21+
<br/>
22+
@foreach($field['email_data'] as $link)
23+
<a href="{{$link['signed_url']}}">{{$link['label']}}</a> <br/>
24+
@endforeach
25+
@else
2126
{!! is_array($field['value'])?implode(',',$field['value']):$field['value']!!}
22-
27+
@endif
2328
@endif
2429
@endforeach
2530
@endif

resources/views/mail/form/submission-notification.blade.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
--------------------------------------------------------------------------------
1111

1212
**{{$field['name']}}**
13-
13+
@if($field['type'] == 'files')
14+
<br/>
15+
@foreach($field['email_data'] as $link)
16+
<a href="{{$link['signed_url']}}">{{$link['label']}}</a> <br/>
17+
@endforeach
18+
@else
1419
{!! is_array($field['value'])?implode(',',$field['value']):$field['value']!!}
15-
20+
@endif
1621
@endif
1722
@endforeach
1823

0 commit comments

Comments
 (0)