- Added ApiPlatformBundle to the project configuration. - Updated SettingsController to use custom access control for viewing and managing settings. - Modified AppFixtures to reflect new module structure and permissions for project management. - Adjusted ProjectStatus and ProjectTask entities to align with new permission checks. - Enhanced User entity to include a method for retrieving module permissions. - Implemented CleanupModulesCommand to deactivate or remove unimplemented modules. - Added CSRF protection configuration for forms. - Introduced property_info configuration for enhanced property handling. - Updated base template to include user module permissions in the frontend. - Created test_permissions.php for testing user permissions and roles.
201 lines
5.3 KiB
PHP
201 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\ApiFilter;
|
|
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\Post;
|
|
use ApiPlatform\Metadata\Put;
|
|
use ApiPlatform\Metadata\Delete;
|
|
use App\Entity\Interface\ModuleAwareInterface;
|
|
use App\Repository\ProjectStatusRepository;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
#[ORM\Entity(repositoryClass: ProjectStatusRepository::class)]
|
|
#[ORM\Table(name: 'project_statuses')]
|
|
#[ApiResource(
|
|
operations: [
|
|
new GetCollection(
|
|
security: "is_granted('VIEW', 'projects')",
|
|
stateless: false
|
|
),
|
|
new Get(
|
|
security: "is_granted('VIEW', object)",
|
|
stateless: false
|
|
),
|
|
new Post(
|
|
security: "is_granted('CREATE', 'projects')",
|
|
stateless: false
|
|
),
|
|
new Put(
|
|
security: "is_granted('EDIT', object)",
|
|
stateless: false
|
|
),
|
|
new Delete(
|
|
security: "is_granted('DELETE', object)",
|
|
stateless: false
|
|
)
|
|
],
|
|
paginationClientItemsPerPage: true,
|
|
paginationItemsPerPage: 30,
|
|
paginationMaximumItemsPerPage: 5000,
|
|
normalizationContext: ['groups' => ['project_status:read']],
|
|
denormalizationContext: ['groups' => ['project_status:write']],
|
|
order: ['sortOrder' => 'ASC']
|
|
)]
|
|
#[ApiFilter(BooleanFilter::class, properties: ['isActive', 'isDefault'])]
|
|
#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial'])]
|
|
class ProjectStatus implements ModuleAwareInterface
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
#[Groups(['project_status:read', 'project:read'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 100)]
|
|
#[Groups(['project_status:read', 'project_status:write', 'project:read'])]
|
|
#[Assert\NotBlank(message: 'Der Statusname darf nicht leer sein')]
|
|
#[Assert\Length(max: 100)]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\Column(length: 7, nullable: true)]
|
|
#[Groups(['project_status:read', 'project_status:write', 'project:read'])]
|
|
#[Assert\Length(max: 7)]
|
|
#[Assert\Regex(pattern: '/^#[0-9A-Fa-f]{6}$/', message: 'Die Farbe muss im Format #RRGGBB sein')]
|
|
private ?string $color = null;
|
|
|
|
#[ORM\Column]
|
|
#[Groups(['project_status:read', 'project_status:write'])]
|
|
private int $sortOrder = 0;
|
|
|
|
#[ORM\Column]
|
|
#[Groups(['project_status:read', 'project_status:write'])]
|
|
private bool $isDefault = false;
|
|
|
|
#[ORM\Column]
|
|
#[Groups(['project_status:read', 'project_status:write'])]
|
|
private bool $isActive = true;
|
|
|
|
#[ORM\Column]
|
|
#[Groups(['project_status:read'])]
|
|
private ?\DateTimeImmutable $createdAt = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
#[Groups(['project_status:read'])]
|
|
private ?\DateTimeImmutable $updatedAt = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->createdAt = new \DateTimeImmutable();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getColor(): ?string
|
|
{
|
|
return $this->color;
|
|
}
|
|
|
|
public function setColor(?string $color): static
|
|
{
|
|
$this->color = $color;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getSortOrder(): int
|
|
{
|
|
return $this->sortOrder;
|
|
}
|
|
|
|
public function setSortOrder(int $sortOrder): static
|
|
{
|
|
$this->sortOrder = $sortOrder;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getIsDefault(): bool
|
|
{
|
|
return $this->isDefault;
|
|
}
|
|
|
|
public function setIsDefault(bool $isDefault): static
|
|
{
|
|
$this->isDefault = $isDefault;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getIsActive(): bool
|
|
{
|
|
return $this->isActive;
|
|
}
|
|
|
|
public function setIsActive(bool $isActive): static
|
|
{
|
|
$this->isActive = $isActive;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
return $this;
|
|
}
|
|
|
|
public function getCreatedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function setCreatedAt(\DateTimeImmutable $createdAt): static
|
|
{
|
|
$this->createdAt = $createdAt;
|
|
return $this;
|
|
}
|
|
|
|
public function getUpdatedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->updatedAt;
|
|
}
|
|
|
|
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
|
|
{
|
|
$this->updatedAt = $updatedAt;
|
|
return $this;
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return $this->name ?? '';
|
|
}
|
|
|
|
/**
|
|
* Returns the module code this entity belongs to.
|
|
* Required by ModuleVoter for permission checks.
|
|
* ProjectStatus inherits permissions from the projects module.
|
|
*/
|
|
public function getModuleName(): string
|
|
{
|
|
return 'projects';
|
|
}
|
|
}
|