2023-12-18 02:00:04 +00:00
|
|
|
<?php
|
|
|
|
|
2024-11-04 07:25:49 +00:00
|
|
|
namespace App\Models\Policies;
|
2023-12-18 02:00:04 +00:00
|
|
|
|
|
|
|
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
|
2023-12-19 00:45:11 +00:00
|
|
|
* @param Netmail $o
|
2023-12-18 02:00:04 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2023-12-19 00:45:11 +00:00
|
|
|
public function view(User $user, Netmail $o): bool
|
2023-12-18 02:00:04 +00:00
|
|
|
{
|
2024-10-15 21:44:46 +00:00
|
|
|
$addresses = $user->addresses()->pluck('id');
|
2023-12-18 02:00:04 +00:00
|
|
|
|
|
|
|
// Site Admins can always view
|
|
|
|
return (
|
|
|
|
$user->isAdmin()
|
2024-10-15 21:44:46 +00:00
|
|
|
|| $user->isZC()
|
|
|
|
|| ($addresses->contains($o->fftn_id))
|
|
|
|
|| ($addresses->contains($o->tftn_id))
|
2023-12-18 02:00:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|