Ejemplo n.º 1
0
 /**
  * Add all Roles to Zend_Acl.
  *
  * @return void
  */
 private function _registerRoles()
 {
     $roles = new Phprojekt_Role_Role();
     foreach ($roles->fetchAll() as $role) {
         if ($role->parent < 1) {
             $role->parent = null;
         }
         $this->addRole(new Zend_Acl_Role($role->id), $role->parent);
     }
 }
Ejemplo n.º 2
0
 public function testDeleteHasManyAndBelongsToMany()
 {
     $authNamespace = new Zend_Session_Namespace('Phprojekt_Auth-login');
     $keepUser = $authNamespace->userId;
     $role = new Phprojekt_Role_Role(array('db' => $this->sharedFixture));
     $role->name = 'deleteMe';
     $role->save();
     $modulePermissions = $role->modulePermissions->create();
     $modulePermissions->moduleId = 1;
     $modulePermissions->roleId = $role->id;
     $modulePermissions->access = 199;
     $this->assertTrue($modulePermissions->save());
     $this->assertNotNull($role->id);
     $this->assertEquals(2, $role->modulePermissions->count());
     $role->delete();
     $this->assertEquals(1, $role->modulePermissions->count());
     $this->assertNull($role->id);
     $authNamespace->userId = $keepUser;
 }
 /**
  * Return all the roles in an array and their relations if exists.
  *
  * @param integer $projectId The Project ID.
  *
  * @return array Array with 'id', 'name' and 'users'.
  */
 function getProjectRoleUserPermissions($projectId)
 {
     $roles = array();
     $model = new Phprojekt_Role_Role();
     foreach ($model->fetchAll(null, 'name ASC') as $role) {
         $roles['data'][$role->id] = array();
         $roles['data'][$role->id]['id'] = (int) $role->id;
         $roles['data'][$role->id]['name'] = $role->name;
         $roles['data'][$role->id]['users'] = array();
     }
     $select = Phprojekt::getInstance()->getDb()->select();
     $select->from(array('prup' => 'project_role_user_permissions'), array('roleId' => 'role_id', 'userId' => 'user_id'))->where('prup.project_id = ?', (int) $projectId)->joinLeft(array('u' => 'user'), 'u.id = prup.user_id', array('username', 'firstname', 'lastname'))->order('prup.user_id ASC');
     $display = Phprojekt_User_User::getDisplay();
     foreach ($select->query()->fetchAll(Zend_Db::FETCH_OBJ) as $right) {
         $userDisplay = Phprojekt_User_User::applyDisplay($display, $right);
         $roles['data'][$right->roleId]['users'][] = array('id' => (int) $right->userId, 'display' => $userDisplay);
     }
     return $roles;
 }
Ejemplo n.º 4
0
 /**
  * Test save
  */
 public function testSave()
 {
     $role = new Phprojekt_Role_Role();
     $role->name = '';
     $this->assertFalse($role->recordValidate());
     $this->assertNotEquals(array(), $role->getError());
     $role->name = 'New Role';
     $role->save();
     $role->saveRights(array('1' => 139));
     $this->assertEquals(1, count($role->modulePermissions->fetchAll()));
     $role->saveRights(array(1 => 139, 2 => 139));
     $this->assertEquals(2, count($role->modulePermissions->fetchAll()));
     $role->delete();
 }
Ejemplo n.º 5
0
 /**
  * Test for mock function
  */
 public function testMocks()
 {
     $role = new Phprojekt_Role_Role();
     $this->assertEquals(array(), $role->getRights());
 }