Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Tenant selection visibility #446

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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