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

@@ -1,6 +1,6 @@
<?php
namespace App\Policies;
namespace App\Models\Policies;
use Illuminate\Auth\Access\HandlesAuthorization;
@@ -13,78 +13,78 @@ class UserPolicy
/**
* Determine whether the user can view the service.
*
* @param User $user
* @param User $uo
* @param User $o
* @return mixed
* @return bool
*/
public function view(User $user, User $o)
public function view(User $uo,User $o): bool
{
// If this is a service for an account managed by a user.
return ($user->id == $o->id)
return ($uo->id == $o->id)
// The user is the wholesaler
OR $user->isWholesaler()
OR $uo->isWholesaler()
// The user is the reseller
OR $user->all_clients()->pluck('id')->search($o->id);
OR ($uo->all_clients()->pluck('id')->search($o->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 $uo->isWholesaler();
}
/**
* Determine whether the user can update the service.
*
* @param User $user
* @param User $uo
* @param User $o
* @return mixed
* @return bool
*/
public function update(User $user, User $o)
public function update(User $uo, User $o): bool
{
//
return $uo->isWholesaler();
}
/**
* Determine whether the user can delete the service.
*
* @param User $user
* @param User $uo
* @param User $o
* @return mixed
* @return bool
*/
public function delete(User $user, User $o)
public function delete(User $uo, User $o): bool
{
//
return $uo->isWholesaler();
}
/**
* Determine whether the user can restore the service.
*
* @param User $user
* @param User $uo
* @param User $o
* @return mixed
* @return bool
*/
public function restore(User $user, User $o)
public function restore(User $uo, User $o): bool
{
//
return $uo->isWholesaler();
}
/**
* Determine whether the user can permanently delete the service.
*
* @param User $user
* @param User $uo
* @param User $o
* @return mixed
* @return bool
*/
public function forceDelete(User $user, User $o)
public function forceDelete(User $uo, User $o): bool
{
//
return $uo->isWholesaler();
}
}