2019-07-04 04:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models\Policies;
|
|
|
|
|
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
|
2021-06-29 03:18:52 +00:00
|
|
|
use App\Models\{Service,User};
|
2019-07-04 04:55:05 +00:00
|
|
|
|
|
|
|
class ServicePolicy
|
|
|
|
{
|
|
|
|
use HandlesAuthorization;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can view the service.
|
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @param User $uo
|
|
|
|
* @param Service $so
|
|
|
|
* @return bool
|
2019-07-04 04:55:05 +00:00
|
|
|
*/
|
2021-09-29 06:20:22 +00:00
|
|
|
public function view(User $uo, Service $so): bool
|
2019-07-04 04:55:05 +00:00
|
|
|
{
|
|
|
|
// If this is a service for an account managed by a user.
|
2021-09-29 06:20:22 +00:00
|
|
|
return ($uo->services->pluck('id')->search($so->id) !== FALSE)
|
2019-07-04 04:55:05 +00:00
|
|
|
|
2020-04-18 22:33:41 +00:00
|
|
|
// The user is the wholesaler
|
2021-09-29 06:20:22 +00:00
|
|
|
OR $uo->isWholesaler()
|
2019-07-04 04:55:05 +00:00
|
|
|
|
2020-04-18 22:33:41 +00:00
|
|
|
// The user is the reseller
|
2021-09-29 06:20:22 +00:00
|
|
|
OR ($uo->all_accounts()->pluck('id')->search($so->account_id) !== FALSE);
|
2019-07-04 04:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can create services.
|
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @param User $uo
|
|
|
|
* @return bool
|
2019-07-04 04:55:05 +00:00
|
|
|
*/
|
2021-09-29 06:20:22 +00:00
|
|
|
public function create(User $uo): bool
|
2019-07-04 04:55:05 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-04-18 22:33:41 +00:00
|
|
|
/**
|
|
|
|
* Can the user progress an order status
|
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @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
|
|
|
}
|
|
|
|
|
2019-07-04 04:55:05 +00:00
|
|
|
/**
|
|
|
|
* Determine whether the user can update the service.
|
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @param User $uo
|
|
|
|
* @param Service $so
|
|
|
|
* @return bool
|
2019-07-04 04:55:05 +00:00
|
|
|
*/
|
2021-09-29 06:20:22 +00:00
|
|
|
public function update(User $uo, Service $so): bool
|
2019-07-04 04:55:05 +00:00
|
|
|
{
|
2021-09-29 06:20:22 +00:00
|
|
|
return $uo->isWholesaler();
|
2019-07-04 04:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can delete the service.
|
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @param User $uo
|
|
|
|
* @param Service $so
|
|
|
|
* @return bool
|
2019-07-04 04:55:05 +00:00
|
|
|
*/
|
2021-09-29 06:20:22 +00:00
|
|
|
public function delete(User $uo, Service $so): bool
|
2019-07-04 04:55:05 +00:00
|
|
|
{
|
2021-09-29 06:20:22 +00:00
|
|
|
return $uo->isWholesaler();
|
2019-07-04 04:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can restore the service.
|
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @param User $uo
|
|
|
|
* @param Service $so
|
|
|
|
* @return bool
|
2019-07-04 04:55:05 +00:00
|
|
|
*/
|
2021-09-29 06:20:22 +00:00
|
|
|
public function restore(User $uo, Service $so): bool
|
2019-07-04 04:55:05 +00:00
|
|
|
{
|
2021-09-29 06:20:22 +00:00
|
|
|
return $uo->isWholesaler();
|
2019-07-04 04:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the user can permanently delete the service.
|
|
|
|
*
|
2021-09-29 06:20:22 +00:00
|
|
|
* @param User $uo
|
|
|
|
* @param Service $so
|
|
|
|
* @return bool
|
2019-07-04 04:55:05 +00:00
|
|
|
*/
|
2021-09-29 06:20:22 +00:00
|
|
|
public function forceDelete(User $uo, Service $so): bool
|
2019-07-04 04:55:05 +00:00
|
|
|
{
|
2021-09-29 06:20:22 +00:00
|
|
|
return $uo->isWholesaler();
|
2019-07-04 04:55:05 +00:00
|
|
|
}
|
|
|
|
}
|