Skip to content

Commit

Permalink
[Fix] Tenant selection visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhanSalleh committed Nov 14, 2024
1 parent 3fef80f commit 1002918
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Commands/SuperAdminCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function handle(): int
$this->superAdmin = $this->createSuperAdmin();
}

if (Utils::isTeamFeatureEnabled()) {
if (Utils::isTenancyEnabled()) {
if (blank($tenantId)) {
$this->components->error('Please provide the team/tenant id via `--tenant` option to assign the super admin to a team/tenant.');

Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/HasAboutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function initAboutCommand()
// 'Resource Sort' => Utils::getResourceNavigationSort(),
// 'Resource Badge' => Utils::isResourceNavigationBadgeEnabled() ? '<fg=green;options=bold>ENABLED</>' : '<fg=red;options=bold>DISABLED</>',
// 'Resource Group' => Utils::isResourceNavigationGroupEnabled() ? '<fg=green;options=bold>ENABLED</>' : '<fg=red;options=bold>DISABLED</>',
'Tenancy' => Utils::isTeamFeatureEnabled() ? '<fg=green;options=bold>ENABLED</>' : '<fg=gray;options=bold>DISABLED</>',
'Tenant Model' => Utils::isTeamFeatureEnabled() && filled($model = config()->get('filament-shield.tenant_model')) ? $model : null,
'Tenancy' => Utils::isTenancyEnabled() ? '<fg=green;options=bold>ENABLED</>' : '<fg=gray;options=bold>DISABLED</>',
'Tenant Model' => Utils::isTenancyEnabled() && filled($model = config()->get('filament-shield.tenant_model')) ? $model : null,
'Translations' => is_dir(resource_path('resource/lang/vendor/filament-shield')) ? '<fg=red;options=bold>PUBLISHED</>' : '<fg=green;options=bold>NOT PUBLISHED</>',
'Views' => is_dir(resource_path('views/vendor/filament-shield')) ? '<fg=red;options=bold>PUBLISHED</>' : '<fg=green;options=bold>NOT PUBLISHED</>',
'Version' => InstalledVersions::getPrettyVersion('bezhansalleh/filament-shield'),
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentShield.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected static function giveSuperAdminPermission(string | array | Collection $

public static function createRole(?string $name = null, ?int $tenantId = null): Role
{
if (Utils::isTeamFeatureEnabled()) {
if (Utils::isTenancyEnabled()) {
return Utils::getRoleModel()::firstOrCreate(
[
'name' => $name ?? Utils::getSuperAdminName(),
Expand Down
7 changes: 3 additions & 4 deletions src/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ public static function form(Form $form): Form
/** @phpstan-ignore-next-line */
->default([Filament::getTenant()?->id])
->options(fn (): Arrayable => Utils::getTenantModel() ? Utils::getTenantModel()::pluck('name', 'id') : collect())
->hidden(fn (): bool => ! static::shield()->isCentralApp() && Filament::hasTenancy())
->dehydrated(fn (): bool => ! static::shield()->isCentralApp() && Filament::hasTenancy()),

->hidden(fn (): bool => ! (static::shield()->isCentralApp() && Utils::isTenancyEnabled()))
->dehydrated(fn (): bool => ! (static::shield()->isCentralApp() && Utils::isTenancyEnabled())),
ShieldSelectAllToggle::make('select_all')
->onIcon('heroicon-s-shield-check')
->offIcon('heroicon-s-shield-exclamation')
Expand Down Expand Up @@ -100,7 +99,7 @@ public static function table(Table $table): Table
->color(fn (mixed $state): string => str($state)->contains('Global') ? 'gray' : 'primary')
->label(__('filament-shield::filament-shield.column.team'))
->searchable()
->visible(fn (): bool => static::shield()->isCentralApp() && ! Filament::hasTenancy()),
->visible(fn (): bool => static::shield()->isCentralApp() && Utils::isTenancyEnabled()),
Tables\Columns\TextColumn::make('permissions_count')
->badge()
->label(__('filament-shield::filament-shield.column.permissions'))
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ protected static function isRolePolicyGenerated(): bool
return (bool) $filesystem->exists(app_path(static::getPolicyPath() . DIRECTORY_SEPARATOR . 'RolePolicy.php'));
}

public static function isTeamFeatureEnabled(): bool
public static function isTenancyEnabled(): bool
{
return (bool) config()->get('permission.teams', false);
}
Expand Down

0 comments on commit 1002918

Please sign in to comment.