Added the required initial users and groups for the database migration

This commit is contained in:
Jan Böhmer 2024-06-09 00:11:58 +02:00
parent c620beb965
commit a88a2e04cf
3 changed files with 110 additions and 43 deletions

View file

@ -4,24 +4,20 @@ declare(strict_types=1);
namespace DoctrineMigrations;
use App\Entity\UserSystem\PermissionData;
use App\Migration\AbstractMultiPlatformMigration;
use App\Security\Interfaces\HasPermissionsInterface;
use App\Migration\WithPermPresetsTrait;
use App\Services\UserSystem\PermissionPresetsHelper;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20221114193325 extends AbstractMultiPlatformMigration implements ContainerAwareInterface
{
private ?ContainerInterface $container = null;
private ?PermissionPresetsHelper $permission_presets_helper = null;
use WithPermPresetsTrait;
public function __construct(Connection $connection, LoggerInterface $logger)
{
@ -33,34 +29,6 @@ final class Version20221114193325 extends AbstractMultiPlatformMigration impleme
return 'Update the permission system to the new system. Please note that all permissions will be reset!';
}
private function getJSONPermDataFromPreset(string $preset): string
{
if ($this->permission_presets_helper === null) {
throw new \RuntimeException('PermissionPresetsHelper not set! There seems to be some issue with the dependency injection!');
}
//Create a virtual user on which we can apply the preset
$user = new class implements HasPermissionsInterface {
public PermissionData $perm_data;
public function __construct()
{
$this->perm_data = new PermissionData();
}
public function getPermissions(): PermissionData
{
return $this->perm_data;
}
};
//Apply the preset to the virtual user
$this->permission_presets_helper->applyPreset($user, $preset);
//And return the json data
return json_encode($user->getPermissions());
}
private function addDataMigrationAndWarning(): void
{
@ -164,13 +132,7 @@ final class Version20221114193325 extends AbstractMultiPlatformMigration impleme
$this->addSql('CREATE INDEX user_idx_username ON "users" (name)');
}
public function setContainer(ContainerInterface $container = null)
{
if ($container) {
$this->container = $container;
$this->permission_presets_helper = $container->get(PermissionPresetsHelper::class);
}
}
public function postgreSQLUp(Schema $schema): void
{