Ejemplo n.º 1
0
 /** Vytvoření formuláře
  * 
  * @return \Nette\Application\UI\Form
  */
 protected function createComponentForm()
 {
     $form = new Form();
     $form->getElementPrototype()->id = "roleForm";
     $form->addText("name", "Jméno skupiny:")->setHtmlId("name")->setRequired("Prosím zadejte jméno skupiny oprávnění.");
     $form->addHidden("aclRoleID");
     $form->addButton("cancel", "Storno")->setHtmlId("cancel");
     $form->addSubmit("sender", "Uložit změny")->setHtmlId("sender");
     $resources = $this->resourceRepository->read();
     foreach ($resources as $resource) {
         $container = $form->addContainer($resource->aclResourceID);
         $actions = $this->modelRepository->read()->where("aclResourceID", $resource->aclResourceID);
         foreach ($actions as $key => $action) {
             $checkbox = $container->addCheckbox($key, $action->getAclAction()->humanName);
             if ($this->aclRoleID) {
                 $permissions = $this->permissionRepository->read()->where("aclRoleID", $this->aclRoleID)->where("aclModel.aclResourceID", $resource->aclResourceID)->where("aclModel.aclActionID", $action->aclActionID)->where("allowed", TRUE);
                 if ($permissions->count() > 0) {
                     $checkbox->setValue(TRUE);
                 }
             }
         }
     }
     if ($this->aclRoleID) {
         $roleEntity = $this->roleRepository->get($this->aclRoleID);
         if ($roleEntity) {
             $form['aclRoleID']->setValue($roleEntity->aclRoleID);
             $form['name']->setValue($roleEntity->name);
         }
     }
     $form->onSuccess[] = callback($this, "Submit");
     $form->onError[] = callback($this, "Error");
     return $form;
 }
Ejemplo n.º 2
0
 /** Remove
  * @param array $aclRoleID
  * @return bool|string
  */
 public function remove($aclRoleID)
 {
     try {
         $this->database->beginTransaction();
         $this->permissionRepository->read()->where("aclRoleID", $aclRoleID)->getSelection()->delete();
         $this->roleRepository->read()->where("aclRoleID", $aclRoleID)->getSelection()->delete();
         $this->database->commit();
         return TRUE;
     } catch (\PDOException $e) {
         $this->database->rollBack();
         return $e->getMessage();
     }
 }
Ejemplo n.º 3
0
 /** Vytvoření komponenty
  *
  * @return \Nette\Application\UI\Form
  */
 protected function createComponentForm()
 {
     $form = new Form();
     $form->addText("login", "Přihlašovací jméno:")->setAttribute("autocomplete", "off")->setRequired("Prosím zadejte přihlašovací jméno.");
     $form->addPassword("password1", "Heslo:")->setAttribute("class", "form-control")->setAttribute("autocomplete", "off");
     $form->addPassword("password2", "Heslo pro kontrolu:")->setAttribute("class", "form-control")->setAttribute("autocomplete", "off");
     $roles = $this->roleRepository->read()->where("name != ?", "root");
     if (!$this->user->isInRole("root")) {
         $roles->where("name NOT(?)", $this->user->getRoles());
     }
     $roles = $roles->fetchPairs("aclRoleID", "name");
     $form->addSelect("role", "Oprávnění:", $roles)->setAttribute("class", "form-control");
     $form->addCheckbox("active", "Aktivní");
     $form->addButton("cancel", "Storno")->setHtmlId("cancel");
     $form->addSubmit("sender", "Uložit změny")->setHtmlId("sender");
     $form->addHidden("userID");
     $form['password2']->addRule(Form::EQUAL, 'Hesla se neshodují', $form['password1']);
     if ($this->rsuserID) {
         $userEntity = $this->userRepository->get($this->rsuserID);
         if ($userEntity) {
             $form['login']->setValue($userEntity->login);
             $form['login']->setAttribute("readonly");
             $form['userID']->setValue($this->rsuserID);
             $form['active']->setValue($userEntity->getActive());
             if ($userEntity->getUserID() == $this->user->getId()) {
                 $form['role']->setDisabled();
             }
             if ($userEntity->getLogin() != "root" && $userEntity->getUserID() !== $this->user->getId()) {
                 $form['role']->setValue($userEntity->aclRoleID);
             }
         }
     } else {
         $form['password1']->setRequired("Prosím zadejte heslo.");
     }
     $form->onSuccess[] = callback($this, "Submit");
     $form->onError[] = callback($this, "FormError");
     return $form;
 }
Ejemplo n.º 4
0
 /**
  *
  */
 private function initRole()
 {
     foreach ($this->roleRepository->read()->order("aclRoleID ASC") as $item) {
         $this->acl->addRole($item->name);
     }
 }