osb/app/Models/Policies/AccountPolicy.php

84 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Models\Policies;
use Illuminate\Auth\Access\HandlesAuthorization;
2021-06-29 03:18:52 +00:00
use App\Models\{Account,User};
class AccountPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view the account.
*
* @param User $uo
* @param Account $ao
* @return bool
*/
public function view(User $uo,Account $ao): bool
{
// If this is a service for an account managed by a user.
2024-07-05 12:56:02 +00:00
return $uo->accounts_all->pluck('id')->contains($ao->id) || $uo->isWholesaler();
}
/**
* Determine whether the user can create services.
*
* @param User $uo
* @return bool
*/
public function create(User $uo): bool
{
return TRUE;
}
/**
* Determine whether the user can update the service.
*
* @param User $uo
* @param Account $ao
* @return bool
*/
public function update(User $uo,Account $ao): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can delete the service.
*
* @param User $uo
* @param Account $ao
* @return bool
*/
public function delete(User $uo,Account $ao): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can restore the service.
*
* @param User $uo
* @param Account $ao
* @return bool
*/
public function restore(User $uo,Account $ao): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can permanently delete the service.
*
* @param User $uo
* @param Account $ao
* @return bool
*/
public function forceDelete(User $uo,Account $ao): bool
{
return $uo->isWholesaler();
}
}