From 45fb11455427f67552b7bfbbb655061487043ce5 Mon Sep 17 00:00:00 2001 From: Chirag Chhatrala <60499540+chiragchhatrala@users.noreply.github.com> Date: Fri, 28 Apr 2023 15:03:16 +0530 Subject: [PATCH] Fix Policy conditions (#117) --- app/Policies/FormPolicy.php | 10 +++++----- app/Policies/Integration/FormZapierWebhookPolicy.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Policies/FormPolicy.php b/app/Policies/FormPolicy.php index 74c82e9..5a06b39 100644 --- a/app/Policies/FormPolicy.php +++ b/app/Policies/FormPolicy.php @@ -30,7 +30,7 @@ class FormPolicy */ public function view(User $user, Form $form) { - return $user->workspaces()->find($form->workspace_id)->exists(); + return $user->workspaces()->find($form->workspace_id) !== null; } /** @@ -53,7 +53,7 @@ class FormPolicy */ public function update(User $user, Form $form) { - return $user->workspaces()->find($form->workspace_id)->exists(); + return $user->workspaces()->find($form->workspace_id) !== null; } /** @@ -65,7 +65,7 @@ class FormPolicy */ public function delete(User $user, Form $form) { - return $user->workspaces()->find($form->workspace_id)->exists(); + return $user->workspaces()->find($form->workspace_id) !== null; } /** @@ -77,7 +77,7 @@ class FormPolicy */ public function restore(User $user, Form $form) { - return $user->workspaces()->find($form->workspace_id)->exists(); + return $user->workspaces()->find($form->workspace_id) !== null; } /** @@ -89,6 +89,6 @@ class FormPolicy */ public function forceDelete(User $user, Form $form) { - return $user->workspaces()->find($form->workspace_id)->exists(); + return $user->workspaces()->find($form->workspace_id) !== null; } } diff --git a/app/Policies/Integration/FormZapierWebhookPolicy.php b/app/Policies/Integration/FormZapierWebhookPolicy.php index e90df2b..7d04dc8 100644 --- a/app/Policies/Integration/FormZapierWebhookPolicy.php +++ b/app/Policies/Integration/FormZapierWebhookPolicy.php @@ -20,11 +20,11 @@ class FormZapierWebhookPolicy public function store(User $user, FormZapierWebhook $webhook) { - return $this->formPolicy->update($user, $webhook->form); // && $user->is_subscribed; + return ($webhook?->form) ? $this->formPolicy->update($user, $webhook->form) : false; // && $user->is_subscribed; } public function delete(User $user, FormZapierWebhook $webhook) { - return $this->formPolicy->update($user, $webhook->form); // && $user->is_subscribed; + return ($webhook?->form) ? $this->formPolicy->update($user, $webhook->form) : false; // && $user->is_subscribed; } }