Fix Model Policies from matching user_id's and account_id's, and other minor cosmetic fixes
This commit is contained in:
@@ -13,29 +13,29 @@ class ServicePolicy
|
||||
/**
|
||||
* Determine whether the user can view the service.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Service $o
|
||||
* @return mixed
|
||||
* @param User $uo
|
||||
* @param Service $so
|
||||
* @return bool
|
||||
*/
|
||||
public function view(User $user, Service $o)
|
||||
public function view(User $uo, Service $so): bool
|
||||
{
|
||||
// If this is a service for an account managed by a user.
|
||||
return ($user->services->pluck('id')->search($o->id) !== FALSE)
|
||||
return ($uo->services->pluck('id')->search($so->id) !== FALSE)
|
||||
|
||||
// The user is the wholesaler
|
||||
OR $user->isWholesaler()
|
||||
OR $uo->isWholesaler()
|
||||
|
||||
// The user is the reseller
|
||||
OR $user->all_accounts()->pluck('id')->search($o->account_id);
|
||||
OR ($uo->all_accounts()->pluck('id')->search($so->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;
|
||||
}
|
||||
@@ -43,61 +43,61 @@ class ServicePolicy
|
||||
/**
|
||||
* Can the user progress an order status
|
||||
*
|
||||
* @param User $user
|
||||
* @param Service $o
|
||||
* @param string $next
|
||||
* @param User $uo
|
||||
* @param Service $so
|
||||
* @param string $stage
|
||||
* @return bool
|
||||
*/
|
||||
public function progress(User $user, Service $o,string $next)
|
||||
public function progress(User $uo,Service $so,string $stage): bool
|
||||
{
|
||||
return $o->actions()->has($next);
|
||||
return $so->actions()->has($stage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the service.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Service $o
|
||||
* @return mixed
|
||||
* @param User $uo
|
||||
* @param Service $so
|
||||
* @return bool
|
||||
*/
|
||||
public function update(User $user, Service $o)
|
||||
public function update(User $uo, Service $so): bool
|
||||
{
|
||||
return $user->isWholesaler();
|
||||
return $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the service.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Service $o
|
||||
* @return mixed
|
||||
* @param User $uo
|
||||
* @param Service $so
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(User $user, Service $o)
|
||||
public function delete(User $uo, Service $so): bool
|
||||
{
|
||||
return $user->isWholesaler();
|
||||
return $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the service.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Service $o
|
||||
* @return mixed
|
||||
* @param User $uo
|
||||
* @param Service $so
|
||||
* @return bool
|
||||
*/
|
||||
public function restore(User $user, Service $o)
|
||||
public function restore(User $uo, Service $so): bool
|
||||
{
|
||||
return $user->isWholesaler();
|
||||
return $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the service.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Service $o
|
||||
* @return mixed
|
||||
* @param User $uo
|
||||
* @param Service $so
|
||||
* @return bool
|
||||
*/
|
||||
public function forceDelete(User $user, Service $o)
|
||||
public function forceDelete(User $uo, Service $so): bool
|
||||
{
|
||||
return $user->isWholesaler();
|
||||
return $uo->isWholesaler();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user