ldc-crm/app/Policies/CustomerPolicy.php

92 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2023-06-20 11:55:52 +02:00
<?php
namespace App\Policies;
use App\Enums\Users\RoleEnum;
2023-06-20 11:55:52 +02:00
use App\Models\Customer;
use App\Models\Service;
use App\Models\User;
2023-06-20 11:55:52 +02:00
use Illuminate\Auth\Access\HandlesAuthorization;
use App\Policies\Rules\UserStaticRules;
2023-06-20 11:55:52 +02:00
class CustomerPolicy
{
use HandlesAuthorization;
2023-06-20 17:37:15 +02:00
/**
* View a Customer.
*
* @param \App\Models\User $authUser
2023-06-20 17:37:15 +02:00
* @return boolean
*/
public function view(User $authUser): bool
2023-06-20 17:37:15 +02:00
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
2023-06-20 17:37:15 +02:00
}
/**
* View any a Customer.
*
* @param \App\Models\User $authUser
2023-06-20 17:37:15 +02:00
* @return boolean
*/
public function viewAny(User $authUser): bool
2023-06-20 17:37:15 +02:00
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
2023-06-20 17:37:15 +02:00
}
/**
* Create a Customer.
*
* @return boolean
*/
public function create(): bool
{
return UserStaticRules::noOne();
2023-06-20 17:37:15 +02:00
}
/**
* Update a Customer.
*
* @return boolean
*/
public function update(): bool
{
return UserStaticRules::noOne();
2023-06-20 17:37:15 +02:00
}
/**
* Delete a Customer.
*
* @param \App\Models\User $authUser
2023-06-20 17:37:15 +02:00
* @return boolean
*/
public function delete(User $authUser): bool
2023-06-20 17:37:15 +02:00
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
2023-06-20 17:37:15 +02:00
}
2023-06-20 11:55:52 +02:00
/**
* Check if the customer belongs to the service.
2023-06-20 11:55:52 +02:00
*
2023-06-23 17:18:59 +02:00
* @param \App\Models\Service $service
* @param \App\Models\Customer $customer
2023-06-20 11:55:52 +02:00
* @return boolean
*/
public function customerBelongsToService(Service $service, Customer $customer)
{
return !\is_null($customer->login($service->brand));
}
/**
* Export Customers.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function export(User $authUser): bool
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
2023-06-20 11:55:52 +02:00
}