| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- <?php
- 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" => "franchisee",
- "description" => "Franqueados",
- "bits" => Permission::MENU | Permission::VIEW,
- "children" => [
- [
- "scope" => "unit",
- "description" => "Unidades",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "franchisee-unit",
- "description" => "Unidades do Franqueado",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- // Pacotes / Aulas
- [
- "scope" => "class-package",
- "description" => "Pacotes (Franqueadora)",
- "bits" => Permission::ALL_PERMS,
- "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" => "class",
- "description" => "Aulas",
- "bits" => Permission::ALL_PERMS,
- "children" => [
- [
- "scope" => "class-attendance",
- "description" => "Frequência de Aulas",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- [
- "scope" => "modality",
- "description" => "Modalidades",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- // 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" => "student-contract",
- "description" => "Contratos de Alunos",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "media",
- "description" => "Mídias",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- // Kanban
- [
- "scope" => "kanban",
- "description" => "Kanban",
- "bits" => Permission::ALL_PERMS,
- "children" => [
- [
- "scope" => "kanban-status",
- "description" => "Status do Kanban",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "kanban-movement",
- "description" => "Movimentos do Kanban",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- // Suporte
- [
- "scope" => "support-ticket",
- "description" => "Chamados de Suporte",
- "bits" => Permission::ALL_PERMS,
- "children" => [
- [
- "scope" => "support-status",
- "description" => "Status de Suporte",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "support-movement",
- "description" => "Movimentos de Suporte",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- // 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" => "product",
- "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" => "financial",
- "description" => "Financeiro",
- "bits" => Permission::MENU | Permission::VIEW,
- "children" => [
- [
- "scope" => "financial-account-payable",
- "description" => "Contas a Pagar",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "financial-account-receive",
- "description" => "Contas a Receber",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "financial-invoice",
- "description" => "Notas Fiscais",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "financial-plan-account",
- "description" => "Plano de Contas",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- // Tesouraria
- [
- "scope" => "treasury",
- "description" => "Tesouraria",
- "bits" => Permission::MENU | Permission::VIEW,
- "children" => [
- [
- "scope" => "treasury-account",
- "description" => "Contas de Tesouraria",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "treasury-imports",
- "description" => "Importações de Tesouraria",
- "bits" => Permission::ALL_PERMS,
- "children" => [
- [
- "scope" => "treasury-import-line",
- "description" => "Linhas de Importação",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- [
- "scope" => "treasury-launch",
- "description" => "Lançamentos de Tesouraria",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- // Integrações
- [
- "scope" => "integrations",
- "description" => "Integrações",
- "bits" => Permission::ALL_PERMS,
- "children" => [
- [
- "scope" => "integration-variable",
- "description" => "Variáveis de Integração",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- // Feriados
- [
- "scope" => "holiday",
- "description" => "Feriados",
- "bits" => Permission::ALL_PERMS,
- "children" => [
- [
- "scope" => "base-holiday",
- "description" => "Feriados Base",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- // TBR
- [
- "scope" => "tbr",
- "description" => "TBR",
- "bits" => Permission::ALL_PERMS,
- "children" => [
- [
- "scope" => "royalties-base-bracket",
- "description" => "Faixas de Royalties Base",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "fnm-base-bracket",
- "description" => "Faixas de FNM Base",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "maintenance-base-bracket",
- "description" => "Faixas de Manutenção Base",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "franchisee-tbr",
- "description" => "TBR por Franqueado",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "franchisee-royalties-bracket",
- "description" => "Faixas de Royalties do Franqueado",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "franchisee-fnm-bracket",
- "description" => "Faixas de FNM do Franqueado",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "franchisee-maintenance-bracket",
- "description" => "Faixas de Manutenção do Franqueado",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "tbr-calculation",
- "description" => "Cálculo de TBR",
- "bits" => Permission::VIEW | Permission::ADD,
- "children" => [],
- ],
- [
- "scope" => "inhabitant-classification",
- "description" => "Classificações de Habitantes",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- [
- "scope" => "unit-inhabitant-classification",
- "description" => "Classificações de Habitantes por Unidade",
- "bits" => Permission::ALL_PERMS,
- "children" => [],
- ],
- ],
- ],
- // Configurações
- [
- "scope" => "config",
- "description" => "Configurações",
- "bits" => Permission::MENU | Permission::VIEW,
- "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" => [],
- ],
- ];
- $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,
- );
- if ($parent) {
- $parent->appendNode($permissionNode);
- }
- if (!empty($children)) {
- $this->createPermissionsAndChildren(
- permissions: $children,
- parent: $permissionNode,
- );
- }
- }
- }
- }
|