osb/app/Models/Policies/ServicePolicy.php

103 lines
1.9 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.
*
2021-06-29 03:18:52 +00:00
* @param User $user
* @param Service $o
* @return mixed
*/
public function view(User $user, Service $o)
{
// If this is a service for an account managed by a user.
return ($user->services->pluck('id')->search($o->id) !== FALSE)
2020-04-18 22:33:41 +00:00
// The user is the wholesaler
OR $user->isWholesaler()
2020-04-18 22:33:41 +00:00
// The user is the reseller
OR $user->all_accounts()->pluck('id')->search($o->account_id);
}
/**
* Determine whether the user can create services.
*
2021-06-29 03:18:52 +00:00
* @param User $user
* @return mixed
*/
public function create(User $user)
{
return TRUE;
}
2020-04-18 22:33:41 +00:00
/**
* Can the user progress an order status
*
* @param User $user
* @param Service $o
2021-06-29 03:18:52 +00:00
* @param string $next
2020-04-18 22:33:41 +00:00
* @return bool
*/
public function progress(User $user, Service $o,string $next)
{
return $o->actions()->has($next);
}
/**
* Determine whether the user can update the service.
*
2021-06-29 03:18:52 +00:00
* @param User $user
* @param Service $o
* @return mixed
*/
public function update(User $user, Service $o)
{
return $user->isWholesaler();
}
/**
* Determine whether the user can delete the service.
*
2021-06-29 03:18:52 +00:00
* @param User $user
* @param Service $o
* @return mixed
*/
public function delete(User $user, Service $o)
{
return $user->isWholesaler();
}
/**
* Determine whether the user can restore the service.
*
2021-06-29 03:18:52 +00:00
* @param User $user
* @param Service $o
* @return mixed
*/
public function restore(User $user, Service $o)
{
return $user->isWholesaler();
}
/**
* Determine whether the user can permanently delete the service.
*
2021-06-29 03:18:52 +00:00
* @param User $user
* @param Service $o
* @return mixed
*/
public function forceDelete(User $user, Service $o)
{
return $user->isWholesaler();
}
}