Add allocation to role permission models & make sure user can target node of allocation (#2124)

This commit is contained in:
Boy132
2026-01-23 16:37:01 +01:00
committed by GitHub
parent 3ca0f64e6e
commit 426643eaa6
2 changed files with 24 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Enums;
enum RolePermissionModels: string
{
case ApiKey = 'apiKey';
case Allocation = 'allocation';
case DatabaseHost = 'databaseHost';
case Database = 'database';
case Egg = 'egg';
@@ -34,4 +35,9 @@ enum RolePermissionModels: string
{
return RolePermissionPrefixes::Update->value . ' ' . $this->value;
}
public function delete(): string
{
return RolePermissionPrefixes::Delete->value . ' ' . $this->value;
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Policies;
use App\Enums\SubuserPermission;
use App\Models\Allocation;
use App\Models\Server;
use App\Models\User;
use Filament\Facades\Filament;
@@ -21,6 +22,23 @@ class AllocationPolicy
protected string $modelName = 'allocation';
public function before(User $user, string $ability, string|Allocation $allocation): ?bool
{
// For "viewAny" the $allocation param is the class name
if (is_string($allocation)) {
return null;
}
/** @var ?Server $server */
$server = Filament::getTenant();
if (!$server && !$user->canTarget($allocation->node)) {
return false;
}
return null;
}
public function viewAny(User $user): bool
{
/** @var ?Server $server */