Skip to content

Commit

Permalink
outta time - todo - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhanSalleh committed Nov 6, 2024
1 parent 27cac36 commit 7e0e342
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
3 changes: 2 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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
☐ 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
4 changes: 2 additions & 2 deletions src/Commands/Concerns/CanGenerateRelationshipsForTenancy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Concerns/CanMakePanelTenantable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
33 changes: 19 additions & 14 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(),

Check failure on line 66 in src/Commands/InstallCommand.php

View workflow job for this annotation

GitHub Actions / phpstan

Left side of && is always false.
tenantModelClass: $tenant
tenantModelClass: $tenantModelClass
);

if (filled($tenant)) {
if (filled($tenant) && ! $shouldSetPanelAsCentralApp) {

Check failure on line 70 in src/Commands/InstallCommand.php

View workflow job for this annotation

GitHub Actions / phpstan

Negated boolean expression is always true.
$this->makePanelTenantable(
panel: $panel,
panelPath: $panelPath,
tenantModel: $tenant
tenantModelClass: $tenantModelClass
);
}

if ($this->option('generate')) {
if (filled($tenant) && $this->option('generate')) {
$this->generateRelationships($panel);
}

Expand Down

0 comments on commit 7e0e342

Please sign in to comment.