Skip to content

Commit 90d1d93

Browse files
committed
add tests
Signed-off-by: Robert Landers <landers.robert@gmail.com>
1 parent 5b811d5 commit 90d1d93

2 files changed

Lines changed: 436 additions & 16 deletions

File tree

src/State/AbstractHistory.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,26 @@ protected function checkAccessControl(?Provenance $user, StateId $from, Reflecti
148148
return true;
149149
}
150150

151-
foreach ($accessControls as $attr) {
152-
$accessControl = $attr->newInstance();
151+
$controls = array_map(fn(ReflectionAttribute $attr) => $attr->newInstance(), $accessControls);
152+
// put deny before allow
153+
usort($controls, fn($left, $right) => get_class($right) <=> get_class($left));
154+
155+
foreach ($controls as $accessControl) {
156+
if ($accessControl instanceof DenyAnyOperation) {
157+
if ($accessControl->fromUser && $user->userId === $accessControl->fromUser) {
158+
return false;
159+
}
160+
if ($accessControl->fromRole && array_any($user->roles, fn($role) => $role === $accessControl->fromRole)) {
161+
return false;
162+
}
163+
if ($accessControl->fromId && ($from->isEntityId() ? $from->toEntityId() : $from->toOrchestrationInstance()) === $accessControl->fromId) {
164+
return false;
165+
}
166+
if (($accessControl->fromType) && (($from->isEntityId() && $from->toEntityId()->name === $accessControl->fromType) || ($from->isOrchestrationId() && $from->toOrchestrationInstance()->instanceId === $accessControl->fromType))) {
167+
return false;
168+
}
169+
}
170+
153171
if ($accessControl instanceof AllowCreateAll) {
154172
return true;
155173
}
@@ -197,20 +215,6 @@ protected function checkAccessControl(?Provenance $user, StateId $from, Reflecti
197215
return true;
198216
}
199217
}
200-
if ($accessControl instanceof DenyAnyOperation) {
201-
if ($accessControl->fromUser && $user->userId === $accessControl->fromUser) {
202-
return false;
203-
}
204-
if ($accessControl->fromRole && array_any($user->roles, fn($role) => $role === $accessControl->fromRole)) {
205-
return false;
206-
}
207-
if ($accessControl->fromId && ($from->isEntityId() ? $from->toEntityId() : $from->toOrchestrationInstance()) === $accessControl->fromId) {
208-
return false;
209-
}
210-
if (($accessControl->fromType) && (($from->isEntityId() && $from->toEntityId()->name === $accessControl->fromType) || ($from->isOrchestrationId() && $from->toOrchestrationInstance()->instanceId === $accessControl->fromType))) {
211-
return false;
212-
}
213-
}
214218
}
215219

216220
return false;

0 commit comments

Comments
 (0)