Skip to content

Beautiful Open-Source Form Builder

zapier improvements (#532)

Chirag Chhatrala943e906c86af
diff --git a/app/Http/Requests/Integration/Zapier/PollSubmissionRequest.php b/app/Http/Requests/Integration/Zapier/PollSubmissionRequest.php
index 27089e0ca..14898aa19 100644
--- a/app/Http/Requests/Integration/Zapier/PollSubmissionRequest.php
+++ b/app/Http/Requests/Integration/Zapier/PollSubmissionRequest.php
@@ -18,15 +18,13 @@ class PollSubmissionRequest extends FormRequest
return [
'form_id' => [
'required',
- Rule::exists(Form::getModel()->getTable(), 'slug'),
+ Rule::exists(Form::getModel()->getTable(), 'id'),
],
];
}
public function form(): Form
{
- return Form::query()
- ->where('slug', $this->input('form_id'))
- ->firstOrFail();
+ return Form::findOrFail($this->input('form_id'));
}
}
diff --git a/app/Http/Requests/Zapier/CreateIntegrationRequest.php b/app/Http/Requests/Zapier/CreateIntegrationRequest.php
index f1e074a8d..da70daf10 100644
--- a/app/Http/Requests/Zapier/CreateIntegrationRequest.php
+++ b/app/Http/Requests/Zapier/CreateIntegrationRequest.php
@@ -13,7 +13,7 @@ class CreateIntegrationRequest extends FormRequest
return [
'form_id' => [
'required',
- Rule::exists(Form::getModel()->getTable(), 'slug'),
+ Rule::exists(Form::getModel()->getTable(), 'id'),
],
'hookUrl' => [
'required',
@@ -24,8 +24,6 @@ class CreateIntegrationRequest extends FormRequest
public function form(): Form
{
- return Form::query()
- ->where('slug', $this->input('form_id'))
- ->firstOrFail();
+ return Form::findOrFail($this->input('form_id'));
}
}
diff --git a/app/Http/Requests/Zapier/DeleteIntegrationRequest.php b/app/Http/Requests/Zapier/DeleteIntegrationRequest.php
index 5c63f2b94..0510160a8 100644
--- a/app/Http/Requests/Zapier/DeleteIntegrationRequest.php
+++ b/app/Http/Requests/Zapier/DeleteIntegrationRequest.php
@@ -13,7 +13,7 @@ class DeleteIntegrationRequest extends FormRequest
return [
'form_id' => [
'required',
- Rule::exists(Form::getModel()->getTable(), 'slug'),
+ Rule::exists(Form::getModel()->getTable(), 'id'),
],
'hookUrl' => [
'required',
@@ -24,8 +24,6 @@ class DeleteIntegrationRequest extends FormRequest
public function form(): Form
{
- return Form::query()
- ->where('slug', $this->input('form_id'))
- ->firstOrFail();
+ return Form::findOrFail($this->input('form_id'));
}
}
diff --git a/app/Http/Resources/Zapier/FormResource.php b/app/Http/Resources/Zapier/FormResource.php
index ee3dfa85a..c9ed5e76a 100644
--- a/app/Http/Resources/Zapier/FormResource.php
+++ b/app/Http/Resources/Zapier/FormResource.php
@@ -12,8 +12,9 @@ class FormResource extends JsonResource
public function toArray($request)
{
return [
- 'id' => $this->resource->slug,
+ 'id' => $this->resource->id,
'name' => $this->resource->title,
+ 'label' => $this->resource->title . ' (' . $this->resource->slug . ')'
];
}
}
diff --git a/integrations/zapier/triggers/new_submission.js b/integrations/zapier/triggers/new_submission.js
index 14af71ea8..52c6d3f85 100644
--- a/integrations/zapier/triggers/new_submission.js
+++ b/integrations/zapier/triggers/new_submission.js
@@ -37,7 +37,7 @@ module.exports = {
key: 'form_id',
type: 'string',
label: 'Form',
- dynamic: 'list_forms.id.name',
+ dynamic: 'list_forms.id.label',
required: true,
list: false,
altersDynamicFields: false,
diff --git a/tests/Feature/Zapier/IntegrationsTest.php b/tests/Feature/Zapier/IntegrationsTest.php
index 6d8c2f8e4..3dec3bb5b 100644
--- a/tests/Feature/Zapier/IntegrationsTest.php
+++ b/tests/Feature/Zapier/IntegrationsTest.php
@@ -23,7 +23,7 @@ test('create an integration', function () {
$this->withoutExceptionHandling();
post(route('zapier.webhooks.store'), [
- 'form_id' => $form->slug,
+ 'form_id' => $form->id,
'hookUrl' => $hookUrl = 'https://zapier.com/hook/test'
])
->assertOk();
@@ -45,7 +45,7 @@ test('cannot create an integration without a corresponding ability', function ()
Sanctum::actingAs($user);
post(route('zapier.webhooks.store'), [
- 'form_id' => $form->slug,
+ 'form_id' => $form->id,
'hookUrl' => 'https://zapier.com/hook/test'
])
->assertForbidden();
@@ -64,7 +64,7 @@ test('cannot create an integration for other users form', function () {
Sanctum::actingAs($user);
post(route('zapier.webhooks.store'), [
- 'form_id' => $form->slug,
+ 'form_id' => $form->id,
'hookUrl' => 'https://zapier.com/hook/test'
])
->assertForbidden();
@@ -94,7 +94,7 @@ test('delete an integration', function () {
assertDatabaseCount('form_integrations', 1);
delete(route('zapier.webhooks.destroy', $integration), [
- 'form_id' => $form->slug,
+ 'form_id' => $form->id,
'hookUrl' => $hookUrl,
])
->assertOk();
@@ -122,7 +122,7 @@ test('cannot delete an integration with an incorrect hook url', function () {
]);
delete(route('zapier.webhooks.destroy', $integration), [
- 'form_id' => $form->slug,
+ 'form_id' => $form->id,
'hookUrl' => 'https://google.com',
])
->assertOk();
@@ -178,7 +178,7 @@ test('poll for the latest submission', function () {
Sanctum::actingAs($user, ['view', 'manage-integrations']);
// Call the poll endpoint
- $response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->slug]));
+ $response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->id]));
// Assert the response status is OK
$response->assertOk();
@@ -229,7 +229,7 @@ test('make up a submission when polling without any submission', function () {
// Call the poll endpoint
$this->withoutExceptionHandling();
- $response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->slug]));
+ $response = $this->getJson(route('zapier.webhooks.poll', ['form_id' => $form->id]));
// Assert the response status is OK
$response->assertOk();
diff --git a/tests/Feature/Zapier/ListFormsTest.php b/tests/Feature/Zapier/ListFormsTest.php
index 57a6fab0f..674e5077e 100644
--- a/tests/Feature/Zapier/ListFormsTest.php
+++ b/tests/Feature/Zapier/ListFormsTest.php
@@ -22,11 +22,11 @@ test('list all forms of a given workspace', function () {
->assertJsonCount(2)
->assertJson([
[
- 'id' => $form1->slug,
+ 'id' => $form1->id,
'name' => $form1->title,
],
[
- 'id' => $form2->slug,
+ 'id' => $form2->id,
'name' => $form2->title,
],
]);