ESC-590 - Fix UUID and Auto Increment ID Generation Logic in StoreFormSubmissio… (#774)
* Fix UUID and Auto Increment ID Generation Logic in StoreFormSubmissionJob - Updated the conditions for generating UUID and auto-increment IDs in the `StoreFormSubmissionJob` to ensure they only trigger when the answer value is not provided. This change enhances the logic for handling form submissions, particularly for users with non-pro subscriptions, by preventing unnecessary ID generation when an answer is already present. These modifications aim to improve the accuracy of form submissions and ensure proper handling of ID generation based on user subscription status. * Enhance ID Generation Logic in StoreFormSubmissionJob - Updated conditions for UUID and auto-increment ID generation in `StoreFormSubmissionJob` to ensure they only trigger when the answer value is either not provided or invalid. This change improves the accuracy of ID generation based on user subscription status, preventing unnecessary ID creation when valid input is present. These modifications aim to enhance the reliability of form submissions and ensure proper handling of ID generation features. * Test case
This commit is contained in:
parent
a140f789c2
commit
a11fb01bef
|
|
@ -179,9 +179,9 @@ class StoreFormSubmissionJob implements ShouldQueue
|
|||
}
|
||||
} else {
|
||||
// Standard field processing (text, ID generation, etc.)
|
||||
if ($field['type'] == 'text' && isset($field['generates_uuid']) && $field['generates_uuid']) {
|
||||
if ((!$answerValue || !Str::isUuid($answerValue)) && $field['type'] == 'text' && isset($field['generates_uuid']) && $field['generates_uuid']) {
|
||||
$finalData[$field['id']] = ($this->form->is_pro) ? Str::uuid()->toString() : 'Please upgrade your OpenForm subscription to use our ID generation features';
|
||||
} elseif ($field['type'] == 'text' && isset($field['generates_auto_increment_id']) && $field['generates_auto_increment_id']) {
|
||||
} elseif ((!$answerValue || !is_int($answerValue)) && $field['type'] == 'text' && isset($field['generates_auto_increment_id']) && $field['generates_auto_increment_id']) {
|
||||
$finalData[$field['id']] = ($this->form->is_pro) ? (string) ($this->form->submissions_count + 1) : 'Please upgrade your OpenForm subscription to use our ID generation features';
|
||||
} else {
|
||||
$finalData[$field['id']] = $answerValue;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
it('can update form with existing record', function () {
|
||||
$user = $this->actingAsProUser();
|
||||
|
|
@ -39,3 +39,56 @@ it('can update form with existing record', function () {
|
|||
expect($response->json('data.' . $nameProperty['id']))->toBe('Testing Updated');
|
||||
}
|
||||
});
|
||||
|
||||
it('can update form with existing record but generates_uuid field is not update', function () {
|
||||
$user = $this->actingAsProUser();
|
||||
$workspace = $this->createUserWorkspace($user);
|
||||
$form = $this->createForm($user, $workspace, [
|
||||
'editable_submissions' => true,
|
||||
'properties' => [
|
||||
[
|
||||
'id' => 'uuid_field',
|
||||
'type' => 'text',
|
||||
'generates_uuid' => true,
|
||||
'name' => 'UUID Field'
|
||||
],
|
||||
[
|
||||
'id' => 'name',
|
||||
'type' => 'text',
|
||||
'name' => 'Name'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$response = $this->postJson(route('forms.answer', $form->slug), ['name' => 'Testing', 'uuid_field' => null])
|
||||
->assertSuccessful()
|
||||
->assertJson([
|
||||
'type' => 'success',
|
||||
'message' => 'Form submission saved.',
|
||||
]);
|
||||
$submissionId = $response->json('submission_id');
|
||||
expect($submissionId)->toBeString();
|
||||
$response = $this->getJson(route('forms.fetchSubmission', [$form->slug, $submissionId]))
|
||||
->assertSuccessful();
|
||||
$uuid = $response->json('data.uuid_field');
|
||||
expect(Str::isUuid($uuid))->toBeTrue();
|
||||
|
||||
if ($submissionId) {
|
||||
$formData = $this->generateFormSubmissionData($form, ['submission_id' => $submissionId, 'name' => 'Testing Updated', 'uuid_field' => $uuid]);
|
||||
$response = $this->postJson(route('forms.answer', $form->slug), $formData)
|
||||
->assertSuccessful()
|
||||
->assertJson([
|
||||
'type' => 'success',
|
||||
'message' => 'Form submission saved.',
|
||||
]);
|
||||
$submissionId2 = $response->json('submission_id');
|
||||
expect($submissionId2)->toBeString();
|
||||
expect($submissionId2)->toBe($submissionId);
|
||||
|
||||
$response = $this->getJson(route('forms.fetchSubmission', [$form->slug, $submissionId]))
|
||||
->assertSuccessful();
|
||||
expect($response->json('data.name'))->toBe('Testing Updated');
|
||||
$uuid2 = $response->json('data.uuid_field');
|
||||
expect($uuid2)->toBe($uuid);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue