clrghouz/app/Policies/NetmailPolicy.php
Deon George f4f8e9fa94
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 37s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m50s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
Fix some user permissions, when viewing netmails and other systems
2024-10-16 08:44:46 +11:00

32 lines
584 B
PHP

<?php
namespace App\Policies;
use Illuminate\Auth\Access\HandlesAuthorization;
use App\Models\{Netmail,User};
class NetmailPolicy
{
use HandlesAuthorization;
/**
* This determines whether a logged-in user can view a netmail
*
* @param User $user
* @param Netmail $o
* @return bool
*/
public function view(User $user, Netmail $o): bool
{
$addresses = $user->addresses()->pluck('id');
// Site Admins can always view
return (
$user->isAdmin()
|| $user->isZC()
|| ($addresses->contains($o->fftn_id))
|| ($addresses->contains($o->tftn_id))
);
}
}