athenahr/app/Policies/TeamPolicy.php
miguel456 3727c84f3e
refactor: code style changes
Signed-off-by: miguel456 <me@nogueira.codes>
2023-01-15 00:04:00 +00:00

55 lines
1.2 KiB
PHP
Executable File

<?php
namespace App\Policies;
use App\Team;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class TeamPolicy
{
use HandlesAuthorization;
/**
* Create a new policy instance.
*
* @return void
*/
public function __construct()
{
//
}
public function index(User $user)
{
return $user->hasPermissionTo('teams.view');
}
public function create(User $user)
{
return $user->hasPermissionTo('teams.create');
}
public function update(User $user, Team $team)
{
// Team owners can update their team regardless of perm.
// This perm would let admins change all teams
return $user->isOwnerOfTeam($team) || $user->hasPermissionTo('teams.update');
}
public function invite(User $user, Team $team)
{
if (! $team->openJoin && $user->isOwnerOfTeam($team) || ! $team->openJoin && $user->hasPermissionTo('teams.invite')) {
return true;
}
return false;
}
public function switchTeam(User $user, Team $team): bool
{
// is the user in the team they're trying to switch to?
return $user->hasTeam($team);
}
}