## Summary - move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling - update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location - add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation` - integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404` ## Remaining Rollout Checks - validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout - confirm web, queue, and scheduler processes all start from the expected working directory in staging/production - verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #213
103 lines
3.1 KiB
PHP
103 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\BackupSchedule;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Support\Auth\Capabilities;
|
|
use App\Support\OperateHub\OperateHubShell;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
use Illuminate\Auth\Access\Response;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class BackupSchedulePolicy
|
|
{
|
|
use HandlesAuthorization;
|
|
|
|
protected function isTenantMember(User $user, ?Tenant $tenant = null): bool
|
|
{
|
|
$tenant ??= $this->resolvedTenant();
|
|
|
|
return $tenant instanceof Tenant
|
|
&& Gate::forUser($user)->allows(Capabilities::TENANT_VIEW, $tenant);
|
|
}
|
|
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $this->isTenantMember($user);
|
|
}
|
|
|
|
public function view(User $user, BackupSchedule $schedule): Response|bool
|
|
{
|
|
$tenant = $this->resolvedTenant();
|
|
|
|
if (! $this->isTenantMember($user, $tenant)) {
|
|
return Response::denyAsNotFound();
|
|
}
|
|
|
|
return (int) $schedule->tenant_id === (int) $tenant->getKey()
|
|
? true
|
|
: Response::denyAsNotFound();
|
|
}
|
|
|
|
public function create(User $user): bool
|
|
{
|
|
$tenant = $this->resolvedTenant();
|
|
|
|
return $tenant instanceof Tenant
|
|
&& Gate::forUser($user)->allows(Capabilities::TENANT_BACKUP_SCHEDULES_MANAGE, $tenant);
|
|
}
|
|
|
|
public function update(User $user, BackupSchedule $schedule): Response|bool
|
|
{
|
|
return $this->authorizeScheduleAction($user, $schedule, Capabilities::TENANT_BACKUP_SCHEDULES_MANAGE);
|
|
}
|
|
|
|
public function delete(User $user, BackupSchedule $schedule): Response|bool
|
|
{
|
|
return $this->authorizeScheduleAction($user, $schedule, Capabilities::TENANT_BACKUP_SCHEDULES_MANAGE);
|
|
}
|
|
|
|
public function restore(User $user, BackupSchedule $schedule): Response|bool
|
|
{
|
|
return $this->authorizeScheduleAction($user, $schedule, Capabilities::TENANT_BACKUP_SCHEDULES_MANAGE);
|
|
}
|
|
|
|
public function forceDelete(User $user, BackupSchedule $schedule): Response|bool
|
|
{
|
|
return $this->authorizeScheduleAction($user, $schedule, Capabilities::TENANT_DELETE);
|
|
}
|
|
|
|
protected function authorizeScheduleAction(User $user, BackupSchedule $schedule, string $capability): Response|bool
|
|
{
|
|
$tenant = $this->resolvedTenant();
|
|
|
|
if (! $this->isTenantMember($user, $tenant)) {
|
|
return Response::denyAsNotFound();
|
|
}
|
|
|
|
if (! $tenant instanceof Tenant || (int) $schedule->tenant_id !== (int) $tenant->getKey()) {
|
|
return Response::denyAsNotFound();
|
|
}
|
|
|
|
return Gate::forUser($user)->allows($capability, $tenant)
|
|
? true
|
|
: Response::deny();
|
|
}
|
|
|
|
protected function resolvedTenant(): ?Tenant
|
|
{
|
|
if (Filament::getCurrentPanel()?->getId() === 'admin') {
|
|
$tenant = app(OperateHubShell::class)->tenantOwnedPanelContext(request());
|
|
|
|
return $tenant instanceof Tenant ? $tenant : null;
|
|
}
|
|
|
|
$tenant = Tenant::current();
|
|
|
|
return $tenant instanceof Tenant ? $tenant : null;
|
|
}
|
|
}
|