39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\User;
|
|
|
|
class UserPolicy
|
|
{
|
|
public function viewAny(User $actor): bool
|
|
{
|
|
return $actor->hasRole('platform-admin')
|
|
|| $actor->hasRole('school-admin')
|
|
|| $actor->hasRole('teacher');
|
|
}
|
|
|
|
public function view(User $actor, User $target): bool
|
|
{
|
|
if ($actor->hasRole('platform-admin')) return true;
|
|
return $actor->tenant_id === $target->tenant_id;
|
|
}
|
|
|
|
public function create(User $actor): bool
|
|
{
|
|
return $actor->hasRole('platform-admin') || $actor->hasRole('school-admin');
|
|
}
|
|
|
|
public function update(User $actor, User $target): bool
|
|
{
|
|
if ($actor->hasRole('platform-admin')) return true;
|
|
return $actor->hasRole('school-admin') && $actor->tenant_id === $target->tenant_id;
|
|
}
|
|
|
|
public function delete(User $actor, User $target): bool
|
|
{
|
|
if ($actor->hasRole('platform-admin')) return true;
|
|
return $actor->hasRole('school-admin') && $actor->tenant_id === $target->tenant_id;
|
|
}
|
|
}
|