Update leenooks/laravel and framework updates

This commit is contained in:
Deon George
2022-06-28 21:57:55 +10:00
parent 3723d644e6
commit 464407e7ee
5 changed files with 97 additions and 110 deletions

View File

@@ -10,6 +10,30 @@ class UserPolicy
{
use HandlesAuthorization;
/**
* Wholesalers can do anything.
*
* @param User $uo
* @param string $ability
* @return bool|null
*/
public function before(User $uo,string $ability): ?bool
{
return $uo->isWholesaler() ?: NULL;
}
/**
* Can this user assume the role of the other user
*
* @param User $uo
* @param User $o
* @return bool
*/
public function assume(User $uo, User $o): bool
{
return $uo->isAdmin($o);
}
/**
* Determine whether the user can view the user details.
*
@@ -22,69 +46,7 @@ class UserPolicy
// If this is a service for an account managed by a user.
return ($uo->id == $o->id)
// The user is the wholesaler
OR $uo->isWholesaler()
// The user has this as one of their accounts
OR $uo->accounts->pluck('user')->pluck('id')->unique()->contains($o->id);
}
/**
* Determine whether the user can create services.
*
* @param User $uo
* @return bool
*/
public function create(User $uo): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can update the service.
*
* @param User $uo
* @param User $o
* @return bool
*/
public function update(User $uo, User $o): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can delete the service.
*
* @param User $uo
* @param User $o
* @return bool
*/
public function delete(User $uo, User $o): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can restore the service.
*
* @param User $uo
* @param User $o
* @return bool
*/
public function restore(User $uo, User $o): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can permanently delete the service.
*
* @param User $uo
* @param User $o
* @return bool
*/
public function forceDelete(User $uo, User $o): bool
{
return $uo->isWholesaler();
}
}

View File

@@ -266,12 +266,12 @@ class User extends Authenticatable implements IDs
/**
* Determine if the user is an admin of the user with $id
*
* @param $id
* @param User|null $user
* @return bool
*/
public function isAdmin($id): bool
public function isAdmin(User $user=NULL): bool
{
return $id AND $this->isReseller() AND $this->accounts->pluck('user_id')->contains($id);
return $user->exists AND $this->isReseller() AND $this->accounts->pluck('user_id')->contains($user->id);
}
/**