示例#1
0
 public function render()
 {
     $template = $this->getTemplate();
     $template->setFile(__DIR__ . '/usersRolesOverview.latte');
     $resultSet = $this->userFacade->fetchRoles($this->roleQuery);
     $template->roles = $resultSet->toArray();
     $template->render();
 }
示例#2
0
 private function prepareRolesForSelect()
 {
     $roles = $this->userFacade->fetchRoles(new RoleQuery());
     $result = [];
     /** @var Role $role */
     foreach ($roles as $role) {
         $result[$role->getId()] = $role->getName();
     }
     return $result;
 }
示例#3
0
 public function processNewRole(Form $form, $values)
 {
     if (!$this->authorizator->isAllowed($this->user, 'user_role', 'create')) {
         $this->flashMessage('authorization.noPermission', FlashMessage::WARNING);
     }
     try {
         $role = $this->userFacade->createRole((array) $values);
         $this->onSuccessRoleCreation($this, $role);
     } catch (RoleMissingException $rm) {
         $this->flashMessage('users.newRole.form.messages.missingRole', FlashMessage::WARNING, ['roleName' => $values['name']]);
     } catch (RoleAlreadyExistsException $re) {
         $this->flashMessage('users.newRole.form.messages.roleAlreadyExists', FlashMessage::WARNING, ['roleName' => $values['name']]);
     }
 }
示例#4
0
 public function removeRole(SubmitButton $button)
 {
     if (!$this->authorizator->isAllowed($this->user, 'user_role', 'remove')) {
         $this->flashMessage('authorization.noPermission', FlashMessage::WARNING);
         $this->redirect('this');
     }
     try {
         $this->userFacade->removeRole($this->role);
         $this->onSuccessRoleRemoval($this->role);
     } catch (ForeignKeyConstraintViolationException $e) {
         $this->flashMessage('users.roleRemoval.messages.roleInUse', FlashMessage::WARNING, ['roleName' => $this->role->getName()]);
         $this->redirect('this');
     }
 }
示例#5
0
 public function removeRole(SubmitButton $button)
 {
     if (!$this->authorizator->isAllowed($this->user, 'user', 'remove')) {
         $this->flashMessage('authorization.noPermission', FlashMessage::WARNING);
         $this->redirect('this');
     }
     try {
         $this->userFacade->removeUser($this->pickedUser);
         $this->onSuccessUserRemoval($this->pickedUser);
     } catch (ForeignKeyConstraintViolationException $e) {
         $this->flashMessage('users.userRemoval.messages.cantBeRemoved', FlashMessage::WARNING, ['username' => $this->pickedUser->getUsername()]);
         $this->redirect('this');
     }
 }
示例#6
0
 public function processUser(Form $form, $values)
 {
     if (!$this->authorizator->isAllowed($this->user, 'user', 'edit')) {
         $this->flashMessage('authorization.noPermission', FlashMessage::WARNING);
     }
     $validationObject = $this->userFacade->saveUser((array) $values, $this->pickedUser);
     if ($validationObject->isValid()) {
         $this->flashMessage('users.user.form.messages.success', FlashMessage::SUCCESS);
         $this->redirect('this');
     }
     /** @var ValidationError $error */
     foreach ($validationObject->getErrors() as $error) {
         $this->flashMessage($error->getMessage(), $error->getType());
     }
 }
示例#7
0
 public function processPrivileges(Form $form)
 {
     if (!$this->authorizator->isAllowed($this->user, 'user_role', 'edit')) {
         $this->flashMessage('authorization.noPermission', FlashMessage::WARNING);
     }
     $values = $form->getHttpData();
     unset($values['save'], $values['do'], $values[Form::PROTECTOR_ID]);
     try {
         $this->userFacade->savePermissionDefinitions($this->role, $values);
         $this->flashMessage('users.roleDefinition.messages.success', FlashMessage::SUCCESS);
         $this->redirect('this');
     } catch (DBALException $e) {
         $this->flashMessage('users.roleDefinition.messages.success', FlashMessage::WARNING);
     }
 }
示例#8
0
 private function getRole($id)
 {
     $role = $this->userFacade->fetchRole((new RoleQuery())->withParent()->byId($id));
     if ($role === null) {
         $this->flashMessage('users.messages.roleNotFound', FlashMessage::WARNING);
         $this->redirect('Users:roles');
     }
     return $role;
 }