public function testDatabaseReaderRole()
 {
     $adm = new couchAdmin($this->aclient);
     $security = $adm->getSecurity();
     $this->assertEquals(count($security->readers->roles), 0);
     $ok = $adm->addDatabaseReaderRole("cowboy");
     $this->assertType("boolean", $ok);
     $this->assertEquals($ok, true);
     $security = $adm->getSecurity();
     $this->assertEquals(count($security->readers->roles), 1);
     $this->assertEquals(reset($security->readers->roles), "cowboy");
     $ok = $adm->removeDatabaseReaderRole("cowboy");
     $this->assertType("boolean", $ok);
     $this->assertEquals($ok, true);
     $security = $adm->getSecurity();
     $this->assertEquals(count($security->readers->roles), 0);
 }
Пример #2
0
 /**
  *  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;
 }