## Summary - replace the legacy Tenant and TenantMembership core models with ManagedEnvironment and ManagedEnvironmentMembership - propagate the managed environment naming and key changes across Filament resources, pages, controllers, jobs, models, and supporting runtime paths - add feature 279 spec artifacts and focused managed-environment test coverage for model behavior, route binding, panel context, authorization, and legacy guardrails ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentAuthorizationTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentPanelContextTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentRouteBindingTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentContextResolverTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php` - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` ## Notes - branch pushed from commit `1123b122` - browser smoke test file was added but not run in this pass Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #335
86 lines
3.0 KiB
PHP
86 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\AlertDelivery;
|
|
use App\Models\AlertDestination;
|
|
use App\Models\AlertRule;
|
|
use App\Models\PlatformUser;
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\TenantOnboardingSession;
|
|
use App\Models\TenantReview;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Models\WorkspaceSetting;
|
|
use App\Policies\AlertDeliveryPolicy;
|
|
use App\Policies\AlertDestinationPolicy;
|
|
use App\Policies\AlertRulePolicy;
|
|
use App\Policies\ProviderConnectionPolicy;
|
|
use App\Policies\TenantOnboardingSessionPolicy;
|
|
use App\Policies\TenantReviewPolicy;
|
|
use App\Policies\WorkspaceSettingPolicy;
|
|
use App\Services\Auth\CapabilityResolver;
|
|
use App\Services\Auth\WorkspaceCapabilityResolver;
|
|
use App\Support\Auth\Capabilities;
|
|
use App\Support\Auth\PlatformCapabilities;
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
{
|
|
protected $policies = [
|
|
ProviderConnection::class => ProviderConnectionPolicy::class,
|
|
TenantOnboardingSession::class => TenantOnboardingSessionPolicy::class,
|
|
TenantReview::class => TenantReviewPolicy::class,
|
|
WorkspaceSetting::class => WorkspaceSettingPolicy::class,
|
|
AlertDestination::class => AlertDestinationPolicy::class,
|
|
AlertDelivery::class => AlertDeliveryPolicy::class,
|
|
AlertRule::class => AlertRulePolicy::class,
|
|
];
|
|
|
|
public function boot(): void
|
|
{
|
|
$this->registerPolicies();
|
|
|
|
$tenantResolver = app(CapabilityResolver::class);
|
|
$workspaceResolver = app(WorkspaceCapabilityResolver::class);
|
|
|
|
$defineTenantCapability = function (string $capability) use ($tenantResolver): void {
|
|
Gate::define($capability, function (User $user, ?ManagedEnvironment $tenant = null) use ($tenantResolver, $capability): bool {
|
|
if (! $tenant instanceof ManagedEnvironment) {
|
|
return false;
|
|
}
|
|
|
|
return $tenantResolver->can($user, $tenant, $capability);
|
|
});
|
|
};
|
|
|
|
$defineWorkspaceCapability = function (string $capability) use ($workspaceResolver): void {
|
|
Gate::define($capability, function (User $user, ?Workspace $workspace = null) use ($workspaceResolver, $capability): bool {
|
|
if (! $workspace instanceof Workspace) {
|
|
return false;
|
|
}
|
|
|
|
return $workspaceResolver->can($user, $workspace, $capability);
|
|
});
|
|
};
|
|
|
|
foreach (Capabilities::all() as $capability) {
|
|
if (str_starts_with($capability, 'workspace')) {
|
|
$defineWorkspaceCapability($capability);
|
|
|
|
continue;
|
|
}
|
|
|
|
$defineTenantCapability($capability);
|
|
}
|
|
|
|
foreach (PlatformCapabilities::all() as $capability) {
|
|
Gate::define($capability, function (PlatformUser $user) use ($capability): bool {
|
|
return $user->hasCapability($capability);
|
|
});
|
|
}
|
|
}
|
|
}
|