From ee0a7a07fcccb6c91e912ee7a0e9c632bdc4ad70 Mon Sep 17 00:00:00 2001 From: James Sessford Date: Thu, 25 Apr 2024 19:47:39 +0100 Subject: [PATCH] Updated authorizeAccess function to check the resource you're trying to create Updated tenant checks in handleRecordCreation and associateRecordWithTenant to check the resource you're trying to create --- src/Pages/CreateRelatedRecord.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Pages/CreateRelatedRecord.php b/src/Pages/CreateRelatedRecord.php index 37c4306..aa47aa6 100644 --- a/src/Pages/CreateRelatedRecord.php +++ b/src/Pages/CreateRelatedRecord.php @@ -81,8 +81,7 @@ public function getRecord(): Model protected function authorizeAccess(): void { - // TODO: maybe need to switch resource to other resource - abort_unless(static::getResource()::canCreate(), 403); + abort_unless(Filament::getModelResource($this->getRelation()->getRelated())::canCreate(), 403); } protected function fillForm(): void @@ -181,7 +180,7 @@ protected function handleRecordCreation(array $data): Model } if ( - static::getResource()::isScopedToTenant() && + Filament::getModelResource($record)::isScopedToTenant() && ($tenant = Filament::getTenant()) ) { return $this->associateRecordWithTenant($record, $tenant); @@ -207,7 +206,7 @@ protected function associateRecordWithParent(Model $record, Model $owner) protected function associateRecordWithTenant(Model $record, Model $tenant): Model { - $relationship = static::getResource()::getTenantRelationship($tenant); + $relationship = Filament::getModelResource($record)::getTenantRelationship($tenant); if ($relationship instanceof HasManyThrough) { $record->save();