User optimisation and code cleanup
This commit is contained in:
@@ -20,13 +20,7 @@ class AccountPolicy
|
||||
public function view(User $uo,Account $ao): bool
|
||||
{
|
||||
// If this is a service for an account managed by a user.
|
||||
return ($uo->accounts->pluck('id')->search($ao->id) !== FALSE)
|
||||
|
||||
// The user is the wholesaler
|
||||
OR $uo->isWholesaler()
|
||||
|
||||
// The user has this as one of their accounts
|
||||
OR $uo->accounts->pluck('id')->contains($ao->id);
|
||||
return $uo->accounts_all->pluck('id')->contains($ao->id) || $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -19,14 +19,7 @@ class InvoicePolicy
|
||||
*/
|
||||
public function view(User $uo,Invoice $io): bool
|
||||
{
|
||||
// If this is a service for an account managed by a user.
|
||||
return ($uo->invoices->pluck('id')->search($io->id) !== FALSE)
|
||||
|
||||
// The user is the wholesaler
|
||||
OR $uo->isWholesaler()
|
||||
|
||||
// The user has this as one of their accounts
|
||||
OR $uo->accounts->pluck('id')->contains($io->account_id);
|
||||
return $uo->accounts_all->pluck('id')->contains($io->account_id) || $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -20,13 +20,7 @@ class ServicePolicy
|
||||
public function view(User $uo, Service $so): bool
|
||||
{
|
||||
// If this is a service for an account managed by a user.
|
||||
return ($uo->services->pluck('id')->search($so->id) !== FALSE)
|
||||
|
||||
// The user is the wholesaler
|
||||
OR $uo->isWholesaler()
|
||||
|
||||
// The user has this as one of their accounts
|
||||
OR $uo->accounts->pluck('id')->contains($so->account_id);
|
||||
return $uo->accounts_all->pluck('id')->contains($so->account_id) || $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user