Fix Model Policies from matching user_id's and account_id's, and other minor cosmetic fixes
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user