Esempio n. 1
0
 /**
  * Tests the creation of an Acl Role (name / description)
  *
  * @author Nikos Dimopoulos <*****@*****.**>
  * @since  2012-11-30
  */
 public function testAclRoleNameDescription()
 {
     $aclRole = new AclRole('Administrators', 'Super-User role');
     $expected = 'Administrators';
     $actual = $aclRole->getName();
     $this->assertEquals($expected, $actual, 'Acl\\Role does not return correct name');
     $expected = 'Super-User role';
     $actual = $aclRole->getDescription();
     $this->assertEquals($expected, $actual, 'Acl\\Role does not return correct description');
 }
Esempio n. 2
0
 /**
  * Adds a role to the ACL list. Second parameter lets to inherit access data from other existing role
  *
  * Example:
  * <code>$acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor');</code>
  * <code>$acl->addRole('administrator', 'consultor');</code>
  *
  * @param  string $role
  * @param  array $accessInherits
  * @return boolean
  */
 public function addRole($role, $accessInherits = null)
 {
     if (!is_object($role)) {
         $role = new Role($role);
     }
     $roles = $this->_getCollection('roles');
     $exists = $roles->count(array('name' => $role->getName()));
     if (!$exists) {
         $roles->insert(array('name' => $role->getName(), 'description' => $role->getDescription()));
         $this->_getCollection('accessList')->insert(array('roles_name' => $role->getName(), 'resources_name' => '*', 'access_name' => '*', 'allowed' => $this->_defaultAccess));
     }
     if ($accessInherits) {
         return $this->addInherit($role->getName(), $accessInherits);
     }
     return true;
 }
Esempio n. 3
0
 /**
  * Adds a role to the ACL list. Second parameter lets to inherit access data from other existing role
  *
  * Example:
  * <code>$acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor');</code>
  * <code>$acl->addRole('administrator', 'consultor');</code>
  *
  * @param  string $role
  * @param  array $accessInherits
  * @return boolean
  */
 public function addRole($role, $accessInherits = null)
 {
     if (!is_object($role)) {
         $role = new Role($role);
     }
     $exists = $this->_db->fetchOne('SELECT COUNT(*) FROM ' . $this->_options['roles'] . " WHERE name = ?", null, [$role->getName()]);
     if (!$exists[0]) {
         $this->_db->insert($this->_options['roles'], [$role->getName(), $role->getDescription()], ['name', 'description']);
         $roleId = $this->_db->lastInsertId();
         $this->_db->insert($this->_options['resources'], ['*', 'All resources'], ['name', 'description']);
         $resourceId = $this->_db->lastInsertId();
         $this->_db->insert($this->_options['resourcesAccesses'], [$resourceId, '*'], ['resource_id', 'name']);
         $accessId = $this->_db->lastInsertId();
         $this->_db->insert($this->_options['accessList'], [$roleId, $resourceId, $accessId, $this->_defaultAccess], ['role_id', 'resource_id', 'access_id', 'allowed']);
     }
     if ($accessInherits) {
         return $this->addInherit($role->getName(), $accessInherits);
     }
     return true;
 }
Esempio n. 4
0
 /**
  * Adds a role to the ACL list. Second parameter lets to inherit access data from other existing role
  *
  * Example:
  * <code>$acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor');</code>
  * <code>$acl->addRole('administrator', 'consultor');</code>
  *
  * @param  string $role
  * @param  array $accessInherits
  * @return boolean
  */
 public function addRole($role, $accessInherits = null)
 {
     if (!is_object($role)) {
         $role = new Role($role);
     }
     $exists = $this->_options['db']->fetchOne('SELECT COUNT(*) FROM ' . $this->_options['roles'] . " WHERE name = ?", null, array($role->getName()));
     if (!$exists[0]) {
         $this->_options['db']->execute('INSERT INTO ' . $this->_options['roles'] . " VALUES (?, ?)", array($role->getName(), $role->getDescription()));
         $this->_options['db']->execute('INSERT INTO ' . $this->_options['accessList'] . " VALUES (?, ?, ?, ?)", array($role->getName(), '*', '*', $this->_defaultAccess));
     }
     if ($accessInherits) {
         return $this->addInherit($role->getName(), $accessInherits);
     }
     return true;
 }
Esempio n. 5
0
 public function getDescription()
 {
     return parent::getDescription();
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  * Example:
  * <code>$acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor');</code>
  * <code>$acl->addRole('administrator', 'consultor');</code>
  *
  * @param  \Phalcon\Acl\Role|string $role
  * @param  string                   $accessInherits
  * @return boolean
  */
 public function addRole($role, $accessInherits = null)
 {
     if (!is_object($role)) {
         $role = new Role($role);
     }
     $exists = $this->connection->fetchOne("SELECT COUNT(*) FROM {$this->roles} WHERE name = ?", null, [$role->getName()]);
     if (!$exists[0]) {
         $this->connection->execute("INSERT INTO {$this->roles} VALUES (?, ?)", [$role->getName(), $role->getDescription()]);
         $this->connection->execute("INSERT INTO {$this->accessList} VALUES (?, ?, ?, ?)", [$role->getName(), '*', '*', $this->_defaultAccess]);
     }
     if ($accessInherits) {
         return $this->addInherit($role->getName(), $accessInherits);
     }
     return true;
 }