123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <?php
- namespace Sonata\AdminBundle\Util;
- use Sonata\AdminBundle\Admin\AdminInterface;
- use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
- use Symfony\Component\Form\Form;
- use Symfony\Component\Security\Acl\Domain\Acl;
- class AdminObjectAclData
- {
-
- protected static $ownerPermissions = array('MASTER', 'OWNER');
-
- protected $admin;
-
- protected $object;
-
- protected $aclUsers;
-
- protected $aclRoles;
-
- protected $masks;
-
- protected $aclUsersForm;
-
- protected $aclRolesForm;
-
- protected $acl;
-
- protected $maskBuilderClass;
-
- public function __construct(AdminInterface $admin, $object, \Traversable $aclUsers, $maskBuilderClass, \Traversable $aclRoles = null)
- {
- $this->admin = $admin;
- $this->object = $object;
- $this->aclUsers = $aclUsers;
- $this->aclRoles = (null === $aclRoles) ? new \ArrayIterator() : $aclRoles;
- $this->maskBuilderClass = $maskBuilderClass;
- $this->updateMasks();
- }
-
- public function getAdmin()
- {
- return $this->admin;
- }
-
- public function getObject()
- {
- return $this->object;
- }
-
- public function getAclUsers()
- {
- return $this->aclUsers;
- }
-
- public function getAclRoles()
- {
- return $this->aclRoles;
- }
-
- public function setAcl(Acl $acl)
- {
- $this->acl = $acl;
- return $this;
- }
-
- public function getAcl()
- {
- return $this->acl;
- }
-
- public function getMasks()
- {
- return $this->masks;
- }
-
- public function setForm(Form $form)
- {
- @trigger_error(
- 'setForm() is deprecated since version 3.0 and will be removed in 4.0. '
- .'Use setAclUsersForm() instead.',
- E_USER_DEPRECATED
- );
- return $this->setAclUsersForm($form);
- }
-
- public function getForm()
- {
- @trigger_error(
- 'getForm() is deprecated since version 3.0 and will be removed in 4.0. '
- .'Use getAclUsersForm() instead.',
- E_USER_DEPRECATED
- );
- return $this->getAclUsersForm();
- }
-
- public function setAclUsersForm(Form $form)
- {
- $this->aclUsersForm = $form;
- return $this;
- }
-
- public function getAclUsersForm()
- {
- return $this->aclUsersForm;
- }
-
- public function setAclRolesForm(Form $form)
- {
- $this->aclRolesForm = $form;
- return $this;
- }
-
- public function getAclRolesForm()
- {
- return $this->aclRolesForm;
- }
-
- public function getPermissions()
- {
- return $this->admin->getSecurityHandler()->getObjectPermissions();
- }
-
- public function getUserPermissions()
- {
- $permissions = $this->getPermissions();
- if (!$this->isOwner()) {
- foreach (self::$ownerPermissions as $permission) {
- $key = array_search($permission, $permissions);
- if ($key !== false) {
- unset($permissions[$key]);
- }
- }
- }
- return $permissions;
- }
-
- public function isOwner()
- {
-
- return $this->admin->isGranted('OWNER', $this->object);
- }
-
- public function getSecurityHandler()
- {
- return $this->admin->getSecurityHandler();
- }
-
- public function getSecurityInformation()
- {
- return $this->admin->getSecurityHandler()->buildSecurityInformation($this->admin);
- }
-
- protected function updateMasks()
- {
- $permissions = $this->getPermissions();
- $reflectionClass = new \ReflectionClass(new $this->maskBuilderClass());
- $this->masks = array();
- foreach ($permissions as $permission) {
- $this->masks[$permission] = $reflectionClass->getConstant('MASK_'.$permission);
- }
- }
- }
|