diff --git a/TODO b/TODO index 0f9cb06..e2a224a 100644 --- a/TODO +++ b/TODO @@ -7,4 +7,5 @@ Todo: ☐ Make use of the custom team foreign key ☐ checking for tables also check if team was enabled or should be enabled if already installed and the tenant flag provided ☐ Remove/replace doctor command with about command - ☐ Move tenant relationship generation to the generate command \ No newline at end of file + ☐ Move tenant relationship generation to the generate command + ☐ should handle if already installed for a panel but central flag. for now central is always false \ No newline at end of file diff --git a/src/Commands/Concerns/CanGenerateRelationshipsForTenancy.php b/src/Commands/Concerns/CanGenerateRelationshipsForTenancy.php index 719214e..da99095 100644 --- a/src/Commands/Concerns/CanGenerateRelationshipsForTenancy.php +++ b/src/Commands/Concerns/CanGenerateRelationshipsForTenancy.php @@ -70,8 +70,8 @@ protected function generateRelationships(Panel $panel): void } if (! $tenantModelstringer->contains($modifiedResource['tenant_model_method']['name'])) { if (filled($importStatement = $this->addModelReturnTypeImportStatement($modifiedResource['tenant_model_method']['relationshipName']))) { - if (! $resourceModelStringer->contains($importStatement)) { - $resourceModelStringer->append('use', $importStatement); + if (! $tenantModelstringer->contains($importStatement)) { + $tenantModelstringer->append('use', $importStatement); } } diff --git a/src/Commands/Concerns/CanMakePanelTenantable.php b/src/Commands/Concerns/CanMakePanelTenantable.php index 5886819..f250b64 100644 --- a/src/Commands/Concerns/CanMakePanelTenantable.php +++ b/src/Commands/Concerns/CanMakePanelTenantable.php @@ -9,12 +9,12 @@ trait CanMakePanelTenantable { - protected function makePanelTenantable(Panel $panel, string $panelPath, ?string $tenantModel): void + protected function makePanelTenantable(Panel $panel, string $panelPath, ?string $tenantModelClass): void { - if (filled($tenantModel) && ! $panel->hasTenancy()) { + if (filled($tenantModelClass) && ! $panel->hasTenancy()) { Stringer::for($panelPath) - ->prepend('->discoverResources', '->tenant(\\' . $tenantModel . '::class)') + ->prepend('->discoverResources', '->tenant(' . $tenantModelClass . ')') ->save(); $this->activateTenancy($panelPath); diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index 298f03f..a26a2d2 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -18,19 +18,24 @@ class InstallCommand extends Command implements PromptsForMissingInput use Concerns\CanRegisterPlugin; /** @var string */ - protected $signature = 'shield:install {panel} {--central} {--tenant} {--generate}'; + protected $signature = 'shield:install {panel} {--tenant} {--generate}'; /** @var string */ protected $description = 'Install and configure shield for the given Filament Panel'; public function handle(): int { - $shouldSetPanelAsCentralApp = $this->option('central') ?? false; + $shouldSetPanelAsCentralApp = false; $panel = Filament::getPanel($this->argument('panel') ?? null); $tenant = $this->option('tenant') ? config()->get('filament-shield.tenant_model') : null; + $tenantModelClass = str($tenant) + ->prepend('\\') + ->append('::class') + ->toString(); + $panelPath = app_path( (string) str($panel->getId()) ->studly() @@ -46,31 +51,31 @@ public function handle(): int return static::FAILURE; } - if ($panel->hasTenancy() && $shouldSetPanelAsCentralApp) { - $this->components->warn('Cannot install Shield as `Central App` on a tenant panel!'); - return static::FAILURE; - } + // if ($panel->hasTenancy() && $shouldSetPanelAsCentralApp) { + // $this->components->warn('Cannot install Shield as `Central App` on a tenant panel!'); + // return static::FAILURE; + // } - if (! $panel->hasTenancy() && $shouldSetPanelAsCentralApp && blank($tenant)) { - $this->components->warn('Make sure you have at least a panel with tenancy setup first!'); - return static::INVALID; - } + // if (! $panel->hasTenancy() && $shouldSetPanelAsCentralApp && blank($tenant)) { + // $this->components->warn('Make sure you have at least a panel with tenancy setup first!'); + // return static::INVALID; + // } $this->registerPlugin( panelPath: $panelPath, centralApp: $shouldSetPanelAsCentralApp && ! $panel->hasTenancy(), - tenantModelClass: $tenant + tenantModelClass: $tenantModelClass ); - if (filled($tenant)) { + if (filled($tenant) && ! $shouldSetPanelAsCentralApp) { $this->makePanelTenantable( panel: $panel, panelPath: $panelPath, - tenantModel: $tenant + tenantModelClass: $tenantModelClass ); } - if ($this->option('generate')) { + if (filled($tenant) && $this->option('generate')) { $this->generateRelationships($panel); }