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,29 +13,29 @@ class AccountPolicy
/**
* Determine whether the user can view the service.
*
* @param User $user
* @param Account $o
* @return mixed
* @param User $uo
* @param Account $ao
* @return bool
*/
public function view(User $user, Account $o)
public function view(User $uo,Account $ao): bool
{
// If this is a service for an account managed by a user.
return ($user->accounts->pluck('id')->search($o->id) !== FALSE)
return ($uo->accounts->pluck('id')->search($ao->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->id);
// The user is the reseller
OR ($uo->all_accounts()->pluck('id')->search($ao->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;
}
@@ -43,48 +43,48 @@ class AccountPolicy
/**
* Determine whether the user can update the service.
*
* @param User $user
* @param Account $o
* @return mixed
* @param User $uo
* @param Account $ao
* @return bool
*/
public function update(User $user, Account $o)
public function update(User $uo,Account $ao): bool
{
return $user->isWholesaler();
return $uo->isWholesaler();
}
/**
* Determine whether the user can delete the service.
*
* @param User $user
* @param Account $o
* @return mixed
* @param User $uo
* @param Account $ao
* @return bool
*/
public function delete(User $user, Account $o)
public function delete(User $uo,Account $ao): bool
{
return $user->isWholesaler();
return $uo->isWholesaler();
}
/**
* Determine whether the user can restore the service.
*
* @param User $user
* @param Account $o
* @return mixed
* @param User $uo
* @param Account $ao
* @return bool
*/
public function restore(User $user, Account $o)
public function restore(User $uo,Account $ao): bool
{
return $user->isWholesaler();
return $uo->isWholesaler();
}
/**
* Determine whether the user can permanently delete the service.
*
* @param User $user
* @param Account $o
* @return mixed
* @param User $uo
* @param Account $ao
* @return bool
*/
public function forceDelete(User $user, Account $o)
public function forceDelete(User $uo,Account $ao): bool
{
return $user->isWholesaler();
return $uo->isWholesaler();
}
}