Files
coolify/app/Policies/TeamPolicy.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

105 lines
2.4 KiB
PHP

<?php
namespace App\Policies;
use App\Enums\AccessLevel;
use App\Models\Team;
use App\Models\User;
use App\Services\Access\AccessResolver;
class TeamPolicy
{
/**
* 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, Team $team): bool
{
return $user->teams->contains('id', $team->id);
}
/**
* Determine whether the user can read the team shared variables (team-wide read).
*/
public function viewSharedVariables(User $user, Team $team): bool
{
return app(AccessResolver::class)->allowsTeamWide($user, AccessLevel::Read, $team->id);
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
// All authenticated users can create teams
return true;
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Team $team): bool
{
if (! $user->teams->contains('id', $team->id)) {
return false;
}
return $user->isAdminOfTeam($team->id);
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Team $team): bool
{
if (! $user->teams->contains('id', $team->id)) {
return false;
}
return $user->roleInTeam($team->id) === 'owner';
}
/**
* Determine whether the user can manage team members.
*/
public function manageMembers(User $user, Team $team): bool
{
if (! $user->teams->contains('id', $team->id)) {
return false;
}
return $user->isAdminOfTeam($team->id);
}
/**
* Determine whether the user can view admin panel.
*/
public function viewAdmin(User $user, Team $team): bool
{
if (! $user->teams->contains('id', $team->id)) {
return false;
}
return $user->isAdminOfTeam($team->id);
}
/**
* Determine whether the user can manage invitations.
*/
public function manageInvitations(User $user, Team $team): bool
{
if (! $user->teams->contains('id', $team->id)) {
return false;
}
return $user->isAdminOfTeam($team->id);
}
}