diff --git a/README.md b/README.md index 385f4db..37c0e4f 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,13 @@ Para poder actualizar la base de datos: Para inicializar la base de datos: ```sh -docker exec ogcore-php php bin/consoledoctrine:migrations:migrate --no-interaction +docker exec ogcore-php php bin/console doctrine:migrations:migrate --no-interaction ``` ```sh docker exec ogcore-php php bin/console doctrine:fixtures:load --no-interaction +docker exec ogcore-php php bin/console app:load-default-user-groups + ``` ## Test diff --git a/config/api_platform/OrganizationalUnit.yaml b/config/api_platform/OrganizationalUnit.yaml index e69de29..577b80a 100644 --- a/config/api_platform/OrganizationalUnit.yaml +++ b/config/api_platform/OrganizationalUnit.yaml @@ -0,0 +1,27 @@ +resources: + App\Entity\OrganizationalUnit: + processor: App\State\Processor\OrganizationalUnitProcessor + input: App\Dto\Input\OrganizationalUnitInput + output: App\Dto\Output\OrganizationalUnitOutput + normalization_context: + groups: ['default', 'organizational-unit:read'] + denormalization_context: + groups: ['organizational-unit:write'] + operations: + ApiPlatform\Metadata\GetCollection: + provider: App\State\Provider\OrganizationalUnitProvider + ApiPlatform\Metadata\Get: + provider: App\State\Provider\OrganizationalUnitProvider + ApiPlatform\Metadata\Put: + provider: App\State\Provider\OrganizationalUnitProvider + ApiPlatform\Metadata\Patch: + provider: App\State\Provider\OrganizationalUnitProvider + ApiPlatform\Metadata\Post: ~ + ApiPlatform\Metadata\Delete: ~ + +properties: + App\Entity\OrganizationalUnit: + id: + identifier: false + uuid: + identifier: true \ No newline at end of file diff --git a/config/api_platform/User.yaml b/config/api_platform/User.yaml index 8a75827..17e4801 100644 --- a/config/api_platform/User.yaml +++ b/config/api_platform/User.yaml @@ -1,8 +1,8 @@ resources: App\Entity\User: - processor: App\State\Processor\UserProcessor input: App\Dto\Input\UserInput output: App\Dto\Output\UserOutput + processor: App\State\Processor\UserProcessor normalization_context: groups: ['default', 'user:read'] denormalization_context: diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index 160cfd2..8fad293 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -17,7 +17,7 @@ api_platform: standard_put: true rfc_7807_compliant_errors: true event_listeners_backward_compatibility_layer: false - keep_legacy_inflector: false + keep_legacy_inflector: true docs_formats: jsonld: ['application/ld+json'] jsonopenapi: ['application/vnd.openapi+json'] diff --git a/config/packages/stof_doctrine_extensions.yaml b/config/packages/stof_doctrine_extensions.yaml index 1432072..c478c2c 100644 --- a/config/packages/stof_doctrine_extensions.yaml +++ b/config/packages/stof_doctrine_extensions.yaml @@ -3,4 +3,6 @@ stof_doctrine_extensions: orm: default: timestampable: true - blameable: true \ No newline at end of file + blameable: true + tree: true + sluggable: true \ No newline at end of file diff --git a/config/services.yaml b/config/services.yaml index af7a6a0..7e12544 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -35,3 +35,7 @@ services: $collectionProvider: '@api_platform.doctrine.orm.state.collection_provider' $itemProvider: '@api_platform.doctrine.orm.state.item_provider' + App\State\Provider\OrganizationalUnitProvider: + bind: + $collectionProvider: '@api_platform.doctrine.orm.state.collection_provider' + $itemProvider: '@api_platform.doctrine.orm.state.item_provider' \ No newline at end of file diff --git a/migrations/Version20240517085550.php b/migrations/Version20240517085550.php deleted file mode 100644 index bec091e..0000000 --- a/migrations/Version20240517085550.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(180) NOT NULL, roles JSON NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_IDENTIFIER_USERNAME (username), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE user'); - } -} diff --git a/migrations/Version20240517101651.php b/migrations/Version20240517101651.php deleted file mode 100644 index 66bf841..0000000 --- a/migrations/Version20240517101651.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE TABLE refresh_tokens (id INT AUTO_INCREMENT NOT NULL, refresh_token VARCHAR(128) NOT NULL, username VARCHAR(255) NOT NULL, valid DATETIME NOT NULL, UNIQUE INDEX UNIQ_9BACE7E1C74F2195 (refresh_token), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE refresh_tokens'); - } -} diff --git a/migrations/Version20240523091838.php b/migrations/Version20240523091838.php deleted file mode 100644 index 6f955c4..0000000 --- a/migrations/Version20240523091838.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE user ADD uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', ADD migration_id VARCHAR(255) DEFAULT NULL'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649D17F50A6 ON user (uuid)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP INDEX UNIQ_8D93D649D17F50A6 ON user'); - $this->addSql('ALTER TABLE user DROP uuid, DROP migration_id'); - } -} diff --git a/migrations/Version20240523093000.php b/migrations/Version20240523093000.php deleted file mode 100644 index 16f1851..0000000 --- a/migrations/Version20240523093000.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE user ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE user DROP created_at, DROP updated_at'); - } -} diff --git a/migrations/Version20240523093036.php b/migrations/Version20240523093036.php deleted file mode 100644 index 5d736be..0000000 --- a/migrations/Version20240523093036.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('ALTER TABLE user ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL, ADD created_by VARCHAR(255) DEFAULT NULL, ADD updated_by VARCHAR(255) DEFAULT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE user DROP created_at, DROP updated_at, DROP created_by, DROP updated_by'); - } -} diff --git a/migrations/Version20240523094836.php b/migrations/Version20240523094836.php deleted file mode 100644 index 478930d..0000000 --- a/migrations/Version20240523094836.php +++ /dev/null @@ -1,37 +0,0 @@ -addSql('CREATE TABLE user_group (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, roles JSON NOT NULL COMMENT \'(DC2Type:json)\', UNIQUE INDEX UNIQ_8F02BF9DD17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE user_group_user (user_group_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_3AE4BD51ED93D47 (user_group_id), INDEX IDX_3AE4BD5A76ED395 (user_id), PRIMARY KEY(user_group_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE user_group_user ADD CONSTRAINT FK_3AE4BD51ED93D47 FOREIGN KEY (user_group_id) REFERENCES user_group (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE user_group_user ADD CONSTRAINT FK_3AE4BD5A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE user_group_user DROP FOREIGN KEY FK_3AE4BD51ED93D47'); - $this->addSql('ALTER TABLE user_group_user DROP FOREIGN KEY FK_3AE4BD5A76ED395'); - $this->addSql('DROP TABLE user_group'); - $this->addSql('DROP TABLE user_group_user'); - } -} diff --git a/migrations/Version20240524063952.php b/migrations/Version20240524063952.php deleted file mode 100644 index f3f4231..0000000 --- a/migrations/Version20240524063952.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('CREATE TABLE organizational_unit (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_749AEB2DD17F50A6 (uuid), INDEX IDX_749AEB2D727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2D727ACA70 FOREIGN KEY (parent_id) REFERENCES organizational_unit (id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2D727ACA70'); - $this->addSql('DROP TABLE organizational_unit'); - } -} diff --git a/migrations/Version20240524065625.php b/migrations/Version20240524065625.php deleted file mode 100644 index 6941a70..0000000 --- a/migrations/Version20240524065625.php +++ /dev/null @@ -1,38 +0,0 @@ -addSql('CREATE TABLE network_settings (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, proxy VARCHAR(255) DEFAULT NULL, dns VARCHAR(255) DEFAULT NULL, netmask VARCHAR(255) DEFAULT NULL, router VARCHAR(255) DEFAULT NULL, ntp VARCHAR(255) DEFAULT NULL, p2p_time INT DEFAULT NULL, p2p_mode VARCHAR(255) DEFAULT NULL, mcast_ip VARCHAR(255) DEFAULT NULL, mcast_speed INT NOT NULL, mcast_mode VARCHAR(255) DEFAULT NULL, mcast_port INT DEFAULT NULL, UNIQUE INDEX UNIQ_48869B54D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - - $this->addSql('ALTER TABLE organizational_unit ADD network_settings_id INT DEFAULT NULL, ADD path VARCHAR(255) DEFAULT NULL'); - $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2D9B9A36D0 FOREIGN KEY (network_settings_id) REFERENCES network_settings (id)'); - $this->addSql('CREATE INDEX IDX_749AEB2D9B9A36D0 ON organizational_unit (network_settings_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2D9B9A36D0'); - $this->addSql('DROP TABLE network_settings'); - $this->addSql('DROP INDEX IDX_749AEB2D9B9A36D0 ON organizational_unit'); - $this->addSql('ALTER TABLE organizational_unit DROP network_settings_id, DROP path'); - } -} diff --git a/migrations/Version20240524083309.php b/migrations/Version20240524083309.php deleted file mode 100644 index cee2d72..0000000 --- a/migrations/Version20240524083309.php +++ /dev/null @@ -1,35 +0,0 @@ -addSql('CREATE TABLE user_organizational_unit (user_id INT NOT NULL, organizational_unit_id INT NOT NULL, INDEX IDX_5E59845FA76ED395 (user_id), INDEX IDX_5E59845FFB84408A (organizational_unit_id), PRIMARY KEY(user_id, organizational_unit_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE user_organizational_unit ADD CONSTRAINT FK_5E59845FA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE user_organizational_unit ADD CONSTRAINT FK_5E59845FFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE user_organizational_unit DROP FOREIGN KEY FK_5E59845FA76ED395'); - $this->addSql('ALTER TABLE user_organizational_unit DROP FOREIGN KEY FK_5E59845FFB84408A'); - $this->addSql('DROP TABLE user_organizational_unit'); - } -} diff --git a/migrations/Version20240527103936.php b/migrations/Version20240527103936.php deleted file mode 100644 index 802e375..0000000 --- a/migrations/Version20240527103936.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('ALTER TABLE user_group CHANGE roles permissions JSON NOT NULL COMMENT \'(DC2Type:json)\''); - $this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON user_group (name)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON user_group'); - $this->addSql('ALTER TABLE user_group CHANGE permissions roles JSON NOT NULL COMMENT \'(DC2Type:json)\''); - } -} diff --git a/migrations/Version20240528093352.php b/migrations/Version20240528093352.php new file mode 100644 index 0000000..60ec26a --- /dev/null +++ b/migrations/Version20240528093352.php @@ -0,0 +1,67 @@ +addSql('CREATE TABLE aulas (idaula INT AUTO_INCREMENT NOT NULL, nombreaula VARCHAR(255) NOT NULL, idcentro INT NOT NULL, urlfoto VARCHAR(255) NOT NULL, cagnon TINYINT(1) NOT NULL, pizarra TINYINT(1) NOT NULL, grupoid INT NOT NULL, ubicacion VARCHAR(255) NOT NULL, comentarios VARCHAR(255) NOT NULL, puestos INT NOT NULL, horaresevini TINYINT(1) NOT NULL, horaresevfin TINYINT(1) NOT NULL, modomul TINYINT(1) NOT NULL, ipmul VARCHAR(255) NOT NULL, pormul VARCHAR(255) NOT NULL, velmul VARCHAR(255) NOT NULL, router VARCHAR(255) NOT NULL, netmask VARCHAR(255) NOT NULL, dns VARCHAR(255) NOT NULL, proxy VARCHAR(255) NOT NULL, ntp VARCHAR(255) NOT NULL, modp2p VARCHAR(255) NOT NULL, timep2p VARCHAR(255) NOT NULL, validacion TINYINT(1) NOT NULL, paginalogin VARCHAR(255) NOT NULL, paginavalidacion VARCHAR(255) NOT NULL, inremotepc VARCHAR(255) NOT NULL, oglivedir VARCHAR(255) NOT NULL, PRIMARY KEY(idaula)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE centros (idcentro INT AUTO_INCREMENT NOT NULL, nombrecentro VARCHAR(255) NOT NULL, identidad INT NOT NULL, comentarios VARCHAR(255) DEFAULT NULL, directorio VARCHAR(255) DEFAULT NULL, PRIMARY KEY(idcentro)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE client (id INT AUTO_INCREMENT NOT NULL, organizational_unit_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, serial_number VARCHAR(255) DEFAULT NULL, netiface VARCHAR(255) DEFAULT NULL, net_driver VARCHAR(255) DEFAULT NULL, mac VARCHAR(255) DEFAULT NULL, ip VARCHAR(255) DEFAULT NULL, status VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_C7440455D17F50A6 (uuid), INDEX IDX_C7440455FB84408A (organizational_unit_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE gruposordenadores (idgrupo INT AUTO_INCREMENT NOT NULL, nombregrupoordenador VARCHAR(255) NOT NULL, idaula VARCHAR(255) NOT NULL, grupoid VARCHAR(255) NOT NULL, comentarios VARCHAR(255) NOT NULL, PRIMARY KEY(idgrupo)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE network_settings (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, proxy VARCHAR(255) DEFAULT NULL, dns VARCHAR(255) DEFAULT NULL, netmask VARCHAR(255) DEFAULT NULL, router VARCHAR(255) DEFAULT NULL, ntp VARCHAR(255) DEFAULT NULL, p2p_time INT DEFAULT NULL, p2p_mode VARCHAR(255) DEFAULT NULL, mcast_ip VARCHAR(255) DEFAULT NULL, mcast_speed INT NOT NULL, mcast_mode VARCHAR(255) DEFAULT NULL, mcast_port INT DEFAULT NULL, UNIQUE INDEX UNIQ_48869B54D17F50A6 (uuid), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE ordenadores (idordenador INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(idordenador)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE organizational_unit (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, network_settings_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, path VARCHAR(255) DEFAULT NULL, level INT DEFAULT NULL, slug VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_749AEB2DD17F50A6 (uuid), INDEX IDX_749AEB2D727ACA70 (parent_id), INDEX IDX_749AEB2D9B9A36D0 (network_settings_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE refresh_tokens (id INT AUTO_INCREMENT NOT NULL, refresh_token VARCHAR(128) NOT NULL, username VARCHAR(255) NOT NULL, valid DATETIME NOT NULL, UNIQUE INDEX UNIQ_9BACE7E1C74F2195 (refresh_token), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, username VARCHAR(180) NOT NULL, roles JSON NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8D93D649D17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_USERNAME (username), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE user_organizational_unit (user_id INT NOT NULL, organizational_unit_id INT NOT NULL, INDEX IDX_5E59845FA76ED395 (user_id), INDEX IDX_5E59845FFB84408A (organizational_unit_id), PRIMARY KEY(user_id, organizational_unit_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE user_group (id INT AUTO_INCREMENT NOT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, permissions JSON NOT NULL COMMENT \'(DC2Type:json)\', name VARCHAR(255) NOT NULL, enabled TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8F02BF9DD17F50A6 (uuid), UNIQUE INDEX UNIQ_IDENTIFIER_NAME (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE user_group_user (user_group_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_3AE4BD51ED93D47 (user_group_id), INDEX IDX_3AE4BD5A76ED395 (user_id), PRIMARY KEY(user_group_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455FB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)'); + $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2D727ACA70 FOREIGN KEY (parent_id) REFERENCES organizational_unit (id)'); + $this->addSql('ALTER TABLE organizational_unit ADD CONSTRAINT FK_749AEB2D9B9A36D0 FOREIGN KEY (network_settings_id) REFERENCES network_settings (id)'); + $this->addSql('ALTER TABLE user_organizational_unit ADD CONSTRAINT FK_5E59845FA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE user_organizational_unit ADD CONSTRAINT FK_5E59845FFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE user_group_user ADD CONSTRAINT FK_3AE4BD51ED93D47 FOREIGN KEY (user_group_id) REFERENCES user_group (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE user_group_user ADD CONSTRAINT FK_3AE4BD5A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C7440455FB84408A'); + $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2D727ACA70'); + $this->addSql('ALTER TABLE organizational_unit DROP FOREIGN KEY FK_749AEB2D9B9A36D0'); + $this->addSql('ALTER TABLE user_organizational_unit DROP FOREIGN KEY FK_5E59845FA76ED395'); + $this->addSql('ALTER TABLE user_organizational_unit DROP FOREIGN KEY FK_5E59845FFB84408A'); + $this->addSql('ALTER TABLE user_group_user DROP FOREIGN KEY FK_3AE4BD51ED93D47'); + $this->addSql('ALTER TABLE user_group_user DROP FOREIGN KEY FK_3AE4BD5A76ED395'); + $this->addSql('DROP TABLE aulas'); + $this->addSql('DROP TABLE centros'); + $this->addSql('DROP TABLE client'); + $this->addSql('DROP TABLE gruposordenadores'); + $this->addSql('DROP TABLE network_settings'); + $this->addSql('DROP TABLE ordenadores'); + $this->addSql('DROP TABLE organizational_unit'); + $this->addSql('DROP TABLE refresh_tokens'); + $this->addSql('DROP TABLE user'); + $this->addSql('DROP TABLE user_organizational_unit'); + $this->addSql('DROP TABLE user_group'); + $this->addSql('DROP TABLE user_group_user'); + } +} diff --git a/src/Command/Migration/MigrateOrganizationalUnitCommand.php b/src/Command/Migration/MigrateOrganizationalUnitCommand.php new file mode 100644 index 0000000..a595626 --- /dev/null +++ b/src/Command/Migration/MigrateOrganizationalUnitCommand.php @@ -0,0 +1,152 @@ +entityManagerSlave->getRepository(Centros::class)->findAll(); + $rooms = $this->entityManagerSlave->getRepository(Aulas::class)->findAll(); + $pcGroups = $this->entityManagerSlave->getRepository(Gruposordenadores::class)->findAll(); + $pcs = $this->entityManagerSlave->getRepository(Ordenadores::class)->findAll(); + + $organizationalUnitRepository = $this->entityManager->getRepository(OrganizationalUnit::class); + $clientRepository = $this->entityManager->getRepository(Client::class); + + /** Centros **/ + $output->writeln("CENTROS TOTAL: ". count($centers)); + foreach ($centers as $center){ + $centerOrganizationalUnit = null; + $centerOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $center->getIdcentro()]); + if(!$centerOrganizationalUnit){ + $centerOrganizationalUnit = new OrganizationalUnit(); + $centerOrganizationalUnit->setMigrationId($center->getIdcentro()); + $centerOrganizationalUnit->setName($center->getNombrecentro()); + $centerOrganizationalUnit->setComments($center->getComentarios()); + $this->entityManager->persist($centerOrganizationalUnit); + } + } + $this->entityManager->flush(); + + /** Aulas **/ + $output->writeln("AULAS TOTAL: ". count($rooms)); + foreach ($rooms as $room){ + $roomOrganizationalUnit = null; + $roomOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $room->getIdaula()]); + if(!$roomOrganizationalUnit){ + $roomOrganizationalUnit = new OrganizationalUnit(); + $roomOrganizationalUnit->setMigrationId($room->getIdaula()); + $roomOrganizationalUnit->setName($room->getNombreaula()); + $roomOrganizationalUnitParent = $organizationalUnitRepository->findOneBy(['migrationId' => $room->getIdcentro()]); + $roomOrganizationalUnit->setParent($roomOrganizationalUnitParent); + $this->entityManager->persist($roomOrganizationalUnit); + } + + $networkSettings = $roomOrganizationalUnit->getNetworkSettings(); + if(!$networkSettings){ + $networkSettings = new NetworkSettings(); + $roomOrganizationalUnit->setNetworkSettings($networkSettings); + $this->entityManager->persist($networkSettings); + } + $networkSettings->setProxy($room->getProxy()); + $networkSettings->setDns($room->getDns()); + $networkSettings->setNetmask($room->getNetmask()); + $networkSettings->setRouter($room->getRouter()); + $networkSettings->setNtp($room->getNtp()); + $networkSettings->setP2pTime($room->getTimep2p()); + $networkSettings->setP2pMode($room->getModp2p()); + $networkSettings->setMcastIp($room->getIpmul()); + $networkSettings->setMcastSpeed($room->getVelmul()); + $networkSettings->setMcastPort($room->getPormul()); + $networkSettings->setMcastMode($room->getModomul()); + } + + $this->entityManager->flush(); + + /** Grupo Ordenador **/ + $output->writeln("GRUPOS ORDENADORES ". count($rooms)); + foreach ($pcGroups as $group){ + $groupPcOrganizationalUnit = null; + $migrateParentId = ($group->getGrupoid() == 0) ? $group->getIdaula() : $group->getGrupoid(); + $groupPcOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $group->getIdgrupo()]); + if(!$groupPcOrganizationalUnit){ + $groupPcOrganizationalUnit = new OrganizationalUnit(); + $groupPcOrganizationalUnit->setMigrationId($group->getIdgrupo()); + $groupPcOrganizationalUnit->setName($group->getNombregrupoordenador()); + $groupPcOrganizationalUnit->setComments($group->getComentarios()); + $groupPcOrganizationalUnitParent = $organizationalUnitRepository->findOneBy(['migrationId' => $migrateParentId]); + $groupPcOrganizationalUnit->setParent($groupPcOrganizationalUnitParent); + $this->entityManager->persist($groupPcOrganizationalUnit); + } + } + $this->entityManager->flush(); + + /** Ordenadores **/ + foreach ($pcs as $pc){ + $newClient = $clientRepository->findOneBy(['migrationId' => $pc->getIdordenador()]); + if(!$newClient){ + $newClient = new Client(); + $newClient->setMigrationId($pc->getIdordenador()); + $this->entityManager->persist($newClient); + } + $newClient->setName($pc->getNombreordenador()); + $newClient->setSerialNumber($pc->getNumserie()); + $newClient->setNetiface($pc->getNetiface()); + $newClient->setNetdriver($pc->getNetdriver()); + $newClient->setMac($pc->getMac()); + $newClient->setIp($pc->getIp()); + //$client->setStatus(); + //$newClient->setCache($pc->getCache()); + //$newClient->setIdproautoexec($pc->getIdproautoexec()); + //$newClient->setOglive($pc->getOglivedir()); + + // Netboot + + //$migrationId = "" + + // HardwareProfile + //$hardwareProfile = $hardwareProfileRepository->findOneBy(['migrationId' => $pc->getIdperfilhard()]); + //$newClient->setHardwareProfile($hardwareProfile); + + // Menu + //$menu = $menuRepository->findOneBy(['migrationId' => $pc->getIdmenu()]); + //$newClient->setMenu($menu); + + // Repository + //$repository = $repositoryRepository->findOneBy(['migrationId' => $pc->getIdrepositorio()]); + //$newClient->setRepository($repository); + + // OrganizationalUnit + $migrationId = $pc->getGrupoid() == 0 ? $pc->getIdaula() : $pc->getGrupoid(); + $organizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]); + $newClient->setOrganizationalUnit($organizationalUnit); + + } + $this->entityManager->flush(); + + return 1; + } +} \ No newline at end of file diff --git a/src/DataFixtures/AppFixtures.php b/src/DataFixtures/AppFixtures.php index ded5655..8feb58e 100644 --- a/src/DataFixtures/AppFixtures.php +++ b/src/DataFixtures/AppFixtures.php @@ -5,36 +5,17 @@ namespace App\DataFixtures; use App\Factory\UserFactory; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Persistence\ObjectManager; -use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Output\BufferedOutput; -use Symfony\Component\HttpKernel\KernelInterface; class AppFixtures extends Fixture { CONST ADMIN_USER = 'ogadmin'; - public function __construct( - private readonly KernelInterface $kernel, - ) - { - } - /** * @throws \Exception */ public function load(ObjectManager $manager): void { UserFactory::createOne(['username' => self::ADMIN_USER]); - - $application = new Application($this->kernel); - - $input = new ArrayInput([ - 'command' => 'app:load-default-user-groups' - ]); - - $output = new BufferedOutput(); - $application->run($input, $output); } } diff --git a/src/Dto/Input/OrganizationalUnitInput.php b/src/Dto/Input/OrganizationalUnitInput.php index b2eb2ed..53f8d40 100644 --- a/src/Dto/Input/OrganizationalUnitInput.php +++ b/src/Dto/Input/OrganizationalUnitInput.php @@ -2,7 +2,33 @@ namespace App\Dto\Input; -class OrganizationalUnitInput -{ +use App\Entity\OrganizationalUnit; +use Symfony\Component\Serializer\Annotation\Groups; +use Symfony\Component\Validator\Constraints as Assert; +final class OrganizationalUnitInput +{ + #[Assert\NotBlank] + #[Groups(['organizational-unit:write'])] + public ?string $name = null; + + public function __construct(?OrganizationalUnit $organizationalUnit = null) + { + if (!$organizationalUnit) { + return; + } + + $this->name = $organizationalUnit->getName(); + } + + public function createOrUpdateEntity(?OrganizationalUnit $organizationalUnit = null): OrganizationalUnit + { + if (!$organizationalUnit) { + $organizationalUnit = new OrganizationalUnit(); + } + + $organizationalUnit->setName($this->name); + + return $organizationalUnit; + } } \ No newline at end of file diff --git a/src/Dto/Input/UserInput.php b/src/Dto/Input/UserInput.php index ce9e9a4..379c5f9 100644 --- a/src/Dto/Input/UserInput.php +++ b/src/Dto/Input/UserInput.php @@ -70,7 +70,10 @@ final class UserInput $user->setPassword($this->password); } - //$user->setAllowedOrganizationalUnits($this->allowedOrganizationalUnits); + foreach ($this->allowedOrganizationalUnits as $allowedOrganizationalUnit) { + $allowedOrganizationalUnitToAdd[] = $allowedOrganizationalUnit->getEntity(); + } + $user->setAllowedOrganizationalUnits( $allowedOrganizationalUnitToAdd ?? [] ); return $user; } diff --git a/src/Dto/Output/AbstractOutput.php b/src/Dto/Output/AbstractOutput.php index 2ca73e0..93f7e50 100644 --- a/src/Dto/Output/AbstractOutput.php +++ b/src/Dto/Output/AbstractOutput.php @@ -10,20 +10,21 @@ use Symfony\Component\Serializer\Annotation\Groups; abstract class AbstractOutput { #[ApiProperty(identifier: true)] - #[Groups(['default'])] + #[Groups('default')] public UuidInterface $uuid; #[ApiProperty(identifier: false)] - #[Groups(['default'])] + #[Groups('default')] public int $id; public function __construct(private readonly AbstractEntity $entity) { - $this->uuid = $entity->getUuid(); $this->id = $entity->getId(); + $this->uuid = $entity->getUuid(); } - public function getEntity(): AbstractEntity + #[ApiProperty(readable: false)] + public function getEntity(): ?AbstractEntity { return $this->entity; } diff --git a/src/Dto/Output/OrganizationalUnitOutput.php b/src/Dto/Output/OrganizationalUnitOutput.php index 204ee06..1b8bf80 100644 --- a/src/Dto/Output/OrganizationalUnitOutput.php +++ b/src/Dto/Output/OrganizationalUnitOutput.php @@ -2,7 +2,28 @@ namespace App\Dto\Output; -class OrganizationalUnitOutput -{ +use ApiPlatform\Metadata\Get; +use App\Entity\OrganizationalUnit; +use Symfony\Component\Serializer\Annotation\Groups; +#[Get(shortName: 'OrganizationalUnit')] +final class OrganizationalUnitOutput extends AbstractOutput +{ + #[Groups(['organizational-unit:read'])] + public string $name; + + #[Groups(['organizational-unit:read'])] + public \DateTime $createAt; + + #[Groups(['organizational-unit:read'])] + public ?string $createBy = null; + + public function __construct(OrganizationalUnit $organizationalUnit) + { + parent::__construct($organizationalUnit); + + $this->name = $organizationalUnit->getName(); + $this->createAt = $organizationalUnit->getCreatedAt(); + $this->createBy = $organizationalUnit->getCreatedBy(); + } } \ No newline at end of file diff --git a/src/Entity/Client.php b/src/Entity/Client.php new file mode 100644 index 0000000..4fa39ea --- /dev/null +++ b/src/Entity/Client.php @@ -0,0 +1,131 @@ +name; + } + + public function setName(?string $name): static + { + $this->name = $name; + + return $this; + } + + public function getSerialNumber(): ?string + { + return $this->serialNumber; + } + + public function setSerialNumber(?string $serialNumber): static + { + $this->serialNumber = $serialNumber; + + return $this; + } + + public function getNetiface(): ?string + { + return $this->netiface; + } + + public function setNetiface(?string $netiface): static + { + $this->netiface = $netiface; + + return $this; + } + + public function getNetDriver(): ?string + { + return $this->netDriver; + } + + public function setNetDriver(string $netDriver): static + { + $this->netDriver = $netDriver; + + return $this; + } + + public function getMac(): ?string + { + return $this->mac; + } + + public function setMac(?string $mac): static + { + $this->mac = $mac; + + return $this; + } + + public function getIp(): ?string + { + return $this->ip; + } + + public function setIp(?string $ip): static + { + $this->ip = $ip; + + return $this; + } + + public function getStatus(): ?string + { + return $this->status; + } + + public function setStatus(?string $status): static + { + $this->status = $status; + + return $this; + } + + public function getOrganizationalUnit(): ?OrganizationalUnit + { + return $this->organizationalUnit; + } + + public function setOrganizationalUnit(?OrganizationalUnit $organizationalUnit): static + { + $this->organizationalUnit = $organizationalUnit; + + return $this; + } +} diff --git a/src/Entity/Migration/Aulas.php b/src/Entity/Migration/Aulas.php new file mode 100644 index 0000000..d4179e3 --- /dev/null +++ b/src/Entity/Migration/Aulas.php @@ -0,0 +1,753 @@ +nombreaula = $nombreaula; + + return $this; + } + + /** + * Get nombreaula. + * + * @return string + */ + public function getNombreaula() + { + return $this->nombreaula; + } + + /** + * Set idcentro. + * + * @param int $idcentro + * + * @return Aulas + */ + public function setIdcentro($idcentro) + { + $this->idcentro = $idcentro; + + return $this; + } + + /** + * Get idcentro. + * + * @return int + */ + public function getIdcentro() + { + return $this->idcentro; + } + + /** + * Set urlfoto. + * + * @param string|null $urlfoto + * + * @return Aulas + */ + public function setUrlfoto($urlfoto = null) + { + $this->urlfoto = $urlfoto; + + return $this; + } + + /** + * Get urlfoto. + * + * @return string|null + */ + public function getUrlfoto() + { + return $this->urlfoto; + } + + /** + * Set cagnon. + * + * @param bool|null $cagnon + * + * @return Aulas + */ + public function setCagnon($cagnon = null) + { + $this->cagnon = $cagnon; + + return $this; + } + + /** + * Get cagnon. + * + * @return bool|null + */ + public function getCagnon() + { + return $this->cagnon; + } + + /** + * Set pizarra. + * + * @param bool|null $pizarra + * + * @return Aulas + */ + public function setPizarra($pizarra = null) + { + $this->pizarra = $pizarra; + + return $this; + } + + /** + * Get pizarra. + * + * @return bool|null + */ + public function getPizarra() + { + return $this->pizarra; + } + + /** + * Set grupoid. + * + * @param int|null $grupoid + * + * @return Aulas + */ + public function setGrupoid($grupoid = null) + { + $this->grupoid = $grupoid; + + return $this; + } + + /** + * Get grupoid. + * + * @return int|null + */ + public function getGrupoid() + { + return $this->grupoid; + } + + /** + * Set ubicacion. + * + * @param string|null $ubicacion + * + * @return Aulas + */ + public function setUbicacion($ubicacion = null) + { + $this->ubicacion = $ubicacion; + + return $this; + } + + /** + * Get ubicacion. + * + * @return string|null + */ + public function getUbicacion() + { + return $this->ubicacion; + } + + /** + * Set comentarios. + * + * @param string|null $comentarios + * + * @return Aulas + */ + public function setComentarios($comentarios = null) + { + $this->comentarios = $comentarios; + + return $this; + } + + /** + * Get comentarios. + * + * @return string|null + */ + public function getComentarios() + { + return $this->comentarios; + } + + /** + * Set puestos. + * + * @param int|null $puestos + * + * @return Aulas + */ + public function setPuestos($puestos = null) + { + $this->puestos = $puestos; + + return $this; + } + + /** + * Get puestos. + * + * @return int|null + */ + public function getPuestos() + { + return $this->puestos; + } + + /** + * Set horaresevini. + * + * @param bool|null $horaresevini + * + * @return Aulas + */ + public function setHoraresevini($horaresevini = null) + { + $this->horaresevini = $horaresevini; + + return $this; + } + + /** + * Get horaresevini. + * + * @return bool|null + */ + public function getHoraresevini() + { + return $this->horaresevini; + } + + /** + * Set horaresevfin. + * + * @param bool|null $horaresevfin + * + * @return Aulas + */ + public function setHoraresevfin($horaresevfin = null) + { + $this->horaresevfin = $horaresevfin; + + return $this; + } + + /** + * Get horaresevfin. + * + * @return bool|null + */ + public function getHoraresevfin() + { + return $this->horaresevfin; + } + + /** + * Set modomul. + * + * @param bool $modomul + * + * @return Aulas + */ + public function setModomul($modomul) + { + $this->modomul = $modomul; + + return $this; + } + + /** + * Get modomul. + * + * @return bool + */ + public function getModomul() + { + return $this->modomul; + } + + /** + * Set ipmul. + * + * @param string $ipmul + * + * @return Aulas + */ + public function setIpmul($ipmul) + { + $this->ipmul = $ipmul; + + return $this; + } + + /** + * Get ipmul. + * + * @return string + */ + public function getIpmul() + { + return $this->ipmul; + } + + /** + * Set pormul. + * + * @param int $pormul + * + * @return Aulas + */ + public function setPormul($pormul) + { + $this->pormul = $pormul; + + return $this; + } + + /** + * Get pormul. + * + * @return int + */ + public function getPormul() + { + return $this->pormul; + } + + /** + * Set velmul. + * + * @param int $velmul + * + * @return Aulas + */ + public function setVelmul($velmul) + { + $this->velmul = $velmul; + + return $this; + } + + /** + * Get velmul. + * + * @return int + */ + public function getVelmul() + { + return $this->velmul; + } + + /** + * Set router. + * + * @param string|null $router + * + * @return Aulas + */ + public function setRouter($router = null) + { + $this->router = $router; + + return $this; + } + + /** + * Get router. + * + * @return string|null + */ + public function getRouter() + { + return $this->router; + } + + /** + * Set netmask. + * + * @param string|null $netmask + * + * @return Aulas + */ + public function setNetmask($netmask = null) + { + $this->netmask = $netmask; + + return $this; + } + + /** + * Get netmask. + * + * @return string|null + */ + public function getNetmask() + { + return $this->netmask; + } + + /** + * Set dns. + * + * @param string|null $dns + * + * @return Aulas + */ + public function setDns($dns = null) + { + $this->dns = $dns; + + return $this; + } + + /** + * Get dns. + * + * @return string|null + */ + public function getDns() + { + return $this->dns; + } + + /** + * Set proxy. + * + * @param string|null $proxy + * + * @return Aulas + */ + public function setProxy($proxy = null) + { + $this->proxy = $proxy; + + return $this; + } + + /** + * Get proxy. + * + * @return string|null + */ + public function getProxy() + { + return $this->proxy; + } + + /** + * Set ntp. + * + * @param string|null $ntp + * + * @return Aulas + */ + public function setNtp($ntp = null) + { + $this->ntp = $ntp; + + return $this; + } + + /** + * Get ntp. + * + * @return string|null + */ + public function getNtp() + { + return $this->ntp; + } + + /** + * Set modp2p. + * + * @param string|null $modp2p + * + * @return Aulas + */ + public function setModp2p($modp2p = null) + { + $this->modp2p = $modp2p; + + return $this; + } + + /** + * Get modp2p. + * + * @return string|null + */ + public function getModp2p() + { + return $this->modp2p; + } + + /** + * Set timep2p. + * + * @param int $timep2p + * + * @return Aulas + */ + public function setTimep2p($timep2p) + { + $this->timep2p = $timep2p; + + return $this; + } + + /** + * Get timep2p. + * + * @return int + */ + public function getTimep2p() + { + return $this->timep2p; + } + + /** + * Set validacion. + * + * @param bool|null $validacion + * + * @return Aulas + */ + public function setValidacion($validacion = null) + { + $this->validacion = $validacion; + + return $this; + } + + /** + * Get validacion. + * + * @return bool|null + */ + public function getValidacion() + { + return $this->validacion; + } + + /** + * Set paginalogin. + * + * @param string|null $paginalogin + * + * @return Aulas + */ + public function setPaginalogin($paginalogin = null) + { + $this->paginalogin = $paginalogin; + + return $this; + } + + /** + * Get paginalogin. + * + * @return string|null + */ + public function getPaginalogin() + { + return $this->paginalogin; + } + + /** + * Set paginavalidacion. + * + * @param string|null $paginavalidacion + * + * @return Aulas + */ + public function setPaginavalidacion($paginavalidacion = null) + { + $this->paginavalidacion = $paginavalidacion; + + return $this; + } + + /** + * Get paginavalidacion. + * + * @return string|null + */ + public function getPaginavalidacion() + { + return $this->paginavalidacion; + } + + /** + * Set inremotepc. + * + * @param bool|null $inremotepc + * + * @return Aulas + */ + public function setInremotepc($inremotepc = null) + { + $this->inremotepc = $inremotepc; + + return $this; + } + + /** + * Get inremotepc. + * + * @return bool|null + */ + public function getInremotepc() + { + return $this->inremotepc; + } + + /** + * Set oglivedir. + * + * @param string $oglivedir + * + * @return Aulas + */ + public function setOglivedir($oglivedir) + { + $this->oglivedir = $oglivedir; + + return $this; + } + + /** + * Get oglivedir. + * + * @return string + */ + public function getOglivedir() + { + return $this->oglivedir; + } + + /** + * Get idaula. + * + * @return int + */ + public function getIdaula() + { + return $this->idaula; + } +} diff --git a/src/Entity/Migration/Centros.php b/src/Entity/Migration/Centros.php new file mode 100644 index 0000000..1978a02 --- /dev/null +++ b/src/Entity/Migration/Centros.php @@ -0,0 +1,133 @@ +nombrecentro = $nombrecentro; + + return $this; + } + + /** + * Get nombrecentro. + * + * @return string + */ + public function getNombrecentro() + { + return $this->nombrecentro; + } + + /** + * Set identidad. + * + * @param int|null $identidad + * + * @return Centros + */ + public function setIdentidad($identidad = null) + { + $this->identidad = $identidad; + + return $this; + } + + /** + * Get identidad. + * + * @return int|null + */ + public function getIdentidad() + { + return $this->identidad; + } + + /** + * Set comentarios. + * + * @param string|null $comentarios + * + * @return Centros + */ + public function setComentarios($comentarios = null) + { + $this->comentarios = $comentarios; + + return $this; + } + + /** + * Get comentarios. + * + * @return string|null + */ + public function getComentarios() + { + return $this->comentarios; + } + + /** + * Set directorio. + * + * @param string|null $directorio + * + * @return Centros + */ + public function setDirectorio($directorio = null) + { + $this->directorio = $directorio; + + return $this; + } + + /** + * Get directorio. + * + * @return string|null + */ + public function getDirectorio() + { + return $this->directorio; + } + + /** + * Get idcentro. + * + * @return int + */ + public function getIdcentro() + { + return $this->idcentro; + } +} diff --git a/src/Entity/Migration/Gruposordenadores.php b/src/Entity/Migration/Gruposordenadores.php new file mode 100644 index 0000000..d2a27b4 --- /dev/null +++ b/src/Entity/Migration/Gruposordenadores.php @@ -0,0 +1,133 @@ +nombregrupoordenador = $nombregrupoordenador; + + return $this; + } + + /** + * Get nombregrupoordenador. + * + * @return string + */ + public function getNombregrupoordenador() + { + return $this->nombregrupoordenador; + } + + /** + * Set idaula. + * + * @param int $idaula + * + * @return Gruposordenadores + */ + public function setIdaula($idaula) + { + $this->idaula = $idaula; + + return $this; + } + + /** + * Get idaula. + * + * @return int + */ + public function getIdaula() + { + return $this->idaula; + } + + /** + * Set grupoid. + * + * @param int|null $grupoid + * + * @return Gruposordenadores + */ + public function setGrupoid($grupoid = null) + { + $this->grupoid = $grupoid; + + return $this; + } + + /** + * Get grupoid. + * + * @return int|null + */ + public function getGrupoid() + { + return $this->grupoid; + } + + /** + * Set comentarios. + * + * @param string|null $comentarios + * + * @return Gruposordenadores + */ + public function setComentarios($comentarios = null) + { + $this->comentarios = $comentarios; + + return $this; + } + + /** + * Get comentarios. + * + * @return string|null + */ + public function getComentarios() + { + return $this->comentarios; + } + + /** + * Get idgrupo. + * + * @return int + */ + public function getIdgrupo() + { + return $this->idgrupo; + } +} diff --git a/src/Entity/Migration/Ordenadores.php b/src/Entity/Migration/Ordenadores.php new file mode 100644 index 0000000..351defe --- /dev/null +++ b/src/Entity/Migration/Ordenadores.php @@ -0,0 +1,663 @@ +nombreordenador = $nombreordenador; + + return $this; + } + + /** + * Get nombreordenador. + * + * @return string|null + */ + public function getNombreordenador() + { + return $this->nombreordenador; + } + + /** + * Set numserie. + * + * @param string|null $numserie + * + * @return Ordenadores + */ + public function setNumserie($numserie = null) + { + $this->numserie = $numserie; + + return $this; + } + + /** + * Get numserie. + * + * @return string|null + */ + public function getNumserie() + { + return $this->numserie; + } + + /** + * Set ip. + * + * @param string $ip + * + * @return Ordenadores + */ + public function setIp($ip) + { + $this->ip = $ip; + + return $this; + } + + /** + * Get ip. + * + * @return string + */ + public function getIp() + { + return $this->ip; + } + + /** + * Set mac. + * + * @param string|null $mac + * + * @return Ordenadores + */ + public function setMac($mac = null) + { + $this->mac = $mac; + + return $this; + } + + /** + * Get mac. + * + * @return string|null + */ + public function getMac() + { + return $this->mac; + } + + /** + * Set idaula. + * + * @param int|null $idaula + * + * @return Ordenadores + */ + public function setIdaula($idaula = null) + { + $this->idaula = $idaula; + + return $this; + } + + /** + * Get idaula. + * + * @return int|null + */ + public function getIdaula() + { + return $this->idaula; + } + + /** + * Set idperfilhard. + * + * @param int|null $idperfilhard + * + * @return Ordenadores + */ + public function setIdperfilhard($idperfilhard = null) + { + $this->idperfilhard = $idperfilhard; + + return $this; + } + + /** + * Get idperfilhard. + * + * @return int|null + */ + public function getIdperfilhard() + { + return $this->idperfilhard; + } + + /** + * Set idrepositorio. + * + * @param int|null $idrepositorio + * + * @return Ordenadores + */ + public function setIdrepositorio($idrepositorio = null) + { + $this->idrepositorio = $idrepositorio; + + return $this; + } + + /** + * Get idrepositorio. + * + * @return int|null + */ + public function getIdrepositorio() + { + return $this->idrepositorio; + } + + /** + * Set grupoid. + * + * @param int|null $grupoid + * + * @return Ordenadores + */ + public function setGrupoid($grupoid = null) + { + $this->grupoid = $grupoid; + + return $this; + } + + /** + * Get grupoid. + * + * @return int|null + */ + public function getGrupoid() + { + return $this->grupoid; + } + + /** + * Set idmenu. + * + * @param int|null $idmenu + * + * @return Ordenadores + */ + public function setIdmenu($idmenu = null) + { + $this->idmenu = $idmenu; + + return $this; + } + + /** + * Get idmenu. + * + * @return int|null + */ + public function getIdmenu() + { + return $this->idmenu; + } + + /** + * Set cache. + * + * @param int|null $cache + * + * @return Ordenadores + */ + public function setCache($cache = null) + { + $this->cache = $cache; + + return $this; + } + + /** + * Get cache. + * + * @return int|null + */ + public function getCache() + { + return $this->cache; + } + + /** + * Set router. + * + * @param string $router + * + * @return Ordenadores + */ + public function setRouter($router) + { + $this->router = $router; + + return $this; + } + + /** + * Get router. + * + * @return string + */ + public function getRouter() + { + return $this->router; + } + + /** + * Set mascara. + * + * @param string $mascara + * + * @return Ordenadores + */ + public function setMascara($mascara) + { + $this->mascara = $mascara; + + return $this; + } + + /** + * Get mascara. + * + * @return string + */ + public function getMascara() + { + return $this->mascara; + } + + /** + * Set idproautoexec. + * + * @param int $idproautoexec + * + * @return Ordenadores + */ + public function setIdproautoexec($idproautoexec) + { + $this->idproautoexec = $idproautoexec; + + return $this; + } + + /** + * Get idproautoexec. + * + * @return int + */ + public function getIdproautoexec() + { + return $this->idproautoexec; + } + + /** + * Set arranque. + * + * @param string $arranque + * + * @return Ordenadores + */ + public function setArranque($arranque) + { + $this->arranque = $arranque; + + return $this; + } + + /** + * Get arranque. + * + * @return string + */ + public function getArranque() + { + return $this->arranque; + } + + /** + * Set netiface. + * + * @param string|null $netiface + * + * @return Ordenadores + */ + public function setNetiface($netiface = null) + { + $this->netiface = $netiface; + + return $this; + } + + /** + * Get netiface. + * + * @return string|null + */ + public function getNetiface() + { + return $this->netiface; + } + + /** + * Set netdriver. + * + * @param string $netdriver + * + * @return Ordenadores + */ + public function setNetdriver($netdriver) + { + $this->netdriver = $netdriver; + + return $this; + } + + /** + * Get netdriver. + * + * @return string + */ + public function getNetdriver() + { + return $this->netdriver; + } + + /** + * Set fotoord. + * + * @param string $fotoord + * + * @return Ordenadores + */ + public function setFotoord($fotoord) + { + $this->fotoord = $fotoord; + + return $this; + } + + /** + * Get fotoord. + * + * @return string + */ + public function getFotoord() + { + return $this->fotoord; + } + + /** + * Set validacion. + * + * @param bool|null $validacion + * + * @return Ordenadores + */ + public function setValidacion($validacion = null) + { + $this->validacion = $validacion; + + return $this; + } + + /** + * Get validacion. + * + * @return bool|null + */ + public function getValidacion() + { + return $this->validacion; + } + + /** + * Set paginalogin. + * + * @param string|null $paginalogin + * + * @return Ordenadores + */ + public function setPaginalogin($paginalogin = null) + { + $this->paginalogin = $paginalogin; + + return $this; + } + + /** + * Get paginalogin. + * + * @return string|null + */ + public function getPaginalogin() + { + return $this->paginalogin; + } + + /** + * Set paginavalidacion. + * + * @param string|null $paginavalidacion + * + * @return Ordenadores + */ + public function setPaginavalidacion($paginavalidacion = null) + { + $this->paginavalidacion = $paginavalidacion; + + return $this; + } + + /** + * Get paginavalidacion. + * + * @return string|null + */ + public function getPaginavalidacion() + { + return $this->paginavalidacion; + } + + /** + * Set agentkey. + * + * @param string|null $agentkey + * + * @return Ordenadores + */ + public function setAgentkey($agentkey = null) + { + $this->agentkey = $agentkey; + + return $this; + } + + /** + * Get agentkey. + * + * @return string|null + */ + public function getAgentkey() + { + return $this->agentkey; + } + + /** + * Set oglivedir. + * + * @param string $oglivedir + * + * @return Ordenadores + */ + public function setOglivedir($oglivedir) + { + $this->oglivedir = $oglivedir; + + return $this; + } + + /** + * Get oglivedir. + * + * @return string + */ + public function getOglivedir() + { + return $this->oglivedir; + } + + /** + * Get idordenador. + * + * @return int + */ + public function getIdordenador() + { + return $this->idordenador; + } +} diff --git a/src/Entity/NameableTrait.php b/src/Entity/NameableTrait.php index 5510771..fdeadfa 100644 --- a/src/Entity/NameableTrait.php +++ b/src/Entity/NameableTrait.php @@ -2,6 +2,8 @@ namespace App\Entity; +use Doctrine\ORM\Mapping as ORM; + trait NameableTrait { #[ORM\Column(length: 255)] diff --git a/src/Entity/OrganizationalUnit.php b/src/Entity/OrganizationalUnit.php index 6de54da..014c847 100644 --- a/src/Entity/OrganizationalUnit.php +++ b/src/Entity/OrganizationalUnit.php @@ -2,14 +2,14 @@ namespace App\Entity; -use App\Repository\OrganizationalUnitRepository; use Gedmo\Mapping\Annotation as Gedmo; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Gedmo\Tree\Entity\Repository\MaterializedPathRepository; -#[Gedmo\Tree(type: 'materialized-path')] -#[ORM\Entity(repositoryClass: OrganizationalUnitRepository::class)] +#[Gedmo\Tree(type: 'materializedPath')] +#[ORM\Entity(repositoryClass: MaterializedPathRepository::class)] class OrganizationalUnit extends AbstractEntity { use NameableTrait; @@ -20,10 +20,19 @@ class OrganizationalUnit extends AbstractEntity #[ORM\Column(length: 255, nullable: true)] private ?string $comments = null; - #[Gedmo\TreePath(separator: '/', appendId: true)] + #[Gedmo\TreePath(separator: '/', appendId: false, startsWithSeparator: true, endsWithSeparator: false)] #[ORM\Column(length: 255, nullable: true)] private ?string $path = null; + #[Gedmo\TreeLevel] + #[ORM\Column(length: 255, nullable: true)] + private ?int $level; + + #[Gedmo\TreePathSource] + #[Gedmo\Slug(fields: ['name'])] + #[ORM\Column(length: 255, nullable: true)] + private ?string $slug = null; + #[Gedmo\TreeParent] #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'organizationalUnits')] private ?self $parent = null; @@ -31,7 +40,7 @@ class OrganizationalUnit extends AbstractEntity /** * @var Collection */ - #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] + #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)] private Collection $organizationalUnits; #[ORM\ManyToOne(inversedBy: 'organizationalUnits')] @@ -43,11 +52,18 @@ class OrganizationalUnit extends AbstractEntity #[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'allowedOrganizationalUnits')] private Collection $users; + /** + * @var Collection + */ + #[ORM\OneToMany(mappedBy: 'organizationalUnit', targetEntity: Client::class)] + private Collection $clients; + public function __construct() { parent::__construct(); $this->organizationalUnits = new ArrayCollection(); $this->users = new ArrayCollection(); + $this->clients = new ArrayCollection(); } public function getDescription(): ?string @@ -86,6 +102,30 @@ class OrganizationalUnit extends AbstractEntity return $this; } + public function getLevel(): ?int + { + return $this->level; + } + + public function setLevel(?int $level): static + { + $this->level = $level; + + return $this; + } + + public function getSlug(): ?string + { + return $this->slug; + } + + public function setSlug(?string $slug): static + { + $this->slug = $slug; + + return $this; + } + public function getParent(): ?self { return $this->parent; @@ -166,4 +206,33 @@ class OrganizationalUnit extends AbstractEntity return $this; } + + /** + * @return Collection + */ + public function getClients(): Collection + { + return $this->clients; + } + + public function addClient(Client $client): static + { + if (!$this->clients->contains($client)) { + $this->clients->add($client); + $client->setOrganizationalUnit($this); + } + + return $this; + } + + public function removeClient(Client $client): static + { + if ($this->clients->removeElement($client)) { + if ($client->getOrganizationalUnit() === $this) { + $client->setOrganizationalUnit(null); + } + } + + return $this; + } } diff --git a/src/Entity/ToggleableTrait.php b/src/Entity/ToggleableTrait.php index 5e724da..7bce1d3 100644 --- a/src/Entity/ToggleableTrait.php +++ b/src/Entity/ToggleableTrait.php @@ -2,6 +2,8 @@ namespace App\Entity; +use Doctrine\ORM\Mapping as ORM; + trait ToggleableTrait { #[ORM\Column(type: 'boolean')] diff --git a/src/Entity/User.php b/src/Entity/User.php index 2349dd7..e7f4c6d 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -91,7 +91,7 @@ class User extends AbstractEntity implements UserInterface, PasswordAuthenticate foreach ($this->getUserGroups() as $userGroup) { if ($userGroup->isEnabled()){ - $roles = array_merge($roles, $userGroup->getRoles()); + $roles = array_merge($roles, $userGroup->getPermissions()); } } @@ -178,6 +178,17 @@ class User extends AbstractEntity implements UserInterface, PasswordAuthenticate return $this->allowedOrganizationalUnits; } + public function setAllowedOrganizationalUnits(array $allowedOrganizationalUnits): static + { + $this->allowedOrganizationalUnits->clear(); + + foreach ($allowedOrganizationalUnits as $allowedOrganizationalUnit){ + $this->addAllowedOrganizationalUnit($allowedOrganizationalUnit); + } + + return $this; + } + public function addAllowedOrganizationalUnit(OrganizationalUnit $allowedOrganizationalUnit): static { if (!$this->allowedOrganizationalUnits->contains($allowedOrganizationalUnit)) { diff --git a/src/Entity/UserGroup.php b/src/Entity/UserGroup.php index 32c8ce4..a017aa9 100644 --- a/src/Entity/UserGroup.php +++ b/src/Entity/UserGroup.php @@ -14,11 +14,9 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; #[UniqueEntity(fields: ['name'], message: 'There is already an role with this name')] class UserGroup extends AbstractEntity { + use NameableTrait; use ToggleableTrait; - #[ORM\Column(length: 255)] - private ?string $name = null; - #[ORM\Column(type: Types::JSON)] private array $permissions = []; @@ -35,18 +33,6 @@ class UserGroup extends AbstractEntity $this->users = new ArrayCollection(); } - public function getName(): ?string - { - return $this->name; - } - - public function setName(string $name): static - { - $this->name = $name; - - return $this; - } - public function getPermissions(): array { return $this->permissions; diff --git a/src/Repository/ClientRepository.php b/src/Repository/ClientRepository.php new file mode 100644 index 0000000..81c3e7f --- /dev/null +++ b/src/Repository/ClientRepository.php @@ -0,0 +1,43 @@ + + */ +class ClientRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Client::class); + } + + // /** + // * @return Client[] Returns an array of Client objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('c.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Client + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/OrganizationalUnitRepository.php b/src/Repository/OrganizationalUnitRepository.php index 591f292..566214c 100644 --- a/src/Repository/OrganizationalUnitRepository.php +++ b/src/Repository/OrganizationalUnitRepository.php @@ -9,35 +9,10 @@ use Doctrine\Persistence\ManagerRegistry; /** * @extends ServiceEntityRepository */ -class OrganizationalUnitRepository extends ServiceEntityRepository +class OrganizationalUnitRepository extends AbstractRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, OrganizationalUnit::class); } - - // /** - // * @return OrganizationalUnit[] Returns an array of OrganizationalUnit objects - // */ - // public function findByExampleField($value): array - // { - // return $this->createQueryBuilder('o') - // ->andWhere('o.exampleField = :val') - // ->setParameter('val', $value) - // ->orderBy('o.id', 'ASC') - // ->setMaxResults(10) - // ->getQuery() - // ->getResult() - // ; - // } - - // public function findOneBySomeField($value): ?OrganizationalUnit - // { - // return $this->createQueryBuilder('o') - // ->andWhere('o.exampleField = :val') - // ->setParameter('val', $value) - // ->getQuery() - // ->getOneOrNullResult() - // ; - // } } diff --git a/src/State/Processor/OrganizationalUnitProcessor.php b/src/State/Processor/OrganizationalUnitProcessor.php new file mode 100644 index 0000000..4dd6aac --- /dev/null +++ b/src/State/Processor/OrganizationalUnitProcessor.php @@ -0,0 +1,68 @@ +processCreateOrUpdate($data, $operation, $uriVariables, $context); + case $operation instanceof Delete: + return $this->processDelete($data, $operation, $uriVariables, $context); + } + } + + /** + * @throws \Exception + */ + private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): OrganizationalUnitOutput + { + if (!($data instanceof OrganizationalUnitOutput)) { + throw new \Exception(sprintf('data is not instance of %s', OrganizationalUnitInput::class)); + } + + $entity = null; + if (isset($uriVariables['uuid'])) { + $entity = $this->organizationalUnitRepository->findOneByUuid($uriVariables['uuid']); + } + + $organizationalUnit = $data->createOrUpdateEntity($entity); + $this->validator->validate($organizationalUnit); + $this->organizationalUnitRepository->save($organizationalUnit); + + return new OrganizationalUnitOutput($organizationalUnit); + } + + private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null + { + $user = $this->organizationalUnitRepository->findOneByUuid($uriVariables['uuid']); + $this->organizationalUnitRepository->delete($user); + + return null; + } +} diff --git a/src/State/Processor/UserGroupProcessor.php b/src/State/Processor/UserGroupProcessor.php index 0dfdaea..e45900b 100644 --- a/src/State/Processor/UserGroupProcessor.php +++ b/src/State/Processor/UserGroupProcessor.php @@ -10,7 +10,6 @@ use ApiPlatform\Metadata\Put; use ApiPlatform\State\ProcessorInterface; use ApiPlatform\Validator\ValidatorInterface; use App\Dto\Input\UserGroupInput; -use App\Dto\Input\UserInput; use App\Dto\Output\UserGroupOutput; use App\Repository\UserGroupRepository; diff --git a/src/State/Provider/OrganizationalUnitProvider.php b/src/State/Provider/OrganizationalUnitProvider.php new file mode 100644 index 0000000..83d5735 --- /dev/null +++ b/src/State/Provider/OrganizationalUnitProvider.php @@ -0,0 +1,71 @@ +provideCollection($operation, $uriVariables, $context); + case $operation instanceof Patch: + case $operation instanceof Put: + return $this->provideInput($operation, $uriVariables, $context); + case $operation instanceof Get: + return $this->provideItem($operation, $uriVariables, $context); + } + } + + private function provideCollection(Operation $operation, array $uriVariables = [], array $context = []): object + { + $paginator = $this->collectionProvider->provide($operation, $uriVariables, $context); + + $items = new \ArrayObject(); + foreach ($paginator->getIterator() as $item){ + $items[] = new OrganizationalUnitOutput($item); + } + + return new TraversablePaginator($items, $paginator->getCurrentPage(), $paginator->getItemsPerPage(), $paginator->getTotalItems()); + } + + public function provideItem(Operation $operation, array $uriVariables = [], array $context = []): object|array|null + { + $item = $this->itemProvider->provide($operation, $uriVariables, $context); + + if (!$item) { + throw new NotFoundHttpException('Organizational unit not found'); + } + + return new OrganizationalUnitOutput($item); + } + + public function provideInput(Operation $operation, array $uriVariables = [], array $context = []): object|array|null + { + if (isset($uriVariables['uuid'])) { + $item = $this->itemProvider->provide($operation, $uriVariables, $context); + + return $item !== null ? new UserGroupInput($item) : null; + } + + return new UserGroupInput(); + } +}