- PermissionSeeder: 29 permissions with role mapping (admin/manager/staff) - Policies updated to use hasPermissionTo() instead of hasRole() - ExportBackup command: JSON per-table backup with chunk processing - UserResource: CRUD users with role assignment (admin only) - RoleResource: CRUD roles with permission assignment (admin only) - UserPolicy + RolePolicy: admin-only access control - ImportCskh: detailed skip logging with color in dry-run mode - Widgets: permission-based visibility checks - Tests: 8/8 pass (21 assertions)
45 lines
963 B
PHP
45 lines
963 B
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\Product;
|
|
use App\Models\User;
|
|
|
|
class ProductPolicy
|
|
{
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $user->hasPermissionTo('view-product');
|
|
}
|
|
|
|
public function view(User $user, Product $product): bool
|
|
{
|
|
return $user->hasPermissionTo('view-product');
|
|
}
|
|
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->hasPermissionTo('create-product');
|
|
}
|
|
|
|
public function update(User $user, Product $product): bool
|
|
{
|
|
return $user->hasPermissionTo('update-product');
|
|
}
|
|
|
|
public function delete(User $user, Product $product): bool
|
|
{
|
|
return $user->hasPermissionTo('delete-product');
|
|
}
|
|
|
|
public function restore(User $user, Product $product): bool
|
|
{
|
|
return $user->hasRole('admin');
|
|
}
|
|
|
|
public function forceDelete(User $user, Product $product): bool
|
|
{
|
|
return $user->hasRole('admin');
|
|
}
|
|
}
|