|
|
@@ -3,303 +3,91 @@
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
use App\Models\Permission;
|
|
|
-use App\Services\PermissionService;
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
class PermissionSeeder extends Seeder
|
|
|
{
|
|
|
- public function __construct(
|
|
|
- protected PermissionService $permissionService,
|
|
|
- ) {}
|
|
|
-
|
|
|
public function run(): void
|
|
|
{
|
|
|
$permissions = [
|
|
|
[
|
|
|
- "scope" => "dashboard",
|
|
|
- "description" => "Dashboard",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "franchisor_franchisee",
|
|
|
- "description" => "Franqueados",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- // Pacotes / Aulas
|
|
|
- [
|
|
|
- "scope" => "franchisor_packages",
|
|
|
- "description" => "Pacotes (Franqueadora)",
|
|
|
- "bits" => Permission::MENU | Permission::VIEW | Permission::ADD | Permission::EDIT,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "class-package-unit",
|
|
|
- "description" => "Pacotes (Unidade)",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "class-package-franchisee",
|
|
|
- "description" => "Pacotes (Franqueado)",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
+ 'scope' => 'dashboard',
|
|
|
+ 'description' => 'Dashboard',
|
|
|
+ 'bits' => Permission::ALL_PERMS,
|
|
|
],
|
|
|
[
|
|
|
- "scope" => "class",
|
|
|
- "description" => "Aulas",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [
|
|
|
- [
|
|
|
- "scope" => "class-attendance",
|
|
|
- "description" => "Frequência de Aulas",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- ],
|
|
|
+ 'scope' => 'franchisor_franchisee',
|
|
|
+ 'description' => 'Franqueados',
|
|
|
+ 'bits' => Permission::ALL_PERMS,
|
|
|
],
|
|
|
[
|
|
|
- "scope" => "modality",
|
|
|
- "description" => "Modalidades",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
+ 'scope' => 'franchisor_packages',
|
|
|
+ 'description' => 'Pacotes',
|
|
|
+ 'bits' => Permission::MENU | Permission::VIEW | Permission::ADD | Permission::EDIT,
|
|
|
],
|
|
|
- // Alunos
|
|
|
[
|
|
|
- "scope" => "student",
|
|
|
- "description" => "Alunos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [
|
|
|
- [
|
|
|
- "scope" => "student-history",
|
|
|
- "description" => "Histórico de Alunos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "student-media",
|
|
|
- "description" => "Mídias de Alunos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "student-responsible",
|
|
|
- "description" => "Responsáveis de Alunos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- ],
|
|
|
+ 'scope' => 'franchisor_products',
|
|
|
+ 'description' => 'Produtos',
|
|
|
+ 'bits' => Permission::CRUD,
|
|
|
],
|
|
|
[
|
|
|
- "scope" => "student-contract",
|
|
|
- "description" => "Contratos de Alunos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
+ 'scope' => 'franchisor_tbr',
|
|
|
+ 'description' => 'TBR',
|
|
|
+ 'bits' => Permission::MENU | Permission::VIEW | Permission::ADD | Permission::EDIT,
|
|
|
],
|
|
|
[
|
|
|
- "scope" => "media",
|
|
|
- "description" => "Mídias",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
+ 'scope' => 'franchisor_financial',
|
|
|
+ 'description' => 'Financeiro',
|
|
|
+ 'bits' => Permission::MENU | Permission::VIEW | Permission::ADD | Permission::EDIT,
|
|
|
],
|
|
|
- // Kanban
|
|
|
[
|
|
|
- "scope" => "franchisor_activities",
|
|
|
- "description" => "Atividades",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
+ 'scope' => 'franchisor_support',
|
|
|
+ 'description' => 'Suporte',
|
|
|
+ 'bits' => Permission::CRUD,
|
|
|
],
|
|
|
- // Suporte
|
|
|
[
|
|
|
- "scope" => "franchisor_support",
|
|
|
- "description" => "Chamados de Suporte",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
+ 'scope' => 'franchisor_activities',
|
|
|
+ 'description' => 'Atividades',
|
|
|
+ 'bits' => Permission::CRUD,
|
|
|
],
|
|
|
- // Notificações
|
|
|
[
|
|
|
- "scope" => "notification",
|
|
|
- "description" => "Notificações",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [
|
|
|
- [
|
|
|
- "scope" => "notification-recipient",
|
|
|
- "description" => "Destinatários de Notificações",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- ],
|
|
|
- ],
|
|
|
- // Produtos / Inventário
|
|
|
- [
|
|
|
- "scope" => "franchisor_products",
|
|
|
- "description" => "Produtos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [
|
|
|
- [
|
|
|
- "scope" => "product-kit",
|
|
|
- "description" => "Kits de Produtos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "product-movement",
|
|
|
- "description" => "Movimentação de Produtos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "product-order",
|
|
|
- "description" => "Pedidos de Produtos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [
|
|
|
- [
|
|
|
- "scope" => "product-order-item",
|
|
|
- "description" => "Itens de Pedido de Produtos",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- ],
|
|
|
- ],
|
|
|
- ],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "franchisor-inventory",
|
|
|
- "description" => "Estoque (Franqueadora)",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "franchisee-inventory",
|
|
|
- "description" => "Estoque (Franqueado)",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- // Fornecedores / Pagamentos
|
|
|
- [
|
|
|
- "scope" => "supplier",
|
|
|
- "description" => "Fornecedores",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "payment-method",
|
|
|
- "description" => "Formas de Pagamento",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- // Financeiro
|
|
|
- [
|
|
|
- "scope" => "franchisor_financial",
|
|
|
- "description" => "Financeiro",
|
|
|
- "bits" => Permission::MENU | Permission::VIEW | Permission::ADD | Permission::EDIT,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- // Feriados
|
|
|
- [
|
|
|
- "scope" => "holiday",
|
|
|
- "description" => "Feriados",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [
|
|
|
- [
|
|
|
- "scope" => "base-holiday",
|
|
|
- "description" => "Feriados Base",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- ],
|
|
|
- ],
|
|
|
- // TBR
|
|
|
- [
|
|
|
- "scope" => "franchisor_tbr",
|
|
|
- "description" => "TBR",
|
|
|
- "bits" => Permission::MENU | Permission::VIEW | Permission::ADD | Permission::EDIT,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- // Configurações
|
|
|
- [
|
|
|
- "scope" => "franchisor_registrations",
|
|
|
- "description" => "Cadastros",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [
|
|
|
- [
|
|
|
- "scope" => "config.user",
|
|
|
- "description" => "Usuários",
|
|
|
- "bits" => Permission::CRUD,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "config.user-type",
|
|
|
- "description" => "Tipos de Usuário",
|
|
|
- "bits" => Permission::CRUD,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "config.permission",
|
|
|
- "description" => "Permissões",
|
|
|
- "bits" => Permission::CRUD,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "config.city",
|
|
|
- "description" => "Cidades",
|
|
|
- "bits" => Permission::CRUD,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "config.country",
|
|
|
- "description" => "Países",
|
|
|
- "bits" => Permission::CRUD,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- [
|
|
|
- "scope" => "config.state",
|
|
|
- "description" => "Estados",
|
|
|
- "bits" => Permission::CRUD,
|
|
|
- "children" => [],
|
|
|
- ],
|
|
|
- ],
|
|
|
- ],
|
|
|
- // Unidade — escopos adicionais usados em subrotas de unit
|
|
|
- [
|
|
|
- "scope" => "unit-user",
|
|
|
- "description" => "Usuários da Unidade",
|
|
|
- "bits" => Permission::ALL_PERMS,
|
|
|
- "children" => [],
|
|
|
+ 'scope' => 'franchisor_registrations',
|
|
|
+ 'description' => 'Cadastros',
|
|
|
+ 'bits' => Permission::CRUD,
|
|
|
],
|
|
|
+ ...collect([
|
|
|
+ 'dashboard' => 'Dashboard',
|
|
|
+ 'students' => 'Alunos',
|
|
|
+ 'contracts' => 'Contratos',
|
|
|
+ 'classes' => 'Agenda / Aulas',
|
|
|
+ 'financial' => 'Financeiro',
|
|
|
+ 'packages' => 'Pacotes',
|
|
|
+ 'users' => 'Usuários',
|
|
|
+ 'unit' => 'Unidade',
|
|
|
+ 'integrations' => 'APIs',
|
|
|
+ 'support' => 'Suporte',
|
|
|
+ 'activities' => 'Atividades',
|
|
|
+ ])->map(fn (string $description, string $scope) => [
|
|
|
+ 'scope' => "franchisee_{$scope}",
|
|
|
+ 'description' => $description,
|
|
|
+ 'bits' => Permission::CRUD,
|
|
|
+ ])->values()->all(),
|
|
|
];
|
|
|
|
|
|
- $this->createPermissionsAndChildren(permissions: $permissions);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Recursively creates or updates permissions and handles nesting.
|
|
|
- */
|
|
|
- private function createPermissionsAndChildren(
|
|
|
- array $permissions,
|
|
|
- ?Permission $parent = null,
|
|
|
- ): void {
|
|
|
- foreach ($permissions as $permissionData) {
|
|
|
- $children = $permissionData["children"];
|
|
|
-
|
|
|
- unset($permissionData["children"]);
|
|
|
-
|
|
|
- $permissionNode = Permission::updateOrCreate(
|
|
|
- ["scope" => $permissionData["scope"]],
|
|
|
- $permissionData,
|
|
|
+ foreach ($permissions as $permission) {
|
|
|
+ Permission::updateOrCreate(
|
|
|
+ ['scope' => $permission['scope']],
|
|
|
+ $permission + ['parent_id' => null],
|
|
|
);
|
|
|
+ }
|
|
|
|
|
|
- if ($parent) {
|
|
|
- $parent->appendNode($permissionNode);
|
|
|
- }
|
|
|
+ $activeScopes = array_column($permissions, 'scope');
|
|
|
|
|
|
- if (!empty($children)) {
|
|
|
- $this->createPermissionsAndChildren(
|
|
|
- permissions: $children,
|
|
|
- parent: $permissionNode,
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
+ Permission::query()
|
|
|
+ ->whereNotIn('scope', $activeScopes)
|
|
|
+ ->orderByDesc('_lft')
|
|
|
+ ->get()
|
|
|
+ ->each
|
|
|
+ ->delete();
|
|
|
}
|
|
|
}
|