From 7505857ae4e78c721212190528072105ffd84145 Mon Sep 17 00:00:00 2001 From: payal-canyon Date: Fri, 18 Oct 2024 05:46:41 +0000 Subject: [PATCH] added permission for prospect conversion --- ...ed_permissions_for_prospect_conversion.php | 38 +++++++++++++++++++ .../ManageProspectConversionSettings.php | 5 ++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app-modules/prospect/database/migrations/2024_10_08_174318_seed_permissions_for_prospect_conversion.php diff --git a/app-modules/prospect/database/migrations/2024_10_08_174318_seed_permissions_for_prospect_conversion.php b/app-modules/prospect/database/migrations/2024_10_08_174318_seed_permissions_for_prospect_conversion.php new file mode 100644 index 000000000..c1559caa7 --- /dev/null +++ b/app-modules/prospect/database/migrations/2024_10_08_174318_seed_permissions_for_prospect_conversion.php @@ -0,0 +1,38 @@ + 'Prospect Conversion', + ]; + + private array $guards = [ + 'web', + 'api', + ]; + + public function up(): void + { + collect($this->guards) + ->each(function (string $guard) { + $permissions = Arr::except($this->permissions, keys: DB::table('permissions') + ->where('guard_name', $guard) + ->pluck('name') + ->all()); + + $this->createPermissions($permissions, $guard); + }); + } + + public function down(): void + { + collect($this->guards) + ->each(fn (string $guard) => $this->deletePermissions(array_keys($this->permissions), $guard)); + } +}; diff --git a/app-modules/prospect/src/Filament/Pages/ManageProspectConversionSettings.php b/app-modules/prospect/src/Filament/Pages/ManageProspectConversionSettings.php index 1195b8efb..9f5f37c30 100644 --- a/app-modules/prospect/src/Filament/Pages/ManageProspectConversionSettings.php +++ b/app-modules/prospect/src/Filament/Pages/ManageProspectConversionSettings.php @@ -37,7 +37,10 @@ class ManageProspectConversionSettings extends SettingsPage public static function canAccess(): bool { - return ProspectConversion::active(); + /** @var User $user */ + $user = auth()->user(); + + return ProspectConversion::active() && $user->can('prospect_conversion.manage'); } public function form(Form $form): Form