Change ScopeServiceUserAuthorised to ScopeAccountUserAuthorised. Scope payments to AccountUserAuthorised, and added PaymentPolicy
This commit is contained in:
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\DB;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
|
||||
use App\Interfaces\IDs;
|
||||
use App\Traits\{ProviderRef,PushNew,SiteID};
|
||||
use App\Traits\{ProviderRef,PushNew,ScopeAccountUserAuthorised,SiteID};
|
||||
|
||||
/**
|
||||
* Class Payment
|
||||
@@ -24,7 +24,7 @@ use App\Traits\{ProviderRef,PushNew,SiteID};
|
||||
*/
|
||||
class Payment extends Model implements IDs
|
||||
{
|
||||
use PushNew,ScopeActive,ProviderRef,SiteID;
|
||||
use ProviderRef,PushNew,ScopeActive,ScopeAccountUserAuthorised,SiteID;
|
||||
|
||||
protected $casts = [
|
||||
'paid_at'=>'datetime:Y-m-d',
|
||||
|
83
app/Models/Policies/PaymentPolicy.php
Normal file
83
app/Models/Policies/PaymentPolicy.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
use App\Models\{Payment,User};
|
||||
|
||||
class PaymentPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the payment.
|
||||
*
|
||||
* @param User $uo
|
||||
* @param Payment $o
|
||||
* @return bool
|
||||
*/
|
||||
public function view(User $uo,Payment $o): bool
|
||||
{
|
||||
return $uo->accounts_all->pluck('id')->contains($o->account_id) || $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Payment $o
|
||||
* @return bool
|
||||
*/
|
||||
public function update(User $uo,Payment $o): bool
|
||||
{
|
||||
return $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the service.
|
||||
*
|
||||
* @param User $uo
|
||||
* @param Payment $o
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(User $uo,Payment $o): bool
|
||||
{
|
||||
return $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the service.
|
||||
*
|
||||
* @param User $uo
|
||||
* @param Payment $o
|
||||
* @return bool
|
||||
*/
|
||||
public function restore(User $uo,Payment $o): bool
|
||||
{
|
||||
return $uo->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the service.
|
||||
*
|
||||
* @param User $uo
|
||||
* @param Payment $o
|
||||
* @return bool
|
||||
*/
|
||||
public function forceDelete(User $uo,Payment $o): bool
|
||||
{
|
||||
return $uo->isWholesaler();
|
||||
}
|
||||
}
|
@@ -16,7 +16,7 @@ use Leenooks\Casts\LeenooksCarbon;
|
||||
|
||||
use App\Models\Product\Type;
|
||||
use App\Interfaces\IDs;
|
||||
use App\Traits\{ScopeServiceActive,ScopeServiceUserAuthorised};
|
||||
use App\Traits\{ScopeAccountUserAuthorised,ScopeServiceActive};
|
||||
|
||||
/**
|
||||
* Class Service
|
||||
@@ -52,7 +52,7 @@ use App\Traits\{ScopeServiceActive,ScopeServiceUserAuthorised};
|
||||
*/
|
||||
class Service extends Model implements IDs
|
||||
{
|
||||
use HasFactory,ScopeServiceActive,ScopeServiceUserAuthorised;
|
||||
use HasFactory,ScopeAccountUserAuthorised,ScopeServiceActive;
|
||||
|
||||
protected $casts = [
|
||||
'order_info' => AsCollection::class,
|
||||
@@ -280,7 +280,7 @@ class Service extends Model implements IDs
|
||||
{
|
||||
return (new self)
|
||||
->ServiceActive()
|
||||
->ServiceUserAuthorised($uo)
|
||||
->AccountUserAuthorised(NULL,$uo)
|
||||
->where('order_status','!=','ACTIVE')
|
||||
->with(['account','product'])
|
||||
->get();
|
||||
|
@@ -9,11 +9,11 @@ use Leenooks\Carbon as LeenooksCarbon;
|
||||
use App\Interfaces\ServiceItem;
|
||||
use App\Models\{Account,Service};
|
||||
use App\Models\Supplier\Type as SupplierType;
|
||||
use App\Traits\{ScopeServiceActive,ScopeServiceUserAuthorised};
|
||||
use App\Traits\{ScopeAccountUserAuthorised,ScopeServiceActive};
|
||||
|
||||
abstract class Type extends Model implements ServiceItem
|
||||
{
|
||||
use ScopeServiceActive,ScopeServiceUserAuthorised;
|
||||
use ScopeAccountUserAuthorised,ScopeServiceActive;
|
||||
|
||||
protected $casts = [
|
||||
'connect_at' => 'datetime:Y-m-d',
|
||||
|
Reference in New Issue
Block a user