From 80c969edf8885664b17695d2c42787214a82cc36 Mon Sep 17 00:00:00 2001 From: Eleazar Resendez Date: Mon, 31 Jul 2023 11:54:44 -0600 Subject: [PATCH] Fix issue when pm-blocks-package is not installed --- ProcessMaker/Policies/ProcessPolicy.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ProcessMaker/Policies/ProcessPolicy.php b/ProcessMaker/Policies/ProcessPolicy.php index e3cfa10e13..953bc6c756 100644 --- a/ProcessMaker/Policies/ProcessPolicy.php +++ b/ProcessMaker/Policies/ProcessPolicy.php @@ -3,7 +3,6 @@ namespace ProcessMaker\Policies; use Illuminate\Auth\Access\HandlesAuthorization; -use Illuminate\Http\Request; use ProcessMaker\Models\AnonymousUser; use ProcessMaker\Models\Group; use ProcessMaker\Models\GroupMember; @@ -30,7 +29,7 @@ public function before(User $user) public function edit(User $user, Process $process) { - if ($process->pmBlock?->is_imported_locked) { + if ($this->isPmBlockImportedLocked($process)) { return false; } @@ -131,4 +130,15 @@ public function editData(User $user, Process $process) return false; } + + /** + * Check if the PM Block package is installed and if so, + * it checks if the related pmBlock of the given Process is imported and locked. + */ + private function isPmBlockImportedLocked(Process $process): bool + { + $className = 'ProcessMaker\Package\PackagePmBlocks\Models\PmBlock'; + + return class_exists($className) && $process->pmBlock?->is_imported_locked; + } }