Skip to content

Commit

Permalink
Add type hints to files in Util directory (#6533)
Browse files Browse the repository at this point in the history
  • Loading branch information
tambait authored Oct 26, 2020
1 parent d31160b commit a9fc410
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 176 deletions.
16 changes: 3 additions & 13 deletions src/Util/AdminAclManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Model\AclInterface;
use Symfony\Component\Security\Acl\Model\MutableAclInterface;

/**
Expand All @@ -34,11 +33,9 @@ final class AdminAclManipulator implements AdminAclManipulatorInterface
private $maskBuilderClass;

/**
* @param string $maskBuilderClass
*
* @phpstan-param class-string $maskBuilderClass
*/
public function __construct($maskBuilderClass)
public function __construct(string $maskBuilderClass)
{
$this->maskBuilderClass = $maskBuilderClass;
}
Expand Down Expand Up @@ -73,17 +70,10 @@ public function configureAcls(OutputInterface $output, AdminInterface $admin): v

public function addAdminClassAces(
OutputInterface $output,
AclInterface $acl,
MutableAclInterface $acl,
AclSecurityHandlerInterface $securityHandler,
array $roleInformation = []
) {
if (!$acl instanceof MutableAclInterface) {
throw new \TypeError(sprintf(
'Argument 2 passed to "%s()" must implement "%s".',
__METHOD__,
MutableAclInterface::class
));
}
): bool {
if (\count($securityHandler->getAdminPermissions()) > 0) {
$builder = new $this->maskBuilderClass();

Expand Down
10 changes: 4 additions & 6 deletions src/Util/AdminAclManipulatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Security\Acl\Model\AclInterface;
use Symfony\Component\Security\Acl\Model\MutableAclInterface;

/**
* @author Thomas Rabaix <[email protected]>
Expand All @@ -25,10 +25,8 @@ interface AdminAclManipulatorInterface
{
/**
* Batch configure the ACLs for all objects handled by an Admin.
*
* @return void
*/
public function configureAcls(OutputInterface $output, AdminInterface $admin);
public function configureAcls(OutputInterface $output, AdminInterface $admin): void;

/**
* Add the class ACE's to the admin ACL.
Expand All @@ -39,8 +37,8 @@ public function configureAcls(OutputInterface $output, AdminInterface $admin);
*/
public function addAdminClassAces(
OutputInterface $output,
AclInterface $acl,
MutableAclInterface $acl,
AclSecurityHandlerInterface $securityHandler,
array $roleInformation = []
);
): bool;
}
112 changes: 19 additions & 93 deletions src/Util/AdminObjectAclData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Model\MutableAclInterface;

/**
Expand Down Expand Up @@ -82,16 +80,13 @@ class AdminObjectAclData
protected $maskBuilderClass;

/**
* @param object $object
* @param string $maskBuilderClass
*
* @phpstan-param class-string $maskBuilderClass
*/
public function __construct(
AdminInterface $admin,
$object,
object $object,
\Traversable $aclUsers,
$maskBuilderClass,
string $maskBuilderClass,
?\Traversable $aclRoles = null
) {
$this->admin = $admin;
Expand All @@ -106,138 +101,79 @@ public function __construct(
$this->updateMasks();
}

/**
* Gets admin.
*
* @return AdminInterface
*/
public function getAdmin()
public function getAdmin(): AdminInterface
{
return $this->admin;
}

/**
* Gets object.
*
* @return object
*/
public function getObject()
public function getObject(): object
{
return $this->object;
}

/**
* Gets ACL users.
*
* @return \Traversable
*/
public function getAclUsers()
public function getAclUsers(): \Traversable
{
return $this->aclUsers;
}

/**
* Gets ACL roles.
*
* @return \Traversable
*/
public function getAclRoles()
public function getAclRoles(): \Traversable
{
return $this->aclRoles;
}

/**
* Sets ACL.
*
* @return AdminObjectAclData
*/
public function setAcl(MutableAclInterface $acl)
public function setAcl(MutableAclInterface $acl): self
{
$this->acl = $acl;

return $this;
}

/**
* Gets ACL.
*
* @return MutableAclInterface
*/
public function getAcl()
public function getAcl(): ?MutableAclInterface
{
return $this->acl;
}

/**
* Gets masks.
*
* @return array<string, mixed>
*/
public function getMasks()
public function getMasks(): array
{
return $this->masks;
}

/**
* Sets ACL users form.
*
* @return AdminObjectAclData
*/
public function setAclUsersForm(FormInterface $form)
public function setAclUsersForm(FormInterface $form): self
{
$this->aclUsersForm = $form;

return $this;
}

/**
* Gets ACL users form.
*
* @return FormInterface
*/
public function getAclUsersForm()
public function getAclUsersForm(): ?FormInterface
{
return $this->aclUsersForm;
}

/**
* Sets ACL roles form.
*
* @return AdminObjectAclData
*/
public function setAclRolesForm(FormInterface $form)
public function setAclRolesForm(FormInterface $form): self
{
$this->aclRolesForm = $form;

return $this;
}

/**
* Gets ACL roles form.
*
* @return FormInterface
*/
public function getAclRolesForm()
public function getAclRolesForm(): ?FormInterface
{
return $this->aclRolesForm;
}

/**
* Gets permissions.
*
* @return array
*/
public function getPermissions()
public function getPermissions(): array
{
return $this->getSecurityHandler()->getObjectPermissions();
}

/**
* Get permissions that the current user can set.
*
* @return array
*/
public function getUserPermissions()
public function getUserPermissions(): array
{
$permissions = $this->getPermissions();

Expand All @@ -253,39 +189,29 @@ public function getUserPermissions()
return $permissions;
}

public function getOwnerPermissions()
public function getOwnerPermissions(): array
{
return self::$ownerPermissions;
}

/**
* Tests if the current user has the OWNER right.
*
* @return bool
*/
public function isOwner()
public function isOwner(): bool
{
// Only a owner can set MASTER and OWNER ACL
return $this->admin->isGranted('OWNER', $this->object);
}

/**
* Gets security handler.
*
* @return AclSecurityHandlerInterface
*/
public function getSecurityHandler()
public function getSecurityHandler(): AclSecurityHandlerInterface
{
$securityHandler = $this->admin->getSecurityHandler();
\assert($securityHandler instanceof AclSecurityHandlerInterface);

return $securityHandler;
}

/**
* @return array
*/
public function getSecurityInformation()
public function getSecurityInformation(): array
{
return $this->getSecurityHandler()->buildSecurityInformation($this->admin);
}
Expand Down
Loading

0 comments on commit a9fc410

Please sign in to comment.