Skip to content

Commit

Permalink
serializer: handle wildcard users
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Sep 24, 2024
1 parent a79f8df commit a969b42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions Serializer/AceSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function __construct(

public function serialize(AccessControlEntryInterface $ace): array
{
$userId = $ace->getUserId();

$payload = [
'id' => $ace->getId(),
'userType' => array_search($ace->getUserType(), AccessControlEntryInterface::USER_TYPES, true),
Expand All @@ -29,11 +31,12 @@ public function serialize(AccessControlEntryInterface $ace): array
'parentId' => $ace->getParentId(),
];

$id = $ace->getUserId();
if ($ace->getUserType() === AccessControlEntryInterface::TYPE_USER_VALUE) {
$payload['user'] = $this->userRepository->getUser($id);
} elseif ($ace->getUserType() === AccessControlEntryInterface::TYPE_GROUP_VALUE) {
$payload['group'] = $this->groupRepository->getGroup($id);
if (null !== $userId) {
if ($ace->getUserType() === AccessControlEntryInterface::TYPE_USER_VALUE) {
$payload['user'] = $this->userRepository->getUser($userId);
} elseif ($ace->getUserType() === AccessControlEntryInterface::TYPE_GROUP_VALUE) {
$payload['group'] = $this->groupRepository->getGroup($userId);
}
}

return $payload;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"homepage": "https://www.alchemy.fr/",
"license": "MIT",
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-json": "*",
"doctrine/orm": "^2.6",
"ramsey/uuid-doctrine": "^1.5",
Expand Down

0 comments on commit a969b42

Please sign in to comment.