mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-14 00:16:42 +00:00
feat(auth): introduce resource creation authorization middleware and policies for enhanced access control
This commit is contained in:
1 parent
0702d29ae1
commit
3e1f47a243
9 files changed
+256
-4
No files matched your search
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\Service;
|
||||
use App\Models\StandaloneClickhouse;
|
||||
use App\Models\StandaloneDragonfly;
|
||||
use App\Models\StandaloneKeydb;
|
||||
use App\Models\StandaloneMariadb;
|
||||
use App\Models\StandaloneMongodb;
|
||||
use App\Models\StandaloneMysql;
|
||||
use App\Models\StandalonePostgresql;
|
||||
use App\Models\StandaloneRedis;
|
||||
use App\Models\User;
|
||||
|
||||
class ResourceCreatePolicy
|
||||
{
|
||||
/**
|
||||
* List of resource classes that can be created
|
||||
*/
|
||||
public const CREATABLE_RESOURCES = [
|
||||
StandalonePostgresql::class,
|
||||
StandaloneRedis::class,
|
||||
StandaloneMongodb::class,
|
||||
StandaloneMysql::class,
|
||||
StandaloneMariadb::class,
|
||||
StandaloneKeydb::class,
|
||||
StandaloneDragonfly::class,
|
||||
StandaloneClickhouse::class,
|
||||
Service::class,
|
||||
Application::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine whether the user can create any resource.
|
||||
*/
|
||||
public function createAny(User $user): bool
|
||||
{
|
||||
return $user->isAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create a specific resource type.
|
||||
*/
|
||||
public function create(User $user, string $resourceClass): bool
|
||||
{
|
||||
if (! in_array($resourceClass, self::CREATABLE_RESOURCES)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user->isAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorize creation of all supported resource types.
|
||||
*/
|
||||
public function authorizeAllResourceCreation(User $user): bool
|
||||
{
|
||||
return $this->createAny($user);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user