clrghouz/app/Models/Policies/NetmailPolicy.php

32 lines
591 B
PHP
Raw Permalink Normal View History

<?php
2024-11-04 07:25:49 +00:00
namespace App\Models\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))
);
}
}