Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Oct 16, 2024
1 parent e282405 commit c3c9806
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 2 additions & 0 deletions databox/api/src/Security/Voter/AbstractVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ abstract class AbstractVoter extends Voter
final public const EDIT = 'EDIT';
final public const DELETE = 'DELETE';
final public const EDIT_PERMISSIONS = 'EDIT_PERMISSIONS';
final public const OPERATOR = 'OPERATOR';
final public const OWNER = 'OWNER';

protected EntityManagerInterface $em;
protected Security $security;
Expand Down
16 changes: 6 additions & 10 deletions databox/api/src/Security/Voter/AssetVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $
return $isOwner()
|| $this->security->isGranted(self::SCOPE_PREFIX.'EDIT')
|| $this->hasAcl(PermissionInterface::OPERATOR, $subject, $token)
|| $this->containerHasAcl($subject, PermissionInterface::OPERATOR, $token);
|| $this->voteOnContainer($subject, AbstractVoter::OPERATOR);
case self::EDIT_ATTRIBUTES:
return $isOwner()
|| $this->security->isGranted(self::SCOPE_PREFIX.'EDIT')
|| $this->hasAcl(PermissionInterface::EDIT, $subject, $token)
|| $this->containerHasAcl($subject, PermissionInterface::EDIT, $token);
|| $this->voteOnContainer($subject, AbstractVoter::EDIT);
case self::SHARE:
return $isOwner()
|| $this->security->isGranted(self::SCOPE_PREFIX.'EDIT')
|| $this->hasAcl(PermissionInterface::SHARE, $subject, $token)
|| $this->containerHasAcl($subject, PermissionInterface::EDIT, $token);
|| $this->voteOnContainer($subject, AbstractVoter::EDIT);
case self::DELETE:
return $isOwner()
|| $this->security->isGranted(self::SCOPE_PREFIX.'DELETE')
Expand All @@ -80,19 +80,15 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $
return $isOwner()
|| $this->security->isGranted(self::SCOPE_PREFIX.'OWNER')
|| $this->hasAcl(PermissionInterface::OWNER, $subject, $token)
|| $this->containerHasAcl($subject, PermissionInterface::OWNER, $token);
|| $this->voteOnContainer($subject, AbstractVoter::OWNER);
}

return false;
}

private function containerHasAcl(Asset $asset, int $permission, TokenInterface $token): bool
private function voteOnContainer(Asset $asset, string|int $attribute): bool
{
if (null !== $collection = $asset->getReferenceCollection()) {
return $this->hasAcl($permission, $collection, $token);
}

return $this->hasAcl($permission, $asset->getWorkspace(), $token);
return $this->security->isGranted($attribute, $asset->getReferenceCollection() ?? $asset->getWorkspace());
}

private function collectionGrantsAccess(Asset $subject): bool
Expand Down
6 changes: 6 additions & 0 deletions databox/api/src/Security/Voter/CollectionVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ private function doVote(string $attribute, Collection $subject, TokenInterface $
self::EDIT_PERMISSIONS => $isOwner()
|| $this->hasAcl(PermissionInterface::OWNER, $subject, $token)
|| (null !== $subject->getParent() && $this->security->isGranted($attribute, $subject->getParent())),
self::OPERATOR => $isOwner()
|| $this->hasAcl(PermissionInterface::OPERATOR, $subject, $token)
|| (null !== $subject->getParent() && $this->security->isGranted($attribute, $subject->getParent())),
self::OWNER => $isOwner()
|| $this->hasAcl(PermissionInterface::OWNER, $subject, $token)
|| (null !== $subject->getParent() && $this->security->isGranted($attribute, $subject->getParent())),
default => false,
};
}
Expand Down
6 changes: 6 additions & 0 deletions databox/api/src/Security/Voter/WorkspaceVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ private function doVote(string $attribute, Workspace $subject, TokenInterface $t
self::EDIT_PERMISSIONS => $isOwner()
|| $this->hasAcl(PermissionInterface::OWNER, $subject, $token)
|| $this->isAdmin(),
self::OPERATOR => $isOwner()
|| $this->hasAcl(PermissionInterface::OPERATOR, $subject, $token),
self::OWNER => $isOwner()
|| $this->hasAcl(PermissionInterface::OWNER, $subject, $token)
|| $this->isAdmin(),

default => false,
};
}
Expand Down

0 comments on commit c3c9806

Please sign in to comment.