/** * Method to return a user based on the username * * @author KnowledgeTree Team * @access public * @param string $username The username of the user * @return array $response The formatted response array */ public function get_user_object_by_username($username) { return KTAPI_User::getByUsername($username); }
/** * Test KTAPI_PermissionAllocation getAllocation(), add(), remove(), save() * */ function testPermissionAllocation() { $root = $this->ktapi->get_root_folder(); $folder = $this->ktapi->get_folder_by_name('test123'); if (!$folder instanceof KTAPI_Folder) { $folder = $root->add_folder('test123'); } $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $folder); $group = KTAPI_Group::getByName('System Administrators'); $user = KTAPI_User::getByUsername('anonymous'); $role = KTAPI_Role::getByName('Publisher'); $read = KTAPI_Permission::getByNamespace('ktcore.permissions.read'); $write = KTAPI_Permission::getByNamespace('ktcore.permissions.write'); $addFolder = KTAPI_Permission::getByNamespace('ktcore.permissions.addFolder'); $security = KTAPI_Permission::getByNamespace('ktcore.permissions.security'); $allocation->add($user, $read); $allocation->add($user, $write); $allocation->add($user, $addFolder); $allocation->add($user, $security); $allocation->add($role, $read); $allocation->add($role, $write); $allocation->remove($group, $write); $allocation->save(); // refresh object and check permission allocations $folder2 = $this->ktapi->get_folder_by_name('test123'); $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $folder2); $this->assertTrue($allocation->isMemberPermissionSet($user, $read)); $this->assertTrue($allocation->isMemberPermissionSet($user, $write)); $this->assertTrue($allocation->isMemberPermissionSet($role, $write)); $this->assertFalse($allocation->isMemberPermissionSet($group, $write)); $folder->delete('Testing permission allocation'); }
/** * Method to return a user based on the username * * @author KnowledgeTree Team * @access public * @param string $username The username of the user * @return array $response The formatted response array */ public function get_user_by_username($username) { $user = KTAPI_User::getByUsername($username); if (PEAR::isError($user)) { $response['status_code'] = 1; $response['message'] = $user->getMessage(); return $response; } $results = $this->_get_user_details($user); $response['message'] = ''; $response['status_code'] = 0; $response['results'] = $results; return $response; }