示例#1
0
 /**
  * @param OutputInterface $output
  */
 private function createAdminUser(OutputInterface $output)
 {
     $dialog = $this->getHelper('dialog');
     $name = $this->getContainer()->getParameter('admin_name');
     $email = $this->getContainer()->getParameter('admin_email');
     $question = "Do you want to create an admin user with name: '{$name}' and email: '{$email}'? [Y/n]";
     if (!$dialog->askConfirmation($output, $question, true)) {
         return;
     }
     $adminUser = new User($name, array('admin'), $email);
     $adminUser->setData('Navn: ' . $email);
     $entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
     $entityManager->persist($adminUser);
     $entityManager->flush();
 }
示例#2
0
 /**
  * @param $dto
  */
 private function toDtoAuditProperties($dto)
 {
     if (empty($this->id)) {
         return;
     }
     $dto->createdAtDate = $this->connection->getCreatedAtDate();
     $dto->updatedAtDate = $this->createdAtDate;
     $dto->updatedFromIp = (string) $this->updatedFromIp;
     $dto->updatedByUserName = $this->updatedByUser instanceof User ? $this->updatedByUser->getUsername() : '';
 }
示例#3
0
 /**
  * @param User                  $user
  * @param string                $right
  * @param \sspmod_janus_Entity  $entity
  * @param string                $entityWorkflowState
  * @return bool
  */
 protected function voteAttribute(User $user, $right, \sspmod_janus_Entity $entity = null, $entityWorkflowState = null)
 {
     // 'normalize' to all lowercase without whitespace
     $right = strtolower(str_replace(' ', '', $right));
     if ($right === static::RIGHT_ACCESS) {
         $allowedUsers = $this->getEntityControllerForEntity($entity)->getUsers();
         if (array_key_exists($user->getUsername(), $allowedUsers)) {
             return true;
         }
         return $this->voteAttribute($user, static::RIGHT_ALL_ENTITIES);
     }
     if ($entity && isset($this->access[$right][static::CONFIG_WORKFLOW_STATES][$entityWorkflowState])) {
         $allowedRoles = $this->access[$right][static::CONFIG_WORKFLOW_STATES][$entityWorkflowState];
     } elseif (isset($this->access[$right][static::CONFIG_WORKFLOW_STATES][static::CONFIG_WORKFLOW_STATE_ALL])) {
         $allowedRoles = $this->access[$right][static::CONFIG_WORKFLOW_STATES][static::CONFIG_WORKFLOW_STATE_ALL];
     } else {
         if (isset($this->access[$right][static::CONFIG_DEFAULT_PERMISSION])) {
             // Return default permission for element
             return (bool) $this->access[$right][static::CONFIG_DEFAULT_PERMISSION];
         } else {
             return false;
         }
     }
     $roles = $user->getRoles();
     // Role is explicitly allowed
     $intersect = array_intersect($roles, $allowedRoles);
     if (!empty($intersect)) {
         return true;
     }
     $rolesNegated = array();
     foreach ($roles as $role) {
         $rolesNegated[] = '-' . $role;
     }
     $rolesNegated[] = '-all';
     // Role is explicitly disallowed
     $intersectNegated = array_intersect($rolesNegated, $allowedRoles);
     if (!empty($intersectNegated)) {
         return false;
     }
     // All roles are allowed (and current role is not explicitly disallowed).
     if (in_array('all', $allowedRoles)) {
         return true;
     }
     // Default to no access.
     return false;
 }