refs #422. Model change
							parent
							
								
									8e8947cdfa
								
							
						
					
					
						commit
						14ace8fdbf
					
				| 
						 | 
				
			
			@ -0,0 +1,43 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DoctrineMigrations;
 | 
			
		||||
 | 
			
		||||
use Doctrine\DBAL\Schema\Schema;
 | 
			
		||||
use Doctrine\Migrations\AbstractMigration;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Auto-generated Migration: Please modify to your needs!
 | 
			
		||||
 */
 | 
			
		||||
final class Version20240715084147 extends AbstractMigration
 | 
			
		||||
{
 | 
			
		||||
    public function getDescription(): string
 | 
			
		||||
    {
 | 
			
		||||
        return '';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function up(Schema $schema): void
 | 
			
		||||
    {
 | 
			
		||||
        // this up() migration is auto-generated, please modify it to your needs
 | 
			
		||||
        $this->addSql('CREATE TABLE user_user_group (user_id INT NOT NULL, user_group_id INT NOT NULL, INDEX IDX_28657971A76ED395 (user_id), INDEX IDX_286579711ED93D47 (user_group_id), PRIMARY KEY(user_id, user_group_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
 | 
			
		||||
        $this->addSql('ALTER TABLE user_user_group ADD CONSTRAINT FK_28657971A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
 | 
			
		||||
        $this->addSql('ALTER TABLE user_user_group ADD CONSTRAINT FK_286579711ED93D47 FOREIGN KEY (user_group_id) REFERENCES user_group (id) ON DELETE CASCADE');
 | 
			
		||||
        $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_user');
 | 
			
		||||
        $this->addSql('ALTER TABLE hardware_profile CHANGE organizational_unit_id organizational_unit_id INT NOT NULL');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function down(Schema $schema): void
 | 
			
		||||
    {
 | 
			
		||||
        // this down() migration is auto-generated, please modify it to your needs
 | 
			
		||||
        $this->addSql('CREATE TABLE user_group_user (user_group_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_3AE4BD5A76ED395 (user_id), INDEX IDX_3AE4BD51ED93D47 (user_group_id), PRIMARY KEY(user_group_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
 | 
			
		||||
        $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');
 | 
			
		||||
        $this->addSql('ALTER TABLE user_user_group DROP FOREIGN KEY FK_28657971A76ED395');
 | 
			
		||||
        $this->addSql('ALTER TABLE user_user_group DROP FOREIGN KEY FK_286579711ED93D47');
 | 
			
		||||
        $this->addSql('DROP TABLE user_user_group');
 | 
			
		||||
        $this->addSql('ALTER TABLE hardware_profile CHANGE organizational_unit_id organizational_unit_id INT DEFAULT NULL');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -10,7 +10,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
 | 
			
		|||
#[Get(shortName: 'UserGroup')]
 | 
			
		||||
final class UserGroupOutput extends AbstractOutput
 | 
			
		||||
{
 | 
			
		||||
    #[Groups(['user-group:read'])]
 | 
			
		||||
    #[Groups(['user-group:read', 'user:read'])]
 | 
			
		||||
    public string $name;
 | 
			
		||||
 | 
			
		||||
    #[Groups(['user-group:read'])]
 | 
			
		||||
| 
						 | 
				
			
			@ -20,10 +20,10 @@ final class UserGroupOutput extends AbstractOutput
 | 
			
		|||
    public bool $enabled;
 | 
			
		||||
 | 
			
		||||
    #[Groups(['user-group:read'])]
 | 
			
		||||
    public \DateTime $createAt;
 | 
			
		||||
    public \DateTime $createdAt;
 | 
			
		||||
 | 
			
		||||
    #[Groups(['user-group:read'])]
 | 
			
		||||
    public ?string $createBy = null;
 | 
			
		||||
    public ?string $createdBy = null;
 | 
			
		||||
 | 
			
		||||
    public function __construct(UserGroup $userGroup)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +32,7 @@ final class UserGroupOutput extends AbstractOutput
 | 
			
		|||
        $this->name = $userGroup->getName();
 | 
			
		||||
        $this->permissions = $userGroup->getPermissions();
 | 
			
		||||
        $this->enabled = $userGroup->isEnabled();
 | 
			
		||||
        $this->createAt = $userGroup->getCreatedAt();
 | 
			
		||||
        $this->createBy = $userGroup->getCreatedBy();
 | 
			
		||||
        $this->createdAt = $userGroup->getCreatedAt();
 | 
			
		||||
        $this->createdBy = $userGroup->getCreatedBy();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -5,6 +5,7 @@ namespace App\Dto\Output;
 | 
			
		|||
use ApiPlatform\Metadata\Get;
 | 
			
		||||
use App\Entity\OrganizationalUnit;
 | 
			
		||||
use App\Entity\User;
 | 
			
		||||
use App\Entity\UserGroup;
 | 
			
		||||
use Symfony\Component\Serializer\Annotation\Groups;
 | 
			
		||||
 | 
			
		||||
#[Get(shortName: 'User')]
 | 
			
		||||
| 
						 | 
				
			
			@ -24,10 +25,10 @@ final class UserOutput extends AbstractOutput
 | 
			
		|||
    public array $userGroups;
 | 
			
		||||
 | 
			
		||||
    #[Groups(['user:read'])]
 | 
			
		||||
    public \DateTime $createAt;
 | 
			
		||||
    public \DateTime $createdAt;
 | 
			
		||||
 | 
			
		||||
    #[Groups(['user:read'])]
 | 
			
		||||
    public ?string $createBy = null;
 | 
			
		||||
    public ?string $createdBy = null;
 | 
			
		||||
 | 
			
		||||
    public function __construct(User $user)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -36,13 +37,16 @@ final class UserOutput extends AbstractOutput
 | 
			
		|||
        $this->username = $user->getUsername();
 | 
			
		||||
        $this->roles = $user->getRoles();
 | 
			
		||||
        $this->enabled = $user->isEnabled();
 | 
			
		||||
        $this->userGroups = $user->getUserGroups()->toArray();
 | 
			
		||||
 | 
			
		||||
        $this->userGroups = $user->getUserGroups()->map(
 | 
			
		||||
            fn(UserGroup $userGroup) => new UserGroupOutput($userGroup)
 | 
			
		||||
        )->toArray();
 | 
			
		||||
 | 
			
		||||
        $this->allowedOrganizationalUnits = $user->getAllowedOrganizationalUnits()->map(
 | 
			
		||||
            fn(OrganizationalUnit $organizationalUnit) => new OrganizationalUnitOutput($organizationalUnit)
 | 
			
		||||
        )->toArray();
 | 
			
		||||
 | 
			
		||||
        $this->createAt = $user->getCreatedAt();
 | 
			
		||||
        $this->createBy = $user->getCreatedBy();
 | 
			
		||||
        $this->createdAt = $user->getCreatedAt();
 | 
			
		||||
        $this->createdBy = $user->getCreatedBy();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -38,7 +38,7 @@ class User extends AbstractEntity implements UserInterface, PasswordAuthenticate
 | 
			
		|||
    /**
 | 
			
		||||
     * @var Collection<int, UserGroup>
 | 
			
		||||
     */
 | 
			
		||||
    #[ORM\ManyToMany(targetEntity: UserGroup::class, mappedBy: 'users')]
 | 
			
		||||
    #[ORM\ManyToMany(targetEntity: UserGroup::class, inversedBy: 'users')]
 | 
			
		||||
    private Collection $userGroups;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -160,7 +160,7 @@ class User extends AbstractEntity implements UserInterface, PasswordAuthenticate
 | 
			
		|||
    {
 | 
			
		||||
        if (!$this->userGroups->contains($userGroup)) {
 | 
			
		||||
            $this->userGroups->add($userGroup);
 | 
			
		||||
            $userGroup->addUser($this);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,7 @@ class UserGroup extends AbstractEntity
 | 
			
		|||
    /**
 | 
			
		||||
     * @var Collection<int, User>
 | 
			
		||||
     */
 | 
			
		||||
    #[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'userGroups')]
 | 
			
		||||
    #[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'userGroups')]
 | 
			
		||||
    private Collection $users;
 | 
			
		||||
 | 
			
		||||
    public function __construct()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue