public function testUsersDatabaseName() { $adm = new couchAdmin($this->aclient, array("users_database" => "test")); $this->assertEquals("test", $adm->getUsersDatabase()); $adm = new couchAdmin($this->aclient); $this->assertEquals("_users", $adm->getUsersDatabase()); $adm->setUsersDatabase("test"); $this->assertEquals("test", $adm->getUsersDatabase()); }
$error++; } } // We test access to couchdb server if (!$error) { include_once($dolibarr_main_document_root . "/core/db/couchdb/lib/couchClient.php"); include_once($dolibarr_main_document_root . "/core/db/couchdb/lib/couchAdmin.php"); print '<input type="hidden" name="couchdb_user_root" value="' . $_POST['couchdb_user_root'] . '">'; print '<input type="hidden" name="couchdb_pass_root" value="' . $_POST['couchdb_pass_root'] . '">'; try { if ($_POST['couchdb_create_admin']) { $couchdb = new couchClient($conf->Couchdb->host . ':' . $conf->Couchdb->port . '/', $conf->Couchdb->name); $couchAdmin = new couchAdmin($couchdb); $couchAdmin->createAdmin($_POST['couchdb_user_root'], $_POST['couchdb_pass_root']); $couchAdmin->addRoleToUser($_POST['couchdb_user_root'], "Administrator"); // Add user in administrator group } $host = substr($conf->Couchdb->host, 7); $couchdb = new couchClient('http://' . $_POST['couchdb_user_root'] . ':' . $_POST['couchdb_pass_root'] . '@' . $host . ':' . $conf->Couchdb->port . '/', $conf->Couchdb->name, array("cookie_auth" => false)); if ($_POST['couchdb_create_database']) $couchdb->createDatabase(); $couchdb->getDatabaseInfos(); print "<tr><td>"; print $langs->trans("ServerConnection") . " (" . $langs->trans("User") . " " . $_POST['couchdb_user_root'] . ") : "; print $dolibarr_main_couchdb_host; print "</td><td>";
public function testUserRoles() { $adm = new couchAdmin($this->aclient); $user = $adm->getUser("joe"); $this->assertType("object", $user); $this->assertObjectHasAttribute("_id", $user); $this->assertObjectHasAttribute("roles", $user); $this->assertType("array", $user->roles); $this->assertEquals(0, count($user->roles)); $adm->addRoleToUser($user, "cowboy"); $user = $adm->getUser("joe"); $this->assertType("object", $user); $this->assertObjectHasAttribute("_id", $user); $this->assertObjectHasAttribute("roles", $user); $this->assertType("array", $user->roles); $this->assertEquals(1, count($user->roles)); $this->assertEquals("cowboy", reset($user->roles)); $adm->addRoleToUser("joe", "trainstopper"); $user = $adm->getUser("joe"); $this->assertType("object", $user); $this->assertObjectHasAttribute("_id", $user); $this->assertObjectHasAttribute("roles", $user); $this->assertType("array", $user->roles); $this->assertEquals(2, count($user->roles)); $this->assertEquals("cowboy", reset($user->roles)); $this->assertEquals("trainstopper", end($user->roles)); $adm->removeRoleFromUser($user, "cowboy"); $user = $adm->getUser("joe"); $this->assertType("object", $user); $this->assertObjectHasAttribute("_id", $user); $this->assertObjectHasAttribute("roles", $user); $this->assertType("array", $user->roles); $this->assertEquals(1, count($user->roles)); $this->assertEquals("trainstopper", reset($user->roles)); $adm->removeRoleFromUser("joe", "trainstopper"); $user = $adm->getUser("joe"); $this->assertType("object", $user); $this->assertObjectHasAttribute("_id", $user); $this->assertObjectHasAttribute("roles", $user); $this->assertType("array", $user->roles); $this->assertEquals(0, count($user->roles)); }
/** * Create views and documents required by module. * Files module.view.json and module.json with create view and create documents * commands must be stored in directory reldir='/module/json/' * This function is called by this->init * * @param string $reldir Relative directory where to scan files * @return int <=0 if KO, >0 if OK */ function _load_documents() { global $db, $conf; $error = 0; $this->couchdb->useDatabase(strtolower($this->name)); // switch to the database for the module if (!$this->couchdb->databaseExists()) { $this->couchdb->createDatabase(); // create the database $couchAdmin = new couchAdmin($this->couchdb); $couchAdmin->addDatabaseReaderRole("administrator"); // add the default admin security group } $ok = 1; foreach ($conf->file->dol_document_root as $dirroot) { if ($ok) { $dir = $dirroot . "/" . $this->name . "/json/"; $ok = 0; // Create or upgrade views and documents $handle = @opendir($dir); // Dir may not exists if (is_resource($handle)) { while (($file = readdir($handle)) !== false) { if (preg_match('/\\.json$/i', $file)) { $fp = fopen($dir . $file, "r"); if ($fp) { $json = fread($fp, filesize($dir . $file)); $obj = json_decode($json); // Test if exist document in database : upgrade try { $result = $this->couchdb->getDoc($obj->_id); $obj->_rev = $result->_rev; } catch (Exception $e) { } try { $this->couchdb->storeDoc($obj); } catch (Exception $e) { dol_print_error("", $e->getMessage()); $error++; } fclose($fp); } } } closedir($handle); } if ($error == 0) { $ok = 1; } } } return $ok; }
/* get the total of entries */ $resultTotal = $db->query($sql); $iTotal = $db->num_rows($resultTotal); $sql.= $sWhere; /* usefull to regroup by the sale needed */ if($search_sale || $_GET['sSearch_7']!=""){ $sql.= " GROUP BY s.rowid"; } $sql.= $sOrder; $sql.= $sLimit; $result = $db->query($sql); //print $sql; $couchAdmin = new couchAdmin($couchdb); $i=0; while ($aRow = $db->fetch_object($result)) { //print_r($aRow);exit; $couchAdmin->createUser($aRow->login, $aRow->pass); $col[$aRow->rowid] = $couchAdmin->getUser($aRow->login); $col[$aRow->rowid]->tms = $db->jdate($aRow->tms); $col[$aRow->rowid]->Lastname = $aRow->name; $col[$aRow->rowid]->Firstname = $aRow->firstname; $col[$aRow->rowid]->Administrator = (bool)$aRow->admin; $col[$aRow->rowid]->PhonePro = $aRow->office_phone; $col[$aRow->rowid]->Fax = $aRow->office_fax;