Files
coolify/app/Policies/ServerPolicy.php
T
Andras Bacsai fb854a7cff fix(access): hide shared variables and actions that a member cannot use
- Check read access on the project or environment for shared variables
  pages, the canvas, and the sidebar, not only navigation access
- Require team-wide read for the server shared variables canvas API
- Open the environment variable editor read-only when the value is hidden
- Show the integration tokens button only to users who can open it
- Show disabled confirmation buttons as disabled, not as danger buttons
2026-10-30 15:14:02 +01:00

126 lines
3.1 KiB
PHP

<?php
namespace App\Policies;
use App\Enums\AccessLevel;
use App\Models\Server;
use App\Models\User;
use App\Services\Access\AccessResolver;
class ServerPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return true;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Server $server): bool
{
return $user->teams->contains('id', $server->team_id);
}
/**
* Determine whether the user can read the shared variables of the server (team-wide read).
*/
public function viewSharedVariables(User $user, Server $server): bool
{
return app(AccessResolver::class)->allowsTeamWide($user, AccessLevel::Read, $server->team_id);
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->isAdmin();
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Server $server): bool
{
return $user->isAdminOfTeam($server->team_id);
}
/**
* Determine whether the user can transfer the server to another Coolify instance.
*
* A transfer sends every secret of the server, also locked environment variables, to the target, so only owners may start it.
*/
public function transfer(User $user, Server $server): bool
{
return $user->roleInTeam($server->team_id) === 'owner';
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Server $server): bool
{
return $user->isAdminOfTeam($server->team_id);
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Server $server): bool
{
return false;
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Server $server): bool
{
return false;
}
/**
* Determine whether the user can manage proxy (start/stop/restart).
*/
public function manageProxy(User $user, Server $server): bool
{
return $user->isAdminOfTeam($server->team_id);
}
/**
* Determine whether the user can manage sentinel (start/stop).
*/
public function manageSentinel(User $user, Server $server): bool
{
return $user->isAdminOfTeam($server->team_id);
}
/**
* Determine whether the user can view Sentinel configuration and logs.
*/
public function viewSentinel(User $user, Server $server): bool
{
return $user->isAdminOfTeam($server->team_id);
}
/**
* Determine whether the user can manage CA certificates.
*/
public function manageCaCertificate(User $user, Server $server): bool
{
return $user->isAdminOfTeam($server->team_id);
}
/**
* Determine whether the user can view security views.
*/
public function viewSecurity(User $user, Server $server): bool
{
return $user->isAdminOfTeam($server->team_id);
}
}