wip
This commit is contained in:
113
app/Policies/Ecommerce/Channel/ChannelPolicy.php
Normal file
113
app/Policies/Ecommerce/Channel/ChannelPolicy.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Channel;
|
||||
|
||||
use App\Models\Ecommerce\Channel\Channel;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class ChannelPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Channel $channel): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Channel $channel): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Channel $channel): Response
|
||||
{
|
||||
if (tmpostChannel()->slug === $channel->slug) {
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Channel $channel): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Channel $channel): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
109
app/Policies/Ecommerce/Payout/PayoutPolicy.php
Normal file
109
app/Policies/Ecommerce/Payout/PayoutPolicy.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Payout;
|
||||
|
||||
use App\Models\Ecommerce\Payouts\Payout;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class PayoutPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Payout $payout): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Payout $payout): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Payout $payout): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Payout $payout): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Payout $payout): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
109
app/Policies/Ecommerce/Product/Brand/BrandPolicy.php
Normal file
109
app/Policies/Ecommerce/Product/Brand/BrandPolicy.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Brand;
|
||||
|
||||
use App\Models\Ecommerce\Product\Brand\Brand;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class BrandPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Brand $brand): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Brand $brand): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Brand $brand): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Brand $brand): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Brand $brand): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
113
app/Policies/Ecommerce/Product/Category/CategoryPolicy.php
Normal file
113
app/Policies/Ecommerce/Product/Category/CategoryPolicy.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Category;
|
||||
|
||||
use App\Models\Ecommerce\Product\Category\Category;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class CategoryPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
if ($user->hasRole('vendor')) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Category $category): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Category $category): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Category $category): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Category $category): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Category $category): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
113
app/Policies/Ecommerce/Product/Collection/CollectionPolicy.php
Normal file
113
app/Policies/Ecommerce/Product/Collection/CollectionPolicy.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Collection;
|
||||
|
||||
use App\Models\Ecommerce\Product\Collection\Collection;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class CollectionPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
if ($user->hasRole(['vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Collection $collection): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Collection $collection): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Collection $collection): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Collection $collection): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Collection $collection): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
109
app/Policies/Ecommerce/Product/Coupon/CouponPolicy.php
Normal file
109
app/Policies/Ecommerce/Product/Coupon/CouponPolicy.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Coupon;
|
||||
|
||||
use App\Models\Ecommerce\Product\Coupon\Coupon;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class CouponPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Coupon $coupon): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Coupon $coupon): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Coupon $coupon): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Coupon $coupon): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Coupon $coupon): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
121
app/Policies/Ecommerce/Product/Inventory/InventoryPolicy.php
Normal file
121
app/Policies/Ecommerce/Product/Inventory/InventoryPolicy.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Inventory;
|
||||
|
||||
use App\Models\Ecommerce\Product\Inventory\Inventory;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class InventoryPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Inventory $inventory): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
if ($user->hasRole('vendor') && $user->ownsInventory($inventory)) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
if ($user->hasRole('vendor') && $user->doesntOwnInventory()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Inventory $inventory): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
if ($user->hasRole('vendor') && $user->ownsInventory($inventory)) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Inventory $inventory): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Inventory $inventory): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Inventory $inventory): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
109
app/Policies/Ecommerce/Product/Order/OrderItemPolicy.php
Normal file
109
app/Policies/Ecommerce/Product/Order/OrderItemPolicy.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Order;
|
||||
|
||||
use App\Models\Ecommerce\Product\Order\OrderItem;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class OrderItemPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'manager', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, OrderItem $orderItem): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, OrderItem $orderItem): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, OrderItem $orderItem): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, OrderItem $orderItem): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, OrderItem $orderItem): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
109
app/Policies/Ecommerce/Product/Order/OrderPolicy.php
Normal file
109
app/Policies/Ecommerce/Product/Order/OrderPolicy.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Order;
|
||||
|
||||
use App\Models\Ecommerce\Product\Order\Order;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class OrderPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'manager', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Order $order): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Order $order): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Order $order): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Order $order): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Order $order): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
121
app/Policies/Ecommerce/Product/Product/ProductPolicy.php
Normal file
121
app/Policies/Ecommerce/Product/Product/ProductPolicy.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Product;
|
||||
|
||||
use App\Models\Ecommerce\Product\Product\Product;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class ProductPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'manager', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Product $product): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
if ($user->hasRole('vendor') && $user->ownsProduct($product)) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Product $product): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
if ($user->hasRole('vendor') && $user->ownsProduct($product)) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Product $product): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
if ($user->hasRole('vendor') && $user->ownsProduct($product)) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Product $product): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Product $product): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
116
app/Policies/Ecommerce/Product/Property/AttributePolicy.php
Normal file
116
app/Policies/Ecommerce/Product/Property/AttributePolicy.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Property;
|
||||
|
||||
use App\Models\Ecommerce\Product\Property\Attribute;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class AttributePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Attribute $attribute): Response
|
||||
{
|
||||
if ($user->hasRole(['admin', 'vendor'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole('admin')) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Attribute $attribute): Response
|
||||
{
|
||||
if ($user->hasRole('admin')) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Attribute $attribute): Response
|
||||
{
|
||||
if (in_array($attribute->slug, [
|
||||
'size',
|
||||
'colour',
|
||||
])) {
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Attribute $attribute): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Attribute $attribute): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
109
app/Policies/Ecommerce/Product/Review/ReviewPolicy.php
Normal file
109
app/Policies/Ecommerce/Product/Review/ReviewPolicy.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies\Ecommerce\Product\Review;
|
||||
|
||||
use App\Models\Ecommerce\Product\Review\Review;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class ReviewPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Perform pre-authorization checks.
|
||||
*/
|
||||
public function before(User $user, string $ability): ?Response
|
||||
{
|
||||
if ($user->isMe()) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Review $review): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Review $review): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Review $review): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Review $review): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Review $review): Response
|
||||
{
|
||||
if ($user->hasRole(['admin'])) {
|
||||
return $this->allow();
|
||||
}
|
||||
|
||||
return $this->deny();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user