Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"symfony/framework-bundle": "^6.4|^7.4",
"symfony/security-bundle": "^6.4|^7.4",
"symfony/validator": "^6.4|^7.4",
"symfony/yaml": "6.4|^7.4"
"symfony/yaml": "^6.4|^7.4"
},
"config": {
"sort-packages": true
Expand Down
3 changes: 1 addition & 2 deletions src/Controller/PermissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public function __construct(
private readonly PermissionManager $permissionManager,
private readonly EntityManagerInterface $em,
private readonly ObjectMapping $objectMapping,
)
{
) {
}

private function validateAuthorization(string $attribute, Request $request): array
Expand Down
2 changes: 1 addition & 1 deletion src/Event/AclDeleteEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

class AclDeleteEvent extends AclEvent
{
public const NAME = 'acl.delete';
public const string NAME = 'acl.delete';
}
22 changes: 14 additions & 8 deletions src/Event/AclEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

abstract class AclEvent extends Event
{
public function __construct(protected int $userType, protected ?string $userId, protected string $objectType, protected ?string $objectId)
{
public function __construct(
protected readonly int $userType,
protected readonly ?string $userId,
protected readonly string $objectType,
protected readonly ?string $objectId,
protected readonly ?int $previousPermissions,
protected readonly ?array $previousMetadata,
) {
}

public function getUserType(): int
Expand All @@ -27,18 +33,18 @@ public function getObjectType(): string
return $this->objectType;
}

public function setObjectType(string $objectType): void
public function getObjectId(): ?string
{
$this->objectType = $objectType;
return $this->objectId;
}

public function getObjectId(): ?string
public function getPreviousPermissions(): ?int
{
return $this->objectId;
return $this->previousPermissions;
}

public function setObjectId(?string $objectId): void
public function getPreviousMetadata(): ?array
{
$this->objectId = $objectId;
return $this->previousMetadata;
}
}
21 changes: 17 additions & 4 deletions src/Event/AclUpsertEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,28 @@

class AclUpsertEvent extends AclEvent
{
public const NAME = 'acl.upsert';
public const string NAME = 'acl.upsert';

public function __construct(int $userType, ?string $userId, string $objectType, ?string $objectId, private readonly int $permissions)
{
parent::__construct($userType, $userId, $objectType, $objectId);
public function __construct(
int $userType,
?string $userId,
string $objectType,
?string $objectId,
private readonly int $permissions,
private readonly array $metadata,
?int $previousPermissions,
?array $previousMetadata,
) {
parent::__construct($userType, $userId, $objectType, $objectId, $previousPermissions, $previousMetadata);
}

public function getPermissions(): int
{
return $this->permissions;
}

public function getMetadata(): array
{
return $this->metadata;
}
}
5 changes: 5 additions & 0 deletions src/Repository/DoctrinePermissionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function updateOrCreateAce(
array $metadata = [],
?string $parentId = null,
bool $append = false,
?AccessControlEntryInterface &$previousAce = null,
): AccessControlEntryInterface {
$ace = $this->findAce($userType, $userId, $objectType, $objectId, $parentId);

Expand All @@ -128,6 +129,8 @@ public function updateOrCreateAce(
$ace->setObjectType($objectType);
$ace->setObjectId($objectId);
$ace->setParentId($parentId);
} else {
$previousAce = clone $ace;
}

if ($append) {
Expand All @@ -149,6 +152,7 @@ public function deleteAce(
string $objectType,
?string $objectId,
?string $parentId = null,
?AccessControlEntryInterface &$previousAce = null,
): bool {
$userId = AccessControlEntryInterface::USER_WILDCARD === $userId ? null : $userId;

Expand All @@ -162,6 +166,7 @@ public function deleteAce(
]);

if ($ace instanceof AccessControlEntry) {
$previousAce = $ace;
$this->em->remove($ace);
$this->em->flush();

Expand Down
2 changes: 2 additions & 0 deletions src/Repository/PermissionRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function updateOrCreateAce(
array $metadata = [],
?string $parentId = null,
bool $append = false,
?AccessControlEntryInterface &$previousAce = null,
): AccessControlEntryInterface;

/**
Expand All @@ -61,5 +62,6 @@ public function deleteAce(
string $objectType,
?string $objectId,
?string $parentId = null,
?AccessControlEntryInterface &$previousAce = null,
): bool;
}
27 changes: 23 additions & 4 deletions src/Security/PermissionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function updateOrCreateAce(
array $metadata = [],
?string $parentId = null,
bool $append = false,
?AccessControlEntryInterface &$previousAce = null,
): ?AccessControlEntryInterface {
$ace = $this->repository->updateOrCreateAce(
$userType,
Expand All @@ -194,12 +195,22 @@ public function updateOrCreateAce(
$permissions,
$metadata,
$parentId,
$append
$append,
$previousAce,
);

unset($this->cache[$this->getCacheKey($userType, $userId, $objectType, $objectId)]);

$this->eventDispatcher->dispatch(new AclUpsertEvent($userType, $userId, $objectType, $objectId, $permissions), AclUpsertEvent::NAME);
$this->eventDispatcher->dispatch(new AclUpsertEvent(
$userType,
$userId,
$objectType,
$objectId,
$permissions,
$metadata,
$previousAce?->getMask(),
$previousAce?->getMetadata()
), AclUpsertEvent::NAME);

return $ace;
}
Expand All @@ -221,9 +232,17 @@ public function deleteAce(
$userId,
$objectType,
$objectId,
$parentId
$parentId,
$previousAce,
)) {
$this->eventDispatcher->dispatch(new AclDeleteEvent($userType, $userId, $objectType, $objectId), AclDeleteEvent::NAME);
$this->eventDispatcher->dispatch(new AclDeleteEvent(
$userType,
$userId,
$objectType,
$objectId,
$previousAce->getMask(),
$previousAce->getMetadata(),
), AclDeleteEvent::NAME);
}

unset($this->cache[$this->getCacheKey($userType, $userId, $objectType, $objectId)]);
Expand Down
Loading