diff --git a/src/Security/AdminModule/PermissionsFormFactory.php b/src/Security/AdminModule/PermissionsFormFactory.php deleted file mode 100755 index 69438670..00000000 --- a/src/Security/AdminModule/PermissionsFormFactory.php +++ /dev/null @@ -1,164 +0,0 @@ - - */ -class PermissionsFormFactory implements \Venne\Forms\IFormFactory -{ - - /** @var \Venne\Forms\IFormFactory */ - private $formFactory; - - /** @var \Venne\Security\AuthorizatorFactory */ - private $authorizatorFactory; - - /** @var \Venne\System\AdministrationManager */ - private $administrationManager; - - /** @var \Nette\Application\PresenterFactory */ - private $presenterFactory; - - /** @var \Venne\Security\IControlVerifierReader */ - private $reader; - - /** @var \Kdyby\Doctrine\EntityDao */ - private $roleDao; - - public function __construct( - IFormFactory $formFactory, - EntityDao $roleDao, - AuthorizatorFactory $authorizatorFactory, - AdministrationManager $administrationManager, - PresenterFactory $presenterFactory, - IControlVerifierReader $reader - ) - { - $this->formFactory = $formFactory; - $this->roleDao = $roleDao; - $this->authorizatorFactory = $authorizatorFactory; - $this->administrationManager = $administrationManager; - $this->presenterFactory = $presenterFactory; - $this->reader = $reader; - } - - /** - * @return \Nette\Application\UI\Form - */ - public function create() - { - $form = $this->formFactory->create(); - - $presenters = $this->administrationManager->getAdministrationPages(); - /** @var $permissions \Nette\Security\Permission */ - $permissions = $this->authorizatorFactory->getPermissionsByRoles(array($form->data->name)); - - foreach ($this->scanResources() as $resource => $privileges) { - $presenter = $this->presenterFactory->unformatPresenterClass($resource); - - $container = $form->addContainer($this->formatName($resource)); - $container->setCurrentGroup($form->addGroup(isset($presenters[$presenter . ':']) ? $presenters[$presenter . ':']['name'] : $resource)); - $val = $permissions->isAllowed($form->data->name, $resource); - $container->addCheckbox('all', 'All')->setDefaultValue($val); - - $privilegeContainer = $container->addContainer('privileges'); - foreach ($privileges as $privilege) { - /** @var $checkbox \Nette\Forms\Controls\Checkbox */ - $checkbox = $privilegeContainer->addCheckbox($privilege, $privilege); - $checkbox->setDefaultValue($permissions->isAllowed($form->data->name, $resource, $privilege)); - if ($val) { - $checkbox->disabled = true; - } - } - } - - $form->setCurrentGroup(); - $form->addSubmit('_submit', 'Save'); - - return $form; - } - - public function handleSave($form) - { - $values = $form->getValues(); - $entity = $form->data; - - $entity->getPermissions()->clear(); - - foreach ($values as $resource => $items) { - foreach ($items['privileges'] as $privilege => $item) { - if ($item) { - $entity->permissions[] = new \Venne\Security\PermissionEntity($entity, $this->unformatName($resource), $privilege); - } - } - } - - $this->addPermissions($entity, $values); - - $this->roleDao->save($form->data); - } - - protected function addPermissions($entity, $values) - { - foreach ($values as $class => $items) { - if ($items['all']) { - $entity->permissions[] = new \Venne\Security\PermissionEntity($entity, $this->unformatName($class)); - } - - if ($class !== 'all' && is_array($items)) { - $this->addPermissions($entity, $items); - } - } - } - - protected function formatName($class) - { - return str_replace('\\', '_', $class); - } - - protected function unformatName($name) - { - return str_replace('_', '\\', $name); - } - - /** - * Array of all resources. - * - * @return array - */ - protected function scanResources() - { - $ret = array(); - - foreach ($this->presenterFactory->getPresenters() as $class => $name) { - $schema = $this->reader->getSchema($class); - - foreach ($schema as $item) { - if (!array_key_exists($item['resource'], $ret)) { - $ret[$item['resource']] = array(); - } - - $ret[$item['resource']] = array_unique(array_merge($ret[$item['resource']], $item['privilege'] ? (array) $item['privilege'] : array())); - } - } - - return $ret; - } -} diff --git a/src/Security/AdminModule/RolesTableFactory.php b/src/Security/AdminModule/RolesTableFactory.php index b90c3368..8f3bb2cf 100644 --- a/src/Security/AdminModule/RolesTableFactory.php +++ b/src/Security/AdminModule/RolesTableFactory.php @@ -14,7 +14,6 @@ use Kdyby\Doctrine\EntityDao; use Nette\Localization\ITranslator; use Venne\Security\RoleEntity; -use Venne\System\Components\AdminGrid\Form; use Venne\System\Components\AdminGrid\IAdminGridFactory; /** @@ -29,9 +28,6 @@ class RolesTableFactory /** @var \Venne\Security\AdminModule\RoleFormFactory */ private $roleForm; - /** @var \Venne\Security\AdminModule\PermissionsFormFactory */ - private $permissionsForm; - /** @var \Venne\System\Components\AdminGrid\IAdminGridFactory */ private $adminGridFactory; @@ -40,14 +36,12 @@ class RolesTableFactory public function __construct( EntityDao $dao, - PermissionsFormFactory $permissionsForm, RoleFormFactory $roleForm, IAdminGridFactory $adminGridFactory, ITranslator $translator ) { $this->dao = $dao; - $this->permissionsForm = $permissionsForm; $this->roleForm = $roleForm; $this->adminGridFactory = $adminGridFactory; $this->translator = $translator; @@ -91,10 +85,8 @@ public function create() ->getElementPrototype()->class[] = 'ajax'; $form = $admin->addForm('role', 'Role', $this->roleForm); - $permissionsForm = $admin->addForm('permissions', 'Permissions', $this->permissionsForm, null, Form::TYPE_LARGE); $admin->connectFormWithAction($form, $table->getAction('edit')); - $admin->connectFormWithAction($permissionsForm, $table->getAction('permissions'), $admin::MODE_PLACE); // Toolbar $toolbar = $admin->getNavbar(); diff --git a/src/Security/DI/SecurityExtension.php b/src/Security/DI/SecurityExtension.php index 7a35ebea..e7142814 100755 --- a/src/Security/DI/SecurityExtension.php +++ b/src/Security/DI/SecurityExtension.php @@ -56,12 +56,6 @@ public function loadConfiguration() public function setupSecurity(ContainerBuilder $container) { - $container->addDefinition($this->prefix('permissionsFormFactory')) - ->setClass('Venne\Security\AdminModule\PermissionsFormFactory', array( - new Statement('@system.admin.basicFormFactory'), - new Statement('@doctrine.dao', array('Venne\Security\RoleEntity')) - )); - $container->addDefinition($this->prefix('roleFormFactory')) ->setClass('Venne\Security\AdminModule\RoleFormFactory', array(new Statement('@system.admin.ajaxFormFactory')));