Files
coolify/app/Policies/ResourceCreatePolicy.php
T
Andras Bacsai 6f1905b7b0 fix(access): enforce member grants on more actions
- Require write access on the target environment to clone or move a resource
- Check read access on shared variables before a reference is added or resolved
- Limit team credentials, git sources, and imports of other backups to team-wide writers
- Require the delete level for backup, volume, storage, and task deletes
- Require create access for previews, new projects, and git sources
- Use the token team for the access scope, and check team-wide access on Livewire updates
- Require instance admin to toggle the API and MCP server
- Hide server pickers and broadcast details from members without access
2026-10-30 16:11:10 +01:00

40 lines
1.4 KiB
PHP

<?php
namespace App\Policies;
use App\Enums\AccessLevel;
use App\Models\Environment;
use App\Models\User;
use App\Services\Access\AccessResolver;
use Illuminate\Database\Eloquent\Model;
class ResourceCreatePolicy
{
/**
* Determine whether the user can create resources in the environment.
* Without an environment, the user needs write access on the whole current team.
*/
public function createAny(User $user, ?Environment $environment = null): bool
{
if ($environment !== null) {
return $user->canAccess(AccessLevel::Write, $environment);
}
$teamId = $user->currentTeam()?->id;
return $teamId !== null && app(AccessResolver::class)->allowsTeamWide($user, AccessLevel::Write, $teamId);
}
/**
* Determine whether the user can use a team credential or team-wide location that the resource does not use
* yet: private keys, git sources, integration tokens, and backup files of other resources.
* Needs write access on the whole team of the resource, or of the current team without a resource.
*/
public function useTeamCredentials(User $user, ?Model $resource = null): bool
{
$teamId = $resource !== null ? $resource->team()?->id : $user->currentTeam()?->id;
return $teamId !== null && app(AccessResolver::class)->allowsTeamWide($user, AccessLevel::Write, (int) $teamId);
}
}