2020-02-06 22:11:02 +00:00
|
|
|
<?php
|
|
|
|
|
2021-09-29 06:20:22 +00:00
|
|
|
namespace App\Models\Policies;
|
2020-02-06 22:11:02 +00:00
|
|
|
|
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
|
2021-06-29 03:18:52 +00:00
|
|
|
use App\Models\User;
|
2020-02-06 22:11:02 +00:00
|
|
|
|
|
|
|
class UserPolicy
|
|
|
|
{
|
|
|
|
use HandlesAuthorization;
|
|
|
|
|
|
|
|
/**
|
2022-06-28 11:57:55 +00:00
|
|
|
* Wholesalers can do anything.
|
2020-02-06 22:11:02 +00:00
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @param User $uo
|
2022-06-28 11:57:55 +00:00
|
|
|
* @param string $ability
|
2024-07-05 12:56:02 +00:00
|
|
|
* @return null|bool
|
2020-02-06 22:11:02 +00:00
|
|
|
*/
|
2024-07-05 12:56:02 +00:00
|
|
|
public function before(User $uo,string $ability): bool|NULL
|
2020-02-06 22:11:02 +00:00
|
|
|
{
|
2024-07-05 12:56:02 +00:00
|
|
|
return $uo->isWholesaler() ?: NULL;
|
2020-02-06 22:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-06-28 11:57:55 +00:00
|
|
|
* Can this user assume the role of the other user
|
2020-02-06 22:11:02 +00:00
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @param User $uo
|
2020-02-06 22:11:02 +00:00
|
|
|
* @param User $o
|
2021-09-29 06:20:22 +00:00
|
|
|
* @return bool
|
2020-02-06 22:11:02 +00:00
|
|
|
*/
|
2022-06-28 11:57:55 +00:00
|
|
|
public function assume(User $uo, User $o): bool
|
2020-02-06 22:11:02 +00:00
|
|
|
{
|
2022-06-28 11:57:55 +00:00
|
|
|
return $uo->isAdmin($o);
|
2020-02-06 22:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-06-28 11:57:55 +00:00
|
|
|
* Determine whether the user can view the user details.
|
2020-02-06 22:11:02 +00:00
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @param User $uo
|
2020-02-06 22:11:02 +00:00
|
|
|
* @param User $o
|
2021-09-29 06:20:22 +00:00
|
|
|
* @return bool
|
2020-02-06 22:11:02 +00:00
|
|
|
*/
|
2022-06-28 11:57:55 +00:00
|
|
|
public function view(User $uo,User $o): bool
|
2020-02-06 22:11:02 +00:00
|
|
|
{
|
2022-06-28 11:57:55 +00:00
|
|
|
// If this is a service for an account managed by a user.
|
2024-07-05 12:56:02 +00:00
|
|
|
return ($uo->id == $o->id) || $uo->accounts_all->pluck('user_id')->contains($o->id) || $uo->isWholesaler();
|
2020-02-06 22:11:02 +00:00
|
|
|
}
|
|
|
|
}
|