User optimisation and code cleanup

This commit is contained in:
2024-07-05 22:56:02 +10:00
parent b6b036e06d
commit 326b1dcfc5
12 changed files with 80 additions and 294 deletions

View File

@@ -15,11 +15,11 @@ class UserPolicy
*
* @param User $uo
* @param string $ability
* @return bool|null
* @return null|bool
*/
public function before(User $uo,string $ability): bool
public function before(User $uo,string $ability): bool|NULL
{
return $uo->isWholesaler() ?: FALSE;
return $uo->isWholesaler() ?: NULL;
}
/**
@@ -44,9 +44,6 @@ class UserPolicy
public function view(User $uo,User $o): bool
{
// If this is a service for an account managed by a user.
return ($uo->id == $o->id)
// The user has this as one of their accounts
OR $uo->accounts->pluck('user')->pluck('id')->unique()->contains($o->id);
return ($uo->id == $o->id) || $uo->accounts_all->pluck('user_id')->contains($o->id) || $uo->isWholesaler();
}
}