osb/app/Models/Policies/ServicePolicy.php

97 lines
1.8 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\{Service,User};
class ServicePolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view the service.
*
* @param User $uo
* @param Service $so
* @return bool
*/
public function view(User $uo, Service $so): 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($so->account_id) || $uo->isWholesaler();
}
/**
* Determine whether the user can create services.
*
* @param User $uo
* @return bool
*/
public function create(User $uo): bool
{
return TRUE;
}
2020-04-18 22:33:41 +00:00
/**
* Can the user progress an order status
*
* @param User $uo
* @param Service $so
* @param string $stage
2020-04-18 22:33:41 +00:00
* @return bool
*/
2021-09-29 07:11:46 +00:00
public function progress(User $uo,Service $so,string $stage=''): bool
2020-04-18 22:33:41 +00:00
{
2021-09-29 07:11:46 +00:00
return $stage ? $so->actions()->has(strtoupper($stage)) : $so->actions()->count();
2020-04-18 22:33:41 +00:00
}
/**
* Determine whether the user can update the service.
*
* @param User $uo
* @param Service $so
* @return bool
*/
public function update(User $uo, Service $so): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can delete the service.
*
* @param User $uo
* @param Service $so
* @return bool
*/
public function delete(User $uo, Service $so): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can restore the service.
*
* @param User $uo
* @param Service $so
* @return bool
*/
public function restore(User $uo, Service $so): bool
{
return $uo->isWholesaler();
}
/**
* Determine whether the user can permanently delete the service.
*
* @param User $uo
* @param Service $so
* @return bool
*/
public function forceDelete(User $uo, Service $so): bool
{
return $uo->isWholesaler();
}
}