Fix Model Policies from matching user_id's and account_id's, and other minor cosmetic fixes

This commit is contained in:
Deon George
2021-09-29 16:20:22 +10:00
parent f7439172b6
commit 4243da9c32
14 changed files with 173 additions and 172 deletions

View File

@@ -13,78 +13,78 @@ class InvoicePolicy
/**
* Determine whether the user can view the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
* @param User $uo
* @param Invoice $io
* @return bool
*/
public function view(User $user, Invoice $o)
public function view(User $uo,Invoice $io): bool
{
// If this is a service for an account managed by a user.
return ($user->invoices->pluck('id')->search($o->id) !== FALSE)
return ($uo->invoices->pluck('id')->search($io->id) !== FALSE)
// The user is the wholesaler
OR $user->isWholesaler()
// The user is the wholesaler
OR $uo->isWholesaler()
// The user is the reseller
OR $user->all_accounts()->pluck('id')->search($o->account_id);
// The user is the reseller
OR ($uo->all_accounts()->pluck('id')->search($io->account_id) !== FALSE);
}
/**
* Determine whether the user can create services.
*
* @param User $user
* @return mixed
* @param User $uo
* @return bool
*/
public function create(User $user)
public function create(User $uo): bool
{
return TRUE;
return $uo->isWholesaler();
}
/**
* Determine whether the user can update the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
* @param User $uo
* @param Invoice $io
* @return bool
*/
public function update(User $user, Invoice $o)
public function update(User $uo,Invoice $io): bool
{
return $user->isWholesaler();
return $uo->isWholesaler();
}
/**
* Determine whether the user can delete the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
* @param User $uo
* @param Invoice $io
* @return bool
*/
public function delete(User $user, Invoice $o)
public function delete(User $uo,Invoice $io): bool
{
return $user->isWholesaler();
return $uo->isWholesaler();
}
/**
* Determine whether the user can restore the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
* @param User $uo
* @param Invoice $io
* @return bool
*/
public function restore(User $user, Invoice $o)
public function restore(User $uo,Invoice $io): bool
{
return $user->isWholesaler();
return $uo->isWholesaler();
}
/**
* Determine whether the user can permanently delete the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
* @param User $uo
* @param Invoice $io
* @return bool
*/
public function forceDelete(User $user, Invoice $o)
public function forceDelete(User $uo,Invoice $io): bool
{
return $user->isWholesaler();
return $uo->isWholesaler();
}
}