Skip to content

Commit f4538c9

Browse files
Merge pull request #3 from j-jalving/main
Fix permissions check typo in update method
2 parents c2be265 + 85240b3 commit f4538c9

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

config/statamic/zapier.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Disable Calls
7+
|--------------------------------------------------------------------------
8+
|
9+
| When set to true, no webhooks will be called
10+
|
11+
*/
12+
13+
"disable_webhooks" => env('ZAPIER_DISABLE_WEBHOOKS', false),
14+
15+
/*
16+
|--------------------------------------------------------------------------
17+
| Force URL
18+
|--------------------------------------------------------------------------
19+
|
20+
| When set, all zapier webhooks will use this URL. This can be used to
21+
| redirect all calls in a dev environment to a single test URL.
22+
|
23+
*/
24+
25+
"force_url" => env('ZAPIER_FORCE_URL', null),
26+
27+
];

src/Http/Controllers/WebhooksController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function edit()
3333

3434
public function update(Request $request)
3535
{
36-
abort_unless(User::current()->can('configure form zapier webshooks'), 403);
36+
abort_unless(User::current()->can('configure form zapier webhooks'), 403);
3737

3838
$blueprint = Webhooks::blueprint();
3939

src/Listeners/PushToWebhook.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function handle(FormSubmitted $event)
2020
{
2121
$webhooks = Webhooks::byForm($event->submission->form->handle());
2222

23-
if (is_null($webhooks)) return;
23+
if (is_null($webhooks) || config('statamic.zapier.disable_webhooks')) return;
2424

2525
foreach ($webhooks as $webhook) {
2626
$this->sendToWebhook($webhook['webhook'], $event);
@@ -32,6 +32,10 @@ public function handle(FormSubmitted $event)
3232
*/
3333
private function sendToWebhook($webhookUrl, FormSubmitted $event)
3434
{
35+
36+
// Overwrite webhook url with force url if set in config
37+
$webhookUrl = config('statamic.zapier.force_url') ?? $webhookUrl;
38+
3539
// all data
3640
$data = $event->submission->data();
3741
$data['submission_id'] = $event->submission->id();

src/ServiceProvider.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public function boot()
2323
{
2424
parent::boot();
2525

26-
// // load views
26+
// load publishables
27+
$this->bootPublishables();
28+
29+
// load views
2730
$this->loadViewsFrom(__DIR__ . '/../resources/views/', 'statamic-zapier');
2831

2932
// load navigation
@@ -35,6 +38,17 @@ public function boot()
3538
});
3639
}
3740

41+
public function bootPublishables(): static
42+
{
43+
if ($this->app->runningInConsole()) {
44+
$this->publishes([
45+
__DIR__.'/../config/statamic/zapier.php' => config_path('/statamic/zapier.php'),
46+
], 'config');
47+
}
48+
49+
return $this;
50+
}
51+
3852
private function bootNavigation(): void
3953
{
4054
Nav::extend(function ($nav) {

0 commit comments

Comments
 (0)