Thread: [Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[188] trunk/0.4
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2010-10-07 19:08:16
|
Revision: 188 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=188&view=rev Author: crazedsanity Date: 2010-10-07 19:08:10 +0000 (Thu, 07 Oct 2010) Log Message: ----------- Changes to work with cs-phpxml v1.1 (trunk) /cs_siteConfig.class.php: * __construct(): -- use cs_phpxmlCreator::attributeIndex to remove any root attributes. * parse_config(): -- use cs_phpxmlCreator::attributeIndex to remove any root attributes. -- TODO about taking out the UPPERCASE requirement... -- modifications to handle cs-phpxml v1.1 (trunk) * get_section(): -- minor changes to retrieve data based on cs-phpxml v1.1 (trunk) * get_value(): -- use dataIndex constant from cs_phpxmlCreator to get value. /cs_webdbupgrade.class.php: * read_upgrade_config_file(): -- build the "matching" array here. -- pull the "INITIALVERSION" value here, if it exists. * do_single_upgrade(): -- updated paths to configuration data. * get_upgrade_list(): -- updated path to config data * load_initial_version(): -- use new location of INITIALVERSION in config. Modified Paths: -------------- trunk/0.4/cs_siteConfig.class.php trunk/0.4/cs_webdbupgrade.class.php Modified: trunk/0.4/cs_siteConfig.class.php =================================================================== --- trunk/0.4/cs_siteConfig.class.php 2010-10-01 19:24:30 UTC (rev 187) +++ trunk/0.4/cs_siteConfig.class.php 2010-10-07 19:08:10 UTC (rev 188) @@ -103,7 +103,7 @@ if(is_null($section) || !strlen($section)) { $myData = $this->xmlReader->get_path($this->xmlReader->get_root_element()); - unset($myData['type'], $myData['attributes']); + unset($myData['type'], $myData[cs_phpxmlCreator::attributeIndex]); $myData = array_keys($myData); $section = $myData[0]; } @@ -168,22 +168,23 @@ private function parse_config() { if(is_object($this->xmlReader)) { $data = $this->xmlReader->get_path($this->xmlReader->get_root_element()); + unset($data[cs_phpxmlCreator::attributeIndex]); $specialVars = $this->build_special_vars(); $parseThis = array(); - $this->configSections = array(); foreach($data as $section=>$secData) { - //only handle UPPERCASE index names; lowercase indexes are special entries (i.e. "type" or "attributes" + //only handle UPPERCASE index names.... + //TODO: take this (above) requirement out, as cs-phpxml doesn't require everything to be upper-case. if($section == strtoupper($section)) { $this->configSections[] = $section; - unset($secData['type']); - - if(isset($secData['attributes']) && is_array($secData['attributes'])) { - $sectionAttribs = $secData['attributes']; - unset($secData['attributes']); + //TODO: use method (i.e. $this->xmlReader->get_attribute($path)) to retrieve attributes. + if(isset($secData[cs_phpxmlCreator::attributeIndex]) && is_array($secData[cs_phpxmlCreator::attributeIndex])) { + //TODO: use method (i.e. $this->xmlReader->get_attribute($path)) to retrieve attributes. + $sectionAttribs = $secData[cs_phpxmlCreator::attributeIndex]; + unset($secData[cs_phpxmlCreator::attributeIndex]); //put stuff into the globals scope... if(isset($sectionAttribs['SETGLOBAL'])) { @@ -197,13 +198,23 @@ } } + $secData = $secData[0]; + $tSectionAttribs = null; + if(isset($secData[cs_phpxmlCreator::attributeIndex])) { + $tSectionAttribs = $secData[cs_phpxmlCreator::attributeIndex]; + unset($secData[cs_phpxmlCreator::attributeIndex]); + } foreach($secData as $itemName=>$itemValue) { $attribs = array(); - if(isset($itemValue['attributes']) && is_array($itemValue['attributes'])) { - $attribs = $itemValue['attributes']; + //TODO: use method (i.e. $this->xmlReader->get_attribute($path)) to retrieve attributes. + if(isset($itemValue[0][cs_phpxmlCreator::attributeIndex]) && is_array($itemValue[0][cs_phpxmlCreator::attributeIndex])) { + //TODO: use method (i.e. $this->xmlReader->get_attribute($path)) to retrieve attributes. + $attribs = $itemValue[0][cs_phpxmlCreator::attributeIndex]; } - if(isset($itemValue['value'])) { - $itemValue = $itemValue['value']; + //TODO: use method (i.e. $this->xmlReader->get_value($path)) to retrieve tag value. + if(isset($itemValue[0][cs_phpxmlCreator::dataIndex])) { + //TODO: use method (i.e. $this->xmlReader->get_value($path)) to retrieve tag value. + $itemValue = $itemValue[0][cs_phpxmlCreator::dataIndex]; } else { $itemValue = null; @@ -230,7 +241,7 @@ $parseThis[$itemName] = $itemValue; $parseThis[$section ."/". $itemName] = $itemValue; - $data[$section][$itemName]['value'] = $itemValue; + $data[$section][$itemName][cs_phpxmlCreator::dataIndex] = $itemValue; $setVarIndex = $this->setVarPrefix . $itemName; if(isset($attribs['SETGLOBAL'])) { @@ -264,7 +275,7 @@ if($this->a2p->get_data($configPath)) { $setMe = array(); foreach($this->a2p->get_data($configPath) as $i=>$v) { - $setMe[$i] = $v['value']; + $setMe[$i] = $v[cs_phpxmlCreator::dataIndex]; } $globA2p->set_data($globalsPath, $setMe); } @@ -294,14 +305,13 @@ public function get_section($section) { if($this->isInitialized === true) { $section = strtoupper($section); - $data = $this->a2p->get_data($section); + $data = $this->a2p->get_data($section .'/0'); - if(is_array($data) && count($data) && $data['type'] == 'open') { - unset($data['type']); + if(is_array($data) && count($data)) { $retval = $data; } else { - throw new exception(__METHOD__ .": invalid section (". $section .") or no data (". $data['type'] .")"); + throw new exception(__METHOD__ .": invalid section (". $section .") or no data::: ". $this->gfObj->debug_print($data,0)); } } else { @@ -332,7 +342,7 @@ //section NOT given, assume they're looking for something in the active section. $index = $this->activeSection ."/". $index; } - $retval = $this->a2p->get_data($index .'/value'); + $retval = $this->a2p->get_data($index .'/'. cs_phpxmlCreator::dataIndex); } else { throw new exception(__METHOD__ .": not initialized"); Modified: trunk/0.4/cs_webdbupgrade.class.php =================================================================== --- trunk/0.4/cs_webdbupgrade.class.php 2010-10-01 19:24:30 UTC (rev 187) +++ trunk/0.4/cs_webdbupgrade.class.php 2010-10-07 19:08:10 UTC (rev 188) @@ -304,10 +304,32 @@ //parse the file. $xmlParser = new cs_phpxmlParser($xmlString); - $config = $xmlParser->get_tree(TRUE); - - if(is_array($config['UPGRADE']) && count($config['UPGRADE'])) { - $this->config['UPGRADELIST'] = $config['UPGRADE']; + if($xmlParser->get_root_element() == 'UPGRADE') { + + //see if there's an "initial version" setting. + try { + $this->config['INITIALVERSION'] = $xmlParser->get_tag_value('/UPGRADE/INITIALVERSION'); + } + catch(Exception $e) { + //no worries, this only happens when the tag doesn't exist or it doesn't have data (that is okay). + } + + $tConfig = array(); + if(is_array($xmlParser->get_data('/UPGRADE/MATCHING'))) { + $matchingData = $xmlParser->get_data('/UPGRADE/MATCHING'); + foreach($matchingData as $index=>$array) { + $array = $array[0]; + foreach($array as $matchingName=>$subInfo) { + if(isset($subInfo[0][cs_phpxmlCreator::dataIndex])) { + $tConfig[$index][$matchingName] = $subInfo[0][cs_phpxmlCreator::dataIndex]; + } + else { + throw new exception(__METHOD__ .": invalid data beneath matching (". $index .")::: ". $this->gfObj->debug_print($subInfo,0)); + } + } + } + } + $this->config['matchingData'] = $tConfig; } else { $this->error_handler(__METHOD__ .": failed to retrieve 'UPGRADE' section; " . @@ -581,7 +603,7 @@ private function do_single_upgrade($fromVersion, $toVersion=null) { //Use the "matching_syntax" data in the upgrade.xml file to determine the filename. $versionIndex = "V". $this->get_full_version_string($fromVersion); - if(!isset($this->config['UPGRADELIST']['MATCHING'][$versionIndex])) { + if(!isset($this->config['matchingData'][$versionIndex])) { //version-only upgrade. $this->newVersion = $toVersion; $this->update_database_version($toVersion); @@ -590,7 +612,7 @@ //scripted upgrade... $scriptIndex = $versionIndex; - $upgradeData = $this->config['UPGRADELIST']['MATCHING'][$versionIndex]; + $upgradeData = $this->config['matchingData'][$versionIndex]; if(isset($upgradeData['TARGET_VERSION']) && count($upgradeData) > 1) { $this->newVersion = $upgradeData['TARGET_VERSION']; @@ -764,9 +786,9 @@ if(!$this->is_higher_version($dbVersion, $newVersion)) { $this->error_handler(__METHOD__ .": version (". $newVersion .") isn't higher than (". $dbVersion .")... something is broken"); } - elseif(is_array($this->config['UPGRADELIST']['MATCHING'])) { + elseif(is_array($this->config['matchingData'])) { $lastVersion = $dbVersion; - foreach($this->config['UPGRADELIST']['MATCHING'] as $matchVersion=>$data) { + foreach($this->config['matchingData'] as $matchVersion=>$data) { $matchVersion = preg_replace('/^V/', '', $matchVersion); if($matchVersion == $data['TARGET_VERSION']) { @@ -1044,8 +1066,8 @@ //if there's an INITIAL_VERSION in the upgrade config file, use that. $this->read_upgrade_config_file(); $insertData = array(); - if(isset($this->config['UPGRADELIST']['INITIALVERSION'])) { - $parseThis = $this->config['UPGRADELIST']['INITIALVERSION']; + if(isset($this->config['INITIALVERSION'])) { + $parseThis = $this->config['INITIALVERSION']; } else { $parseThis = $this->versionFileVersion; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-01-20 01:27:15
|
Revision: 192 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=192&view=rev Author: crazedsanity Date: 2011-01-20 01:27:08 +0000 (Thu, 20 Jan 2011) Log Message: ----------- Better testing using created+dropped database to avoid breaking existing db. /abstract/testDb.abstract.class.php [NEW]: * class for creating, accessing, and destroying a test database. * NOTE::: this class lacks proper exception/error handling. /setup/genericPermissions.pgsql.sql: * remove the BEGIN statement from the top of the file. /tests/testOfCSGenericPermissions.php: * MAIN: -- extends testDbAbstract instead of UnitTestCase. * setUp(): -- call parent to create database -- create new _gpTester, use connection from extended (parent) class * tearDown(): -- destroy the database instead of removing tables * create_dbconn() [DELETED]: -- removed, using connection from parent class. * remove_tables() [DELETED]: -- no longer needed; using a temporary database instead. * get_valid_users(): -- remove call to deleted method -- reference internal db var * test_userGroups(): -- use internal permObj var. -- use internal db var. * test_permissions(): -- don't create new _gpTester (unnecessary) /tests/files/test_db.sql: * fixed uid's so they would not collide. Modified Paths: -------------- trunk/0.4/setup/genericPermissions.pgsql.sql trunk/0.4/tests/files/test_db.sql trunk/0.4/tests/testOfCSGenericPermissions.php Added Paths: ----------- trunk/0.4/abstract/testDb.abstract.class.php Added: trunk/0.4/abstract/testDb.abstract.class.php =================================================================== --- trunk/0.4/abstract/testDb.abstract.class.php (rev 0) +++ trunk/0.4/abstract/testDb.abstract.class.php 2011-01-20 01:27:08 UTC (rev 192) @@ -0,0 +1,83 @@ +<?php + + +abstract class testDbAbstract extends UnitTestCase { + + protected $config = array(); + protected $db; + private $templateDb; + private $templateConfig; + + //----------------------------------------------------------------------------- + public function __construct($superUserName, $password, $hostname, $port) { + /* + 'host' => $this->host, + 'port' => $this->port, + 'dbname' => $this->dbname, + 'user' => $this->user, + 'password' => $this->password + */ + $this->config = array( + 'user' => $superUserName, + 'password' => $password, + 'host' => $hostname, + 'port' => $port, + + //make sure the database name is unique and has (almost) no chance of clashing. + 'dbname' => $this->set_dbname(__CLASS__) + ); + $this->templateConfig = $this->config; + $this->templateConfig['dbname'] = 'template1'; + $this->templateDb = new cs_phpdb('pgsql'); + $this->templateDb->connect($this->templateConfig); + + $this->gfObj = new cs_globalFunctions; + + $this->db = new cs_phpdb('pgsql'); + $this->create_db(); + }//end __construct() + //----------------------------------------------------------------------------- + + + + //----------------------------------------------------------------------------- + private function set_dbname($prefix) { + return(strtolower(__CLASS__ .'_'. preg_replace('/\./', '', microtime(true)))); + }//end set_dbname() + //----------------------------------------------------------------------------- + + + + //----------------------------------------------------------------------------- + protected function create_db() { + $sql = "CREATE DATABASE ". $this->config['dbname']; + $this->templateDb->exec($sql); + + //now run the SQL file. + $this->db->connect($this->config); + $this->db->run_sql_file(dirname(__FILE__) .'/../tests/files/test_db.sql'); + }//end create_db() + //----------------------------------------------------------------------------- + + + + //----------------------------------------------------------------------------- + protected function destroy_db() { + $this->db->close(); + $this->templateDb->exec("DROP DATABASE ". $this->config['dbname']); + }//end destroy_db() + //----------------------------------------------------------------------------- + + + + //----------------------------------------------------------------------------- + public function __destruct() { + #$this->destroy_db(); + }//end __destruct() + //----------------------------------------------------------------------------- + + + +}//end testDbAbstract{} + +?> Modified: trunk/0.4/setup/genericPermissions.pgsql.sql =================================================================== --- trunk/0.4/setup/genericPermissions.pgsql.sql 2011-01-15 05:27:39 UTC (rev 191) +++ trunk/0.4/setup/genericPermissions.pgsql.sql 2011-01-20 01:27:08 UTC (rev 192) @@ -1,4 +1,3 @@ -BEGIN; -- -- Group table Modified: trunk/0.4/tests/files/test_db.sql =================================================================== --- trunk/0.4/tests/files/test_db.sql 2011-01-15 05:27:39 UTC (rev 191) +++ trunk/0.4/tests/files/test_db.sql 2011-01-20 01:27:08 UTC (rev 192) @@ -67,11 +67,11 @@ -- INSERT INTO cs_authentication_table VALUES (101, 'slaughter', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'sla...@de...ll', 1); -INSERT INTO cs_authentication_table VALUES (101, 'mary', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'ma...@de...ll', 1); -INSERT INTO cs_authentication_table VALUES (101, 'einstein', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'ein...@de...ll', 1); -INSERT INTO cs_authentication_table VALUES (101, 'alexander.graham.bell', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'ale...@de...ll', 1); -INSERT INTO cs_authentication_table VALUES (101, 'john', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'jo...@de...ll', 1); -INSERT INTO cs_authentication_table VALUES (101, 'xavier', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'xa...@de...ll', 1); +INSERT INTO cs_authentication_table VALUES (102, 'mary', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'ma...@de...ll', 1); +INSERT INTO cs_authentication_table VALUES (103, 'einstein', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'ein...@de...ll', 1); +INSERT INTO cs_authentication_table VALUES (104, 'alexander.graham.bell', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'ale...@de...ll', 1); +INSERT INTO cs_authentication_table VALUES (105, 'john', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'jo...@de...ll', 1); +INSERT INTO cs_authentication_table VALUES (106, 'xavier', 'x', true, '2008-06-01', '2011-01-10 21:07:07.029629-06', 'xa...@de...ll', 1); -- Modified: trunk/0.4/tests/testOfCSGenericPermissions.php =================================================================== --- trunk/0.4/tests/testOfCSGenericPermissions.php 2011-01-15 05:27:39 UTC (rev 191) +++ trunk/0.4/tests/testOfCSGenericPermissions.php 2011-01-20 01:27:08 UTC (rev 192) @@ -11,18 +11,16 @@ * $LastChangedRevision$ */ -class testOfCSGenericPermissions extends UnitTestCase { +class testOfCSGenericPermissions extends testDbAbstract { //-------------------------------------------------------------------------- function setUp() { $this->gfObj = new cs_globalFunctions; $this->gfObj->debugPrintOpt=1; - if(!defined('CS_UNITTEST')) { - throw new exception(__METHOD__ .": FATAL: constant 'CS_UNITTEST' not set, can't do testing safely"); - } + parent::__construct('postgres','', 'localhost', '5432'); $this->get_valid_users(); - $perm = new _gpTester($this->create_dbconn()); - $perm->do_schema(); + $this->permObj = new _gpTester($this->db); + $this->permObj->do_schema(); }//end setUp() //-------------------------------------------------------------------------- @@ -30,60 +28,20 @@ //-------------------------------------------------------------------------- public function tearDown() { - $this->remove_tables(); + $this->destroy_db(); } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- - private function create_dbconn() { - $dbParams = array( - 'host' => constant('cs_webapplibs-DB_CONNECT_HOST'), - 'dbname' => constant('cs_webapplibs-DB_CONNECT_DBNAME'), - 'user' => constant('cs_webapplibs-DB_CONNECT_USER'), - 'password' => constant('cs_webapplibs-DB_CONNECT_PASSWORD'), - 'port' => constant('cs_webapplibs-DB_CONNECT_PORT') - ); - $db = new cs_phpDB(constant('DBTYPE')); - $db->connect($dbParams); - return($db); - }//end create_dbconn() - //-------------------------------------------------------------------------- - - - - //-------------------------------------------------------------------------- - private function remove_tables() { - $tableList = array( - 'cswal_gdl_object_table', 'cswal_gdl_attribute_table', 'cswal_gdl_path_table', - 'cswal_object_table', 'cswal_user_group_table', 'cswal_group_table' - ); - - $db = $this->create_dbconn(); - foreach($tableList as $name) { - try { - $db->run_update("DROP TABLE ". $name ." CASCADE", true); - } - catch(exception $e) { - //force an error. - //$this->assertTrue(false, "Error while dropping (". $name .")::: ". $e->getMessage()); - } - } - }//end remove_tables() - //-------------------------------------------------------------------------- - - - - //-------------------------------------------------------------------------- /** * Just like the schema, this SQL will need to change to match your database in order to work. */ private function get_valid_users() { $sql = "SELECT uid,username FROM cs_authentication_table ORDER BY uid"; try { - $db = $this->create_dbconn(); - $this->validUsers = $db->run_query($sql); + $this->validUsers = $this->db->run_query($sql); } catch(Exception $e) { cs_debug_backtrace(1); @@ -96,11 +54,9 @@ //-------------------------------------------------------------------------- public function test_userGroups() { - $perm = new _gpTester($this->create_dbconn()); - //make sure there are groups available. { - $groupList = $perm->get_all_groups(); + $groupList = $this->permObj->get_all_groups(); $keys = array_keys($groupList); $myKey = $keys[0]; @@ -114,24 +70,24 @@ //create some groups. { - $newGroupId = $perm->create_group(__METHOD__); + $newGroupId = $this->permObj->create_group(__METHOD__); $this->assertTrue(is_numeric($newGroupId)); - $groupList = $perm->get_all_groups(); + $groupList = $this->permObj->get_all_groups(); foreach($groupList as $groupData) { - $this->assertEqual($perm->get_group_by_id($groupData['group_id']), $groupData); - $this->assertEqual($perm->get_group($groupData['group_name']), $groupData); + $this->assertEqual($this->permObj->get_group_by_id($groupData['group_id']), $groupData); + $this->assertEqual($this->permObj->get_group($groupData['group_name']), $groupData); } } //create & test user_group relationships. { - $newId = $perm->create_user_group($this->validUsers[$myKey]['uid'],1); + $newId = $this->permObj->create_user_group($this->validUsers[$myKey]['uid'],1); $this->assertTrue(is_numeric($newId)); - $this->assertTrue($perm->is_group_member($this->validUsers[$myKey]['uid'],1)); + $this->assertTrue($this->permObj->is_group_member($this->validUsers[$myKey]['uid'],1)); - $ugList = $perm->get_user_groups($this->validUsers[$myKey]['uid']); + $ugList = $this->permObj->get_user_groups($this->validUsers[$myKey]['uid']); $this->assertTrue(is_array($ugList)); $this->assertTrue(count($ugList) > 0); $this->assertFalse(isset($ugList['group_name'])); @@ -144,8 +100,6 @@ //-------------------------------------------------------------------------- public function test_permissions() { - $perm = new _gpTester($this->create_dbconn()); - //Test permission string parsing. { $myPermArr = array( @@ -178,16 +132,16 @@ ); $permString = 'rwx-----x'; - $this->assertEqual(strlen($perm->make_perm_string($myPermArr)),9); - $this->assertEqual(count($perm->parse_perm_string($permString)), 9); - $this->assertEqual($perm->make_perm_string($myPermArr), $permString); - $this->assertEqual(array_keys($perm->parse_perm_string($permString)), array_keys($myPermArr)); - $this->assertEqual($perm->make_perm_string($perm->parse_perm_string($permString)), $permString); - $this->assertEqual(array_keys($perm->parse_perm_string($perm->make_perm_string($myPermArr))), array_keys($myPermArr)); + $this->assertEqual(strlen($this->permObj->make_perm_string($myPermArr)),9); + $this->assertEqual(count($this->permObj->parse_perm_string($permString)), 9); + $this->assertEqual($this->permObj->make_perm_string($myPermArr), $permString); + $this->assertEqual(array_keys($this->permObj->parse_perm_string($permString)), array_keys($myPermArr)); + $this->assertEqual($this->permObj->make_perm_string($this->permObj->parse_perm_string($permString)), $permString); + $this->assertEqual(array_keys($this->permObj->parse_perm_string($this->permObj->make_perm_string($myPermArr))), array_keys($myPermArr)); - $this->assertEqual($perm->get_perm_list($myPermArr,'u'), $permByType['u']); - $this->assertEqual($perm->get_perm_list($myPermArr,'g'), $permByType['g']); - $this->assertEqual($perm->get_perm_list($myPermArr,'o'), $permByType['o']); + $this->assertEqual($this->permObj->get_perm_list($myPermArr,'u'), $permByType['u']); + $this->assertEqual($this->permObj->get_perm_list($myPermArr,'g'), $permByType['g']); + $this->assertEqual($this->permObj->get_perm_list($myPermArr,'o'), $permByType['o']); } //create some permissions. @@ -198,39 +152,39 @@ $usePermString = 'rwxrw-r--'; $usePermName = __METHOD__ .'/test1'; - $this->assertFalse($perm->permission_exists($usePermName)); - $permId = $perm->create_permission($usePermName, $myUid, 1, $usePermString); - $this->assertTrue($perm->permission_exists($usePermName)); + $this->assertFalse($this->permObj->permission_exists($usePermName)); + $permId = $this->permObj->create_permission($usePermName, $myUid, 1, $usePermString); + $this->assertTrue($this->permObj->permission_exists($usePermName)); $this->assertTrue(is_numeric($permId)); //the method 'build_permissions_string()' should disregard extra indices in the array & build the string. - $this->assertEqual($perm->make_perm_string($perm->get_permission_by_id($permId)), $usePermString); - $this->assertEqual($perm->make_perm_string($perm->get_object_by_id($permId)), $usePermString); - $this->assertEqual($perm->make_perm_string($perm->get_permission($usePermName)), $usePermString); - $this->assertEqual($perm->make_perm_string($perm->get_object($usePermName)), $usePermString); + $this->assertEqual($this->permObj->make_perm_string($this->permObj->get_permission_by_id($permId)), $usePermString); + $this->assertEqual($this->permObj->make_perm_string($this->permObj->get_object_by_id($permId)), $usePermString); + $this->assertEqual($this->permObj->make_perm_string($this->permObj->get_permission($usePermName)), $usePermString); + $this->assertEqual($this->permObj->make_perm_string($this->permObj->get_object($usePermName)), $usePermString); //check to make sure individual permission requests work as expected. - $this->assertTrue($perm->has_read_permission($myUid, $usePermName)); - $this->assertTrue($perm->has_write_permission($myUid, $usePermName)); - $this->assertTrue($perm->has_execute_permission($myUid, $usePermName)); + $this->assertTrue($this->permObj->has_read_permission($myUid, $usePermName)); + $this->assertTrue($this->permObj->has_write_permission($myUid, $usePermName)); + $this->assertTrue($this->permObj->has_execute_permission($myUid, $usePermName)); //make sure "anonymous" permissions are correct. - $this->assertTrue($perm->has_read_permission(0,$usePermName)); - $this->assertFalse($perm->has_write_permission(0,$usePermName)); - $this->assertFalse($perm->has_execute_permission(0,$usePermName)); + $this->assertTrue($this->permObj->has_read_permission(0,$usePermName)); + $this->assertFalse($this->permObj->has_write_permission(0,$usePermName)); + $this->assertFalse($this->permObj->has_execute_permission(0,$usePermName)); //put a second user into the proper user_group, then test group permissions. $secondUser = $this->validUsers[$userKeys[1]]['uid']; - $this->assertTrue(is_numeric($perm->create_user_group($secondUser, 1))); - $this->assertTrue($perm->has_read_permission($secondUser, $usePermName)); - $this->assertTrue($perm->has_write_permission($secondUser, $usePermName)); - $this->assertFalse($perm->has_execute_permission($secondUser, $usePermName)); + $this->assertTrue(is_numeric($this->permObj->create_user_group($secondUser, 1))); + $this->assertTrue($this->permObj->has_read_permission($secondUser, $usePermName)); + $this->assertTrue($this->permObj->has_write_permission($secondUser, $usePermName)); + $this->assertFalse($this->permObj->has_execute_permission($secondUser, $usePermName)); //test a THIRD user (non-zero uid), make sure they are subject to the same permissions as anonymous (uid=0) $thirdUser = $this->validUsers[$userKeys[2]]['uid']; - $this->assertEqual($perm->has_read_permission(0,$usePermName), $perm->has_read_permission($thirdUser,$usePermName)); - $this->assertEqual($perm->has_write_permission(0,$usePermName), $perm->has_write_permission($thirdUser,$usePermName)); - $this->assertEqual($perm->has_execute_permission(0,$usePermName), $perm->has_execute_permission($thirdUser,$usePermName)); + $this->assertEqual($this->permObj->has_read_permission(0,$usePermName), $this->permObj->has_read_permission($thirdUser,$usePermName)); + $this->assertEqual($this->permObj->has_write_permission(0,$usePermName), $this->permObj->has_write_permission($thirdUser,$usePermName)); + $this->assertEqual($this->permObj->has_execute_permission(0,$usePermName), $this->permObj->has_execute_permission($thirdUser,$usePermName)); } }//end test_permissions //-------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-01-26 04:25:48
|
Revision: 193 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=193&view=rev Author: crazedsanity Date: 2011-01-26 04:25:41 +0000 (Wed, 26 Jan 2011) Log Message: ----------- Drop Generic Data Linker code, since it was flawed and really isn't used. Modified Paths: -------------- trunk/0.4/setup/schema.mysql.sql trunk/0.4/setup/schema.pgsql.sql trunk/0.4/tests/testOfCSWebAppLibs.php Removed Paths: ------------- trunk/0.4/abstract/cs_gdlAttrib.abstract.class.php trunk/0.4/abstract/cs_gdlObject.abstract.class.php trunk/0.4/abstract/cs_gdlPath.abstract.class.php Deleted: trunk/0.4/abstract/cs_gdlAttrib.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_gdlAttrib.abstract.class.php 2011-01-20 01:27:08 UTC (rev 192) +++ trunk/0.4/abstract/cs_gdlAttrib.abstract.class.php 2011-01-26 04:25:41 UTC (rev 193) @@ -1,89 +0,0 @@ -<?php -/* - * Created on Jan 29, 2009 - * - * FILE INFORMATION: - * - * $HeadURL$ - * $Id$ - * $LastChangedDate$ - * $LastChangedBy$ - * $LastChangedRevision$ - */ - -abstract class cs_gdlAttribAbstract extends cs_gdlPathAbstract { - - - const table='cswal_gdl_attribute_table'; - const tableSeq = 'cswal_gdl_attribute_table_attribute_id_seq'; - - - - //------------------------------------------------------------------------- - public function create_attrib($path, $data, $type=null) { - - $objectId = $this->get_object_id_from_path($path); - - $insertString = ""; - $attribs = array(); - if(is_array($data) && count($data)) { - foreach($data as $n=>$v) { - $n = $this->translate_attrib_name($n); - $attribs[$n] = $v; - } - } - elseif(!is_null($type)) { - $key = $this->translate_attrib_name($type); - $attribs = array($key => $data); - } - else { - throw new exception(__METHOD__ .": data was not array and no type set"); - } - - if(!is_array($attribs) || !count($attribs)) { - throw new exception(__METHOD__ .": failed to create an array of attributes... ". $this->gfObj->debug_print(func_get_args(),0)); - } - - $attribs['object_id'] = $objectId; - $insertString = $this->gfObj->string_from_array($attribs, 'insert'); - - - if(!strlen($insertString)) { - throw new exception(__METHOD__ .": invalid insert string (". $insertString .")"); - } - $sql = "INSERT INTO ". self::attrTable ." ". $insertString; - - try { - $retval = $this->db->run_insert($sql, self::attrTableSeq); - } - catch(exception $e) { - throw new exception(__METHOD__ .": failed to perform insert::: ". $e->getMessage() .' ---- '. $sql); - } - - return($retval); - }//end create_attrib() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function translate_attrib_name($name) { - $retval = null; - foreach($this->validTypes as $type) { - if(preg_match('/^'. $type .'/', $name)) { - $retval = 'a_'. $type; - break; - } - } - - if(is_null($retval) || !strlen($retval)) { - $this->gfObj->debug_print(__METHOD__ .": name was (". $name ."), retval=(". $retval .")",1); - throw new exception(__METHOD__ .": invalid attribute name (". $name .")"); - } - - return($retval); - }//end translate_attrib_name() - //------------------------------------------------------------------------- - -} -?> \ No newline at end of file Deleted: trunk/0.4/abstract/cs_gdlObject.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_gdlObject.abstract.class.php 2011-01-20 01:27:08 UTC (rev 192) +++ trunk/0.4/abstract/cs_gdlObject.abstract.class.php 2011-01-26 04:25:41 UTC (rev 193) @@ -1,136 +0,0 @@ -<?php -/* - * Created on Jan 29, 2009 - * - * FILE INFORMATION: - * - * $HeadURL$ - * $Id$ - * $LastChangedDate$ - * $LastChangedBy$ - * $LastChangedRevision$ - */ - -abstract class cs_gdlObjectAbstract extends cs_webapplibsAbstract { - - - const table='cswal_gdl_object_table'; - const tableSeq = 'cswal_gdl_object_table_object_id_seq'; - - //------------------------------------------------------------------------- - public function get_object_id_from_path($path) { - $sql = "SELECT object_id FROM ". self::table ." WHERE object_path='". - $this->clean_path($path) ."'"; - - try { - $data = $this->db->run_query($sql); - - if(is_array($data) && count($data) == 1) { - $retval = $data['object_id']; - } - else { - throw new exception(__METHOD__ .": invalid data for path (". $this->clean_path($path) .")::: ". $this->gfObj->debug_var_dump($data,0)); - } - } - catch(exception $e) { - throw new exception(__METHOD__ .": error retrieving path::: ". $e->getMessage()); - } - - return($retval); - }//end get_object_id_from_path() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function create_object($name, $data=null, $type=null) { - $sql = "INSERT INTO ". self::table ." (object_name) VALUES ('". - $this->gfObj->cleanString($this->clean_path($name), 'sql_insert') ."')"; - try { - $retval = $this->db->run_insert($sql, self::tableSeq); - } - catch(exception $e) { - throw new exception(__METHOD__ .": failed to perform insert::: ". $e->getMessage()); - } - - if(!is_null($data)) { - throw new exception(__METHOD__ .": can't create data for objects yet"); - } - return($retval); - }//end create_object() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function build_object_id_list(array $objects) { - $this->gfObj->switch_force_sql_quotes(1); - $sql = "SELECT * FROM ". self::table ." WHERE object_name IN (". - $this->gfObj->string_from_array($objects, null, ',', 'sql') .")"; - $this->gfObj->switch_force_sql_quotes(0); - - $retval = array(); - try { - $retval = $this->db->run_query($sql, 'object_name', 'object_id'); - if(!is_array($retval)) { - $retval = array(); - } - } - catch(exception $e) { - //throw new exception(__METHOD__ .": failed to retrieve list"); - } - - return($retval); - }//end build_object_id_list() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function build_object_name_list(array $objectIds) { - $this->gfObj->switch_force_sql_quotes(1); -//string_from_array($array,$style=NULL,$separator=NULL, $cleanString=NULL, $removeEmptyVals=FALSE) - foreach($objectIds as $i=>$myId) { - if(!strlen($myId)) { - unset($objectIds[$i]); - } - } - $sql = "SELECT * FROM ". self::table ." WHERE object_id IN (". - $this->gfObj->string_from_array($objectIds, null, ',', 'sql',true) .")"; - $this->gfObj->switch_force_sql_quotes(0); - - try { - $retval = $this->db->run_query($sql, 'object_id', 'object_name'); - if(!is_array($retval)) { - $retval = array(); - } - } - catch(exception $e) { - throw new exception(__METHOD__ .": failed to retrieve list::: ". $e->getMessage()); - } - - return($retval); - }//end build_object_id_list() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function create_objects_enmasse(array $objectList) { - $retval = 0; - foreach($objectList as $name) { - try { - $this->create_object($name); - $retval++; - } - catch(exception $e) { - //nothing to see here, move along. - } - } - return($retval); - }//end create_objects_enmasse() - //------------------------------------------------------------------------- - - -} -?> Deleted: trunk/0.4/abstract/cs_gdlPath.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_gdlPath.abstract.class.php 2011-01-20 01:27:08 UTC (rev 192) +++ trunk/0.4/abstract/cs_gdlPath.abstract.class.php 2011-01-26 04:25:41 UTC (rev 193) @@ -1,126 +0,0 @@ -<?php -/* - * Created on Jan 29, 2009 - * - * FILE INFORMATION: - * - * $HeadURL$ - * $Id$ - * $LastChangedDate$ - * $LastChangedBy$ - * $LastChangedRevision$ - */ - -abstract class cs_gdlPathAbstract extends cs_gdlObjectAbstract { - - - const table='cswal_gdl_path_table'; - const tableSeq = 'cswal_gdl_path_table_path_id_seq'; - - - - - - //------------------------------------------------------------------------- - public function create_path($path) { - $idList = $this->create_path_objects($path); - $pathIdList = $this->create_id_path($idList); - - if($this->get_path_from_idlist($pathIdList)) { - $retval = $pathIdList; - } - else { - - $sql = "INSERT INTO ". self::table ." (path_id_list) VALUES ('". $pathIdList ."')"; - - try { - $insertedId = $this->db->run_insert($sql, self::tableSeq); - $retval = $pathIdList; - } - catch(exception $e) { - throw new exception(__METHOD__ .": unable to create path::: ". $e->getMessage()); - } - } - - return($retval); - }//end create_path() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function clean_path($path, $appendBase=true) { - if(strlen($path)) { - if($appendBase === true && !is_null($this->basePath)) { - $path = $this->basePath .'/'. $path; - } - $newPath = preg_replace('/\/{2,}/', '/', $path); - - if(!strlen($newPath)) { - throw new exception(__METHOD__ .": new path is zero-length (". $newPath ."), old path=(". func_get_arg(0) .")"); - } - } - else { - throw new exception(__METHOD__ .": no valid path given (". $path .")"); - } - - return($newPath); - }//end clean_path() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function set_base_path($path) { - if(is_null($path) || !strlen($path)) { - $this->basePath = null; - } - else { - $this->basePath = $this->clean_path($path,false); - } - }//end set_base_path() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function explode_path($path, $appendBase=true) { - $path = $this->clean_path($path, $appendBase); - $path = preg_replace('/^\//', '', $path); - $path = preg_replace('/\/$/', '', $path); - - return(explode('/', $path)); - }//end explode_path() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function create_id_path(array $idList) { - $retval = ':'. $this->gfObj->string_from_array($idList, null, '::') .':'; - return($retval); - }//end create_id_path() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function get_path_from_idlist($idPath) { - - $idList = explode('::', preg_replace('/^:/', '', preg_replace('/:$/', '', $idPath))); - - $nameList = $this->build_object_name_list($idList); - - $retval = "/"; - foreach($nameList as $id=>$name) { - $retval = $this->gfObj->create_list($retval, $name, '/'); - } - - $retval = $this->clean_path($retval,false); - - return($retval); - }//end get_text_path_from_id_path() - //------------------------------------------------------------------------- - -} -?> \ No newline at end of file Modified: trunk/0.4/setup/schema.mysql.sql =================================================================== --- trunk/0.4/setup/schema.mysql.sql 2011-01-20 01:27:08 UTC (rev 192) +++ trunk/0.4/setup/schema.mysql.sql 2011-01-26 04:25:41 UTC (rev 193) @@ -168,33 +168,6 @@ -- --- Table for cs_genericDataLinker{}. --- -CREATE TABLE `cswal_gdl_object_table` ( - `object_id` int(11) NOT NULL PRIMARY KEY auto_increment, - `object_name` text NOT NULL UNIQUE -) ENGINE=InnoDB; - - -CREATE TABLE `cswal_gdl_path_table` ( - `path_id` int(11) NOT NULL PRIMARY KEY auto_increment, - `path_id_list` text NOT NULL UNIQUE -) ENGINE=InnoDB; - --- --- Store attributes here. --- NOTE: fields prefixed with "a_" to avoid clashes with reserved words. --- -CREATE TABLE `cswal_gdl_attribute_table` ( - `attribute_id` serial NOT NULL PRIMARY KEY auto_increment, - `object_path` text NOT NULL, - `a_text` text DEFAULT NULL, - `a_int` integer DEFAULT NULL, - `a_dec` decimal(10,2) DEFAULT NULL, - `a_bool` boolean DEFAULT NULL -) ENGINE=InnoDB; - --- -- Constraints for dumped tables -- Modified: trunk/0.4/setup/schema.pgsql.sql =================================================================== --- trunk/0.4/setup/schema.pgsql.sql 2011-01-20 01:27:08 UTC (rev 192) +++ trunk/0.4/setup/schema.pgsql.sql 2011-01-26 04:25:41 UTC (rev 193) @@ -119,30 +119,3 @@ session_data text ); - --- --- Table for cs_genericDataLinker{}. --- -CREATE TABLE cswal_gdl_object_table ( - object_id serial NOT NULL PRIMARY KEY, - object_name text NOT NULL UNIQUE -); - - -CREATE TABLE cswal_gdl_path_table ( - path_id serial NOT NULL PRIMARY KEY, - path_id_list text NOT NULL UNIQUE -); - --- --- Store attributes here. --- NOTE: fields prefixed with "a_" to avoid clashes with reserved words. --- -CREATE TABLE cswal_gdl_attribute_table ( - attribute_id serial NOT NULL PRIMARY KEY, - object_path text NOT NULL, - a_text text DEFAULT NULL, - a_int integer DEFAULT NULL, - a_dec decimal(10,2) DEFAULT NULL, - a_bool boolean DEFAULT NULL -); Modified: trunk/0.4/tests/testOfCSWebAppLibs.php =================================================================== --- trunk/0.4/tests/testOfCSWebAppLibs.php 2011-01-20 01:27:08 UTC (rev 192) +++ trunk/0.4/tests/testOfCSWebAppLibs.php 2011-01-26 04:25:41 UTC (rev 193) @@ -11,66 +11,40 @@ * $LastChangedRevision$ */ -class testOfCSWebAppLibs extends UnitTestCase { +class testOfCSWebAppLibs extends testDbAbstract { //-------------------------------------------------------------------------- function __construct() { $this->gfObj = new cs_globalFunctions; $this->gfObj->debugPrintOpt=1; - if(!defined('CS_UNITTEST')) { - throw new exception(__METHOD__ .": FATAL: constant 'CS_UNITTEST' not set, can't do testing safely"); - } }//end __construct() //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- - private function create_dbconn() { - $dbParams = array( - 'host' => constant('cs_webapplibs-DB_CONNECT_HOST'), - 'dbname' => constant('cs_webapplibs-DB_CONNECT_DBNAME'), - 'user' => constant('cs_webapplibs-DB_CONNECT_USER'), - 'password' => constant('cs_webapplibs-DB_CONNECT_PASSWORD'), - 'port' => constant('cs_webapplibs-DB_CONNECT_PORT') - ); - $db = new cs_phpDB(constant('DBTYPE')); - $db->connect($dbParams); - return($db); - }//end create_dbconn() + function setUp() { + $this->gfObj = new cs_globalFunctions; + $this->gfObj->debugPrintOpt=1; + parent::__construct('postgres','', 'localhost', '5432'); + $tok = new authTokenTester($this->db); + $tok->load_schema('pgsql', $this->db); + }//end setUp() //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- - private function remove_tables() { - $tableList = array( - 'cswal_auth_token_table', 'cswal_version_table', 'cswal_attribute_table', - 'cswal_category_table', 'cswal_class_table', 'cswal_event_table', - 'cswal_log_attribute_table', 'cswal_log_table', 'cswal_session_store_table', - 'cswal_gdl_object_table', 'cswal_gdl_path_table', 'cswal_gdl_attribute_table' - ); - - $db = $this->create_dbconn(); - foreach($tableList as $name) { - try { - $db->run_update("DROP TABLE ". $name ." CASCADE", true); - } - catch(exception $e) { - //force an error. - //$this->assertTrue(false, "Error while dropping (". $name .")::: ". $e->getMessage()); - } - } - }//end remove_tables() + public function tearDown() { + $this->destroy_db(); + } //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- function test_token_basics() { - $db = $this->create_dbconn(); - $this->remove_tables(); - $tok = new authTokenTester($db); + $tok = new authTokenTester($this->db); //Generic test to ensure we get the appropriate data back. { @@ -202,262 +176,6 @@ //-------------------------------------------------------------------------- - function test_genericDataLinker() { - - $x = new gdlTester($this->create_dbconn()); - - //test objects & paths first. - { - $myPath = '/character/sheet///Tetra Tealeaf'; - - $this->assertEqual(array('character', 'sheet', 'Tetra Tealeaf'), $x->explode_path($myPath)); - $x->set_base_path('/testing'); - $this->assertEqual('/testing/character/sheet/Tetra Tealeaf', $x->clean_path($myPath)); - $this->assertEqual(array('testing', 'character', 'sheet', 'Tetra Tealeaf'), $x->explode_path($myPath)); - $x->set_base_path(null); - $this->assertNotEqual(array('testing', 'character', 'sheet', 'Tetra Tealeaf'), $x->explode_path($myPath)); - $this->assertEqual(array('character', 'sheet', 'Tetra Tealeaf'), $x->explode_path($myPath)); - $this->assertEqual('/character/sheet/Tetra Tealeaf', $x->clean_path($myPath)); - - //now create some objects. - $pathBits = array(); - foreach($x->explode_path($myPath) as $name) { - $pathBits[$x->create_object($name)] = $name; - } - $newPathIdList = $x->create_path($myPath); - $myPathIdList = ':'. $this->gfObj->string_from_array(array_keys($pathBits), null, '::') .':'; - $this->assertEqual($newPathIdList, $myPathIdList); - - $newId = $x->create_object('testing'); - $t = array_keys($pathBits); - $t = array_pop($t); - $lastPathId = $t; - $this->assertEqual($newId, ($lastPathId +1)); - - $oldBits = $pathBits; - $pathBits = array(); - $pathBits[$newId] = 'testing'; - foreach($oldBits as $id=>$name) { - $pathBits[$id] = $name; - } - - $newPathIdList = $x->create_path('/testing/'. $myPath); - $myPathIdList = ':'. $this->gfObj->string_from_array(array_flip($pathBits), null, '::') .':'; - $this->assertEqual($newPathIdList, $myPathIdList); - - $this->assertEqual($newPathIdList, $x->create_path('/testing/'. $myPath)); - - $myRearrangedPath = array_reverse($pathBits, true); - $rPathIdList = ':'. $this->gfObj->string_from_array(array_flip($myRearrangedPath), null, '::') .':'; - $rPath = '/'. $this->gfObj->string_from_array($myRearrangedPath, null, '/'); - $this->assertEqual($x->create_path($rPath), $rPathIdList); - - $this->assertEqual($x->get_path_from_idlist($x->create_path($rPath)), $x->get_path_from_idlist($rPathIdList)); - $this->assertEqual($x->get_path_from_idlist($x->create_path($rPath)), $x->get_path_from_idlist($rPathIdList)); - $this->assertEqual($x->get_path_from_idlist($x->create_path($rPath)), $x->get_path_from_idlist($rPathIdList)); - $this->assertEqual($x->get_path_from_idlist($x->create_path($rPath)), $x->get_path_from_idlist($rPathIdList)); - } - - - //basic tests for building text-based paths vs. id-based paths. - { - $myPath = '/character/sheet/Tetra Tealeaf'; - - - $idList = $x->createPathObjects($myPath); - - $testObjectIdList = explode('/', preg_replace('/^\//', '', $myPath)); - $this->assertEqual($idList, $x->build_object_id_list($testObjectIdList)); - - $idList2 = $x->create_path($myPath); - $this->assertEqual($x->create_id_path(array_values($idList)), $idList2); - - $this->assertEqual($myPath, $x->get_path_from_idlist($x->create_id_path($idList))); - $this->gfObj->debug_var_dump($x->get_path_from_idlist($x->create_id_path($idList))); - - $this->gfObj->debug_var_dump($idList); - $this->gfObj->debug_var_dump($idList2); - - $this->assertEqual(':1::2::3:', $idList2); - $this->assertEqual($idList2, ':'. $this->gfObj->string_from_array($idList, null, '::') .':'); - - $this->assertEqual(':1::2::3:', $x->create_id_path($idList)); - - $this->assertEqual(':1:', $x->create_id_path(array(1))); - $this->assertEqual(':000010:', $x->create_id_path(array('000010'))); - - } - - - // now REALLY test paths. - { - $gdl = new gdlTester($this->create_dbconn()); - - $myBasePath = '/character/sheet/Xander Cage'; - $x->set_base_path($myBasePath); - - //now add something that should be BENEATH that path. - $idList = $x->create_path('attributes/str'); - - $this->gfObj->debug_var_dump($idList); - } - #*/ - - - - - /*/test some basics first. - $translations = array( - 'good' => array( - 'a_int' => array('int', 'integer', 'integraIsACarNotAnArgument'), - 'a_dec' => array('dec', 'decimal', 'decemberIsAMonth'), - 'a_bool' => array('bool', 'boolean', 'boolJustLooksLikeSomethingJiggly'), - 'a_text' => array('text', 'textual', 'textPaperJustLooksPink') - ), - 'bad' => array( - 'a_int' => array('num', 'a_int', 'nittedStuff'), - 'a_dec' => array('dce', 'a_dec', 'dceStuff'), - 'a_bool' => array('bolo', 'a_bool', 'boloMeansBeOnLookOut'), - 'a_text' => array('txt', 'a_text', 'txtIsABadAbbreviation') - ) - ); - - foreach($translations as $goodBad=>$matchesArray) { - foreach($matchesArray as $matchThis => $tryThese) { - foreach($tryThese as $k) { - try { - $this->assertEqual($matchThis, $x->translate_attrib_name($k)); - } - catch(exception $e) { - if($goodBad == 'good') { - $this->assertFalse(true, "test (". $k .") should have been good, but was bad::: ". $e->getMessage()); - } - } - } - } - } - $testData = array( - 'skills/Appraise/cc' => array('bool' => true), - 'skills/Appraise/mod' => array('int' => 3), - 'skills/Appraise/ab_mod' => array('int' => 3), - 'skills/Appraise/rank' => array('int' => 3), - 'skills/Appraise/misc_mod' => array('int' => 3), - 'skills/Appraise/notes' => array('text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit."), - 'skills/Appraise/test' => array( - 'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", - 'bool' => true, - 'dec' => 0.03 - ), - ); - - - $myBasePath = '/characters/Tetra Tealeaf/'; - $x->set_base_path($myBasePath); - foreach($testData as $path=>$subData) { - $this->assertEqual($myBasePath . $path, $x->clean_path($path)); - $this->assertTrue(is_numeric($x->create_object($path, $subData))); - } - - //get each individual item about the skill 'Appraise' individually. - $x->get_object_attribs('skills/Appraise/cc', 'bool'); - $x->get_object_attribs('skills/Appraise/mod', 'int'); - $x->get_object_attribs('skills/Appraise/ab_mod', 'int'); - $x->get_object_attribs('skills/Appraise/rank', 'int'); - $x->get_object_attribs('skills/Appraise/misc_mod', 'int'); - $x->get_object_attribs('skills/Appraise/notes', 'text'); - $x->get_object_attribs('skills/Appraise/test', array('text', 'bool', 'dec')); - $returnVal = array( - 'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", - 'bool' => true, - 'dec' => 0.03 - ); - - - //another way to retrieve it, without caring about what types are returned::: - $returnVal = $x->get_all_object_attribs('skills/Appraise', false); - $returnVal = array( - 'cc' => array( - 'test' => null, - 'bool' => true, - 'int' => null, - 'dec' => null - ), - 'mod' => array( - 'test' => null, - 'bool' => null, - 'int' => 10, - 'dec' => null - ), - 'ab_mod' => array( - 'test' => null, - 'bool' => null, - 'int' => 3, - 'dec' => null - ), - 'rank' => array( - 'test' => null, - 'bool' => null, - 'int' => 6, - 'dec' => null - ), - 'misc_mod' => array( - 'test' => null, - 'bool' => null, - 'int' => 1, - 'dec' => null - ), - 'notes' => array( - 'test' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", - 'bool' => null, - 'int' => null, - 'dec' => null - ), - 'test' => array( - 'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", - 'bool' => true, - 'int' => null, - 'dec' => 0.03 - ) - ); - - //a better way to retrieve that data: - $returnVal = $x->get_all_object_attribs('skills/Appraise', false); - $returnVal = array( - 'cc' => true, - 'mod' => 10, - 'ab_mod' => 3, - 'rank' => 6, - 'misc_mod' => 1, - 'notes' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", - 'test' => array( - 'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", - 'bool' => true, - 'dec' => 0.03 - ) - ); - - //if we don't want all that junk in test, we can specify what to get for EACH one: - $types = array( - 'cc' => "bool", - 'test' => "dec" - ); - $returnVal = $x->get_all_object_attribs('skills/Appraise', false, $types); - $returnVal = array( - 'cc' => true, - 'mod' => 10, - 'ab_mod' => 3, - 'rank' => 6, - 'misc_mod' => 1, - 'notes' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", - 'test' => 0.03 - ); - #*/ - }//end test_genericDataLinker() - //-------------------------------------------------------------------------- - - - - //-------------------------------------------------------------------------- public function test_genericPermissions() { }//end test_genericPermissions() //-------------------------------------------------------------------------- @@ -494,16 +212,4 @@ } } -class gdlTester extends cs_genericDataLinker { - public $isTest = true; - - public function __construct($db) { - parent::__construct($db); - } - - public function createPathObjects($path) { - return($this->create_path_objects($path)); - } -} - ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-01-26 23:06:52
|
Revision: 195 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=195&view=rev Author: crazedsanity Date: 2011-01-26 17:26:38 +0000 (Wed, 26 Jan 2011) Log Message: ----------- All tests work + minor fixes and tweaks. /tests/testOfCSGenericPermissions.php: * __construct() [NEW]: -- explicitely define so parent::__construct() is not called. * setUp(): -- call get_valid_users() only AFTER the permission object is used to create the schema for cs-webapplibs. * tearDown(): -- allow a way to NOT destroy the database after a test. * test_userGroups(): -- commented-out code for keeping a database around -- fixed code for testing creation of user groups (remove a hard-coded value of group ID, instead using a dynamic one). /abstract/cs_genericUserGroup.abstract.class.php: * get_user_groups(): -- also retrieve the "group_admin" field in the query (for later use) Modified Paths: -------------- trunk/0.4/abstract/cs_genericUserGroup.abstract.class.php trunk/0.4/tests/testOfCSGenericPermissions.php Modified: trunk/0.4/abstract/cs_genericUserGroup.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_genericUserGroup.abstract.class.php 2011-01-26 04:33:58 UTC (rev 194) +++ trunk/0.4/abstract/cs_genericUserGroup.abstract.class.php 2011-01-26 17:26:38 UTC (rev 195) @@ -52,7 +52,7 @@ public function get_user_groups($userId) { if(is_numeric($userId) && $userId >= 0) { try { - $sql = "SELECT ug.*, g.group_name FROM ". self::ugTable ." AS ug INNER " + $sql = "SELECT ug.*, g.group_name, g.group_admin FROM ". self::ugTable ." AS ug INNER " ."JOIN ". parent::groupTable ." as g USING (group_id) WHERE user_id=". $userId; $retval = $this->db->run_query($sql, 'group_id'); } Modified: trunk/0.4/tests/testOfCSGenericPermissions.php =================================================================== --- trunk/0.4/tests/testOfCSGenericPermissions.php 2011-01-26 04:33:58 UTC (rev 194) +++ trunk/0.4/tests/testOfCSGenericPermissions.php 2011-01-26 17:26:38 UTC (rev 195) @@ -13,14 +13,22 @@ class testOfCSGenericPermissions extends testDbAbstract { + //-------------------------------------------------------------------------- + public function __construct() { + }//end __construct() + //-------------------------------------------------------------------------- + + + + //-------------------------------------------------------------------------- function setUp() { $this->gfObj = new cs_globalFunctions; $this->gfObj->debugPrintOpt=1; parent::__construct('postgres','', 'localhost', '5432'); - $this->get_valid_users(); $this->permObj = new _gpTester($this->db); $this->permObj->do_schema(); + $this->get_valid_users(); }//end setUp() //-------------------------------------------------------------------------- @@ -28,7 +36,12 @@ //-------------------------------------------------------------------------- public function tearDown() { - $this->destroy_db(); + if(isset($GLOBALS['keepDb'])) { + unset($GLOBALS['keepDb']); + } + else { + $this->destroy_db(); + } } //-------------------------------------------------------------------------- @@ -54,6 +67,7 @@ //-------------------------------------------------------------------------- public function test_userGroups() { + #$GLOBALS['keepDb'] = true; //make sure there are groups available. { $groupList = $this->permObj->get_all_groups(); @@ -83,9 +97,11 @@ //create & test user_group relationships. { - $newId = $this->permObj->create_user_group($this->validUsers[$myKey]['uid'],1); + $newId = $this->permObj->create_user_group($this->validUsers[$myKey]['uid'],$newGroupId); $this->assertTrue(is_numeric($newId)); - $this->assertTrue($this->permObj->is_group_member($this->validUsers[$myKey]['uid'],1)); + $this->assertTrue($this->permObj->is_group_member($this->validUsers[$myKey]['uid'],$newGroupId), "user (". + $this->validUsers[$myKey]['uid'] .") isn't member of group (". $newGroupId .") after ". + "being added to it... "); $ugList = $this->permObj->get_user_groups($this->validUsers[$myKey]['uid']); $this->assertTrue(is_array($ugList)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-01-26 23:07:11
|
Revision: 197 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=197&view=rev Author: crazedsanity Date: 2011-01-26 18:09:30 +0000 (Wed, 26 Jan 2011) Log Message: ----------- Add some stuff for permissions so it will use an "id path", so it will be much easier to determine what should inherit from what... EXPERIMENTAL!!! Modified Paths: -------------- trunk/0.4/setup/genericPermissions.pgsql.sql Added Paths: ----------- trunk/0.4/cs_idPath.class.php trunk/0.4/cs_urlBasedPermission.class.php Copied: trunk/0.4/cs_idPath.class.php (from rev 195, trunk/0.4/cs_genericPermission.class.php) =================================================================== --- trunk/0.4/cs_idPath.class.php (rev 0) +++ trunk/0.4/cs_idPath.class.php 2011-01-26 18:09:30 UTC (rev 197) @@ -0,0 +1,26 @@ +<?php +/* + * Created on January 26, 2011 + * + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +class cs_idPath extends cs_webapplibsAbstract { + + /** cs_globalFunctions object, for cleaning strings & such. */ + public $gfObj; + + //============================================================================ + /** + */ + public function __construct() { + }//end __construct() + //============================================================================ + +} Property changes on: trunk/0.4/cs_idPath.class.php ___________________________________________________________________ Added: svn:keywords + Id Author Revision HeadURL Date Added: svn:mergeinfo + Copied: trunk/0.4/cs_urlBasedPermission.class.php (from rev 195, trunk/0.4/cs_genericPermission.class.php) =================================================================== --- trunk/0.4/cs_urlBasedPermission.class.php (rev 0) +++ trunk/0.4/cs_urlBasedPermission.class.php 2011-01-26 18:09:30 UTC (rev 197) @@ -0,0 +1,54 @@ +<?php +/* + * Created on January 26, 2011 + * + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +class cs_urlBasedPermission extends cs_genericPermission { + + + //============================================================================ + /** + * Permission system for Web URLs; so "http://web.site.com/index" can have + * special permissions. The most important part is that a permission set for + * the URL "/" might have a setting, and "/x/y/z" might as well, without + * anything for the interim URLs ("/x", "/x/y", "/x/y/z"); those missing URLs + * are given the permissions for the closest URL (in this case "/"). + */ + public function __construct(cs_phpDB $db) { + $this->db = $db; + $this->gfObj = new cs_globalFunctions; + parent::__construct($db); + }//end __construct() + //============================================================================ + + + + //============================================================================ + /** + * Break the URL into bits (delimited by "/"), and return an array. + */ + private function _get_url_bits($url) { + $url = $this->gfObj->clean_url($url); + if(!is_array($url)) { + $bits = array("/"); + } + else { + $bits = explode("/", $url); + } + return($bits); + }//end _get_url_bits() + //============================================================================ + + + + //============================================================================ + //============================================================================ +} Property changes on: trunk/0.4/cs_urlBasedPermission.class.php ___________________________________________________________________ Added: svn:keywords + Id Author Revision HeadURL Date Added: svn:mergeinfo + Modified: trunk/0.4/setup/genericPermissions.pgsql.sql =================================================================== --- trunk/0.4/setup/genericPermissions.pgsql.sql 2011-01-26 18:08:16 UTC (rev 196) +++ trunk/0.4/setup/genericPermissions.pgsql.sql 2011-01-26 18:09:30 UTC (rev 197) @@ -6,7 +6,8 @@ CREATE TABLE cswal_group_table ( group_id serial NOT NULL PRIMARY KEY, group_name text NOT NULL UNIQUE, - group_admin integer REFERENCES cs_authentication_table(uid) + group_admin integer REFERENCES cs_authentication_table(uid), + created TIMESTAMPTZ NOT NULL DEFAULT NOW() ); -- @@ -17,21 +18,54 @@ CREATE TABLE cswal_user_group_table ( user_group_id serial NOT NULL PRIMARY KEY, user_id integer NOT NULL REFERENCES cs_authentication_table(uid), - group_id integer NOT NULL REFERENCES cswal_group_table(group_id) + group_id integer NOT NULL REFERENCES cswal_group_table(group_id), + created TIMESTAMPTZ NOT NULL DEFAULT NOW() ); +-- +-- System Table +-- Allows types of permissions to be separated (i.e. URL-based permissions from action-based permissions) +-- NOTE::: setting "use_default_deny" to TRUE means requests to objects within the given system are automatically denied, a setting +-- of FALSE means those requests are automatically granted (USE WITH CAUTION). +-- +CREATE TABLE cswal_system_table ( + system_id serial NOT NULL PRIMARY KEY, + system_name text NOT NULL UNIQUE, + use_default_deny boolean NOT NULL DEFAULT TRUE, + created TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + + +-- +-- Object table +-- Unique set of names which should be chained together to create an object path; for a URL of "/member/blog/edit", the pieces would be created +-- with ID's, such as "member"=1, "blog"=2, "edit"=3; the object path would then be ":1::2::3:"; an extra prefix element might be created to +-- define a default, inheritable set of permissions, such as "{root}"=10; the path might then be ":10::1::2::3:". -- --- Object table --- Contains unique list of objects along with the owner, default group, & user/group/other permissions (like *nix filesystem permissions) +CREATE TABLE cswal_object_table ( + object_id integer NOT NULL PRIMARY KEY, + object_name text NOT NULL UNIQUE, + is_hidden boolean NOT NULL DEFAULT FALSE, + created TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + + +-- +-- Permission table +-- Contains unique list of object paths along with the owner, default group, & user/group/other permissions (like *nix filesystem permissions) -- The permissions for user/group/other could be converted to octal (i.e. "rwxrwxrwx" == "777"), but it isn't as straightforward to read. -- NOTE::: the "user_id" table should be updated to match your database schema. +-- NOTE2:: the "inherit" column isn't used by the base permissions system. +-- NOTE3:: the "object_path" is a chain of object_id's. -- -CREATE TABLE cswal_object_table ( - object_id serial NOT NULL PRIMARY KEY, - object_name text NOT NULL UNIQUE, +CREATE TABLE cswal_permission_table ( + permission_id serial NOT NULL PRIMARY KEY, + system_name integer NOT NULL DEFAULT 0 REFERENCES cswal_system_table(system_id), + object_path text NOT NULL UNIQUE, user_id integer NOT NULL REFERENCES cs_authentication_table(uid), group_id integer NOT NULL REFERENCES cswal_group_table(group_id), + inherit boolean NOT NULL DEFAULT FALSE, u_r boolean NOT NULL DEFAULT TRUE, u_w boolean NOT NULL DEFAULT TRUE, u_x boolean NOT NULL DEFAULT FALSE, @@ -40,20 +74,26 @@ g_x boolean NOT NULL DEFAULT FALSE, o_r boolean NOT NULL DEFAULT TRUE, o_w boolean NOT NULL DEFAULT FALSE, - o_x boolean NOT NULL DEFAULT FALSE + o_x boolean NOT NULL DEFAULT FALSE, + created TIMESTAMPTZ NOT NULL DEFAULT NOW() ); +INSERT INTO cswal_system_table (system_id, system_name) VALUES (0, 'DEFAULT'); INSERT INTO cswal_group_table (group_name) VALUES ('www'); INSERT INTO cswal_group_table (group_name) VALUES ('blogs'); INSERT INTO cswal_group_table (group_name) VALUES ('admin'); -INSERT INTO cswal_object_table - (object_name,user_id, group_id) +INSERT INTO cswal_object_table (object_id, object_name,is_hidden) VALUES (0, '/', true); +INSERT INTO cswal_object_table (object_id, object_name,is_hidden) VALUES (1, 'member', false); + +INSERT INTO cswal_permission_table + (object_path,user_id, group_id) VALUES - ('/', 101, 1); + (':0:', 101, 1); -INSERT INTO cswal_object_table - (object_name, user_id, group_id, g_r, g_w) +INSERT INTO cswal_permission_table + (object_path, user_id, group_id, g_r, g_w) VALUES - ('/member', 101, 2, true, true); + (':0::1:', 101, 2, true, true); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-01-27 03:55:16
|
Revision: 198 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=198&view=rev Author: crazedsanity Date: 2011-01-27 03:55:10 +0000 (Thu, 27 Jan 2011) Log Message: ----------- Return the last SQL statement/query. /cs_phpDB.class.php: * get_last_query(): -- returns the last SQL statement from dbLayerObj (lastQuery var) /db_types/cs_phpDB__mysql.class.php: * MAIN::: -- lastQuery changed to public from protected /db_types/cs_phpDB__pgsql.class.php: * MAIN::: -- lastQuery changed to public from protected /db_types/cs_phpDB__sqlite.class.php: * MAIN::: -- lastQuery changed to public from protected Modified Paths: -------------- trunk/0.4/cs_phpDB.class.php trunk/0.4/db_types/cs_phpDB__mysql.class.php trunk/0.4/db_types/cs_phpDB__pgsql.class.php trunk/0.4/db_types/cs_phpDB__sqlite.class.php Modified: trunk/0.4/cs_phpDB.class.php =================================================================== --- trunk/0.4/cs_phpDB.class.php 2011-01-26 18:09:30 UTC (rev 197) +++ trunk/0.4/cs_phpDB.class.php 2011-01-27 03:55:10 UTC (rev 198) @@ -252,6 +252,14 @@ return($this->dbLayerObj->is_connected()); }//end is_connected() //========================================================================= + + + + //========================================================================= + public function get_last_query() { + return($this->dbLayerObj->lastQuery); + }//end get_last_query() + //========================================================================= } // end class phpDB ?> Modified: trunk/0.4/db_types/cs_phpDB__mysql.class.php =================================================================== --- trunk/0.4/db_types/cs_phpDB__mysql.class.php 2011-01-26 18:09:30 UTC (rev 197) +++ trunk/0.4/db_types/cs_phpDB__mysql.class.php 2011-01-27 03:55:10 UTC (rev 198) @@ -26,7 +26,7 @@ protected $inTrans = FALSE; /** Holds the last query performed. */ - protected $lastQuery = NULL; + public $lastQuery = NULL; /** List of queries that have been run */ protected $queryList=array(); Modified: trunk/0.4/db_types/cs_phpDB__pgsql.class.php =================================================================== --- trunk/0.4/db_types/cs_phpDB__pgsql.class.php 2011-01-26 18:09:30 UTC (rev 197) +++ trunk/0.4/db_types/cs_phpDB__pgsql.class.php 2011-01-27 03:55:10 UTC (rev 198) @@ -44,7 +44,7 @@ protected $inTrans = FALSE; /** Holds the last query performed. */ - protected $lastQuery = NULL; + public $lastQuery = NULL; /** List of queries that have been run */ protected $queryList=array(); Modified: trunk/0.4/db_types/cs_phpDB__sqlite.class.php =================================================================== --- trunk/0.4/db_types/cs_phpDB__sqlite.class.php 2011-01-26 18:09:30 UTC (rev 197) +++ trunk/0.4/db_types/cs_phpDB__sqlite.class.php 2011-01-27 03:55:10 UTC (rev 198) @@ -26,7 +26,7 @@ protected $inTrans = FALSE; /** Holds the last query performed. */ - protected $lastQuery = NULL; + public $lastQuery = NULL; /** List of queries that have been run */ protected $queryList=array(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-01-27 06:18:16
|
Revision: 201 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=201&view=rev Author: crazedsanity Date: 2011-01-27 06:18:09 +0000 (Thu, 27 Jan 2011) Log Message: ----------- permissions to allow id-paths; use dbTableHandler to make SQL easier. /cs_genericPermission.class.php: * MAIN::: -- changed objTable to permTable, from const to protected -- changed objSeq to permSeq, from const to protected -- objectDelimiter [NEW]: character to separate objects in a path. -- pathCleaner [NEW]: how to clean the path -- dbTableHandler [NEW]: object to create & retrieve data from the db. * __construct(): -- ARG CHANGE: NEW ARG: #2 ($objectDelimiter=NULL) -- ARG CHANGE: NEW ARG: #3 ($useUrlCleaner=true) -- set internal vars for objectDelimiter and useUrlCleaner -- setup internal var for dbTableHandler * build_permission_string(): -- added comment to explain what might otherwise seem illogical -- more helpful information in the event of an exception * create_permission(): -- minor column name changes (object_name to object_path) -- use dbTableHandler::create_record() instead of arbitrary SQL. * get_object() [DELETED]: -- unnecessary alias method * get_permission(): -- use dbTableHandler::get_single_record() instead of arbitrary SQL. * get_object_by_id() [DELETED]: -- unnecessary alias method * get_permission_by_id(): -- use dbTableHandler::get_record_by_id() instead of arbitrary SQL. * get_permission_list(): -- remove some commented-out code. /abstract/cs_genericGroup.abstract.class.php: * MAIN::: -- changed groupTable from constant to protected -- changed groupSeq from constant to protected -- dbTableHandler [NEW]: object to create & retrieve data from db. * __construct(): -- setup the dbTableHandler object. * create_group(): -- use dbTableHandler::create_record() instead of arbitrary SQL. * get_group(): -- use dbTableHandler::get_single_record() instead of arbitrary SQL. * get_group_by_id(): -- use dbTableHandler::get_record_by_id() instead of arbitrary SQL. /abstract/cs_genericUserGroup.abstract.class.php: * MAIN::: -- changed ugTable from constant to protected -- changed ugSeq from constant to protected -- dbTableHandler [NEW]: for table interaction * __construct(): -- set dbTableHandler object * create_user_group(): -- use dbTableHandler::create_record() * get_user_groups(): -- use dbTableHandler::get_records() * is_group_member(): -- fixed to work properly /setup/genericPermissions.pgsql.sql: * cswal_object_table: -- updated comment -- remove "is_hidden" column, unnecessary (and confusing) * INSERT STATEMENTS::: -- updated to match new schema. /tests/testOfCSGenericPermissions.php: * test_userGroups(): -- updated tests * test_permissions(): -- removed calls to deleted methods Modified Paths: -------------- trunk/0.4/abstract/cs_genericGroup.abstract.class.php trunk/0.4/abstract/cs_genericUserGroup.abstract.class.php trunk/0.4/cs_genericPermission.class.php trunk/0.4/setup/genericPermissions.pgsql.sql trunk/0.4/tests/testOfCSGenericPermissions.php Modified: trunk/0.4/abstract/cs_genericGroup.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_genericGroup.abstract.class.php 2011-01-27 05:04:56 UTC (rev 200) +++ trunk/0.4/abstract/cs_genericGroup.abstract.class.php 2011-01-27 06:18:09 UTC (rev 201) @@ -20,15 +20,25 @@ public $gfObj; /** Table name used to store groups. */ - const groupTable = "cswal_group_table"; + protected $groupTable = "cswal_group_table"; /** Sequence for groups table. */ - const groupSeq = "cswal_group_table_group_id_seq"; + protected $groupSeq = "cswal_group_table_group_id_seq"; + /** Table handler object for simple SQL handling */ + private $dbTableHandler; + //============================================================================ public function __construct(cs_phpDB $db) { $this->db = $db; $this->gfObj = new cs_globalFunctions; + + //setup table handler. + $cleanString = array( + 'group_name' => 'text', + 'group_admin' => 'integer' + ); + $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->groupTable, $this->groupSeq, 'group_id', $cleanString); }//end __construct() //============================================================================ @@ -51,9 +61,7 @@ //============================================================================ public function create_group($name) { try{ - $name = $this->clean_group_name($name); - $sql = "INSERT INTO ". self::groupTable ." (group_name) VALUES ('". $name ."')"; - $newId = $this->db->run_insert($sql, self::groupSeq); + $newId = $this->dbTableHandler->create_record(array('group_name'=>$this->clean_group_name($name))); } catch(Exception $e) { throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage()); @@ -68,9 +76,7 @@ //============================================================================ public function get_group($name) { try { - $name = $this->clean_group_name($name); - $sql = "SELECT * FROM ". self::groupTable ." WHERE group_name='". $name ."'"; - $retval = $this->db->run_query($sql); + $retval = $this->dbTableHandler->get_single_record(array('group_name' => $this->clean_group_name($name))); } catch(Exception $e) { throw new exception(__METHOD__ .":: error while locating group '". $name ."', DETAILS::: ". $e->getMessage()); @@ -85,8 +91,7 @@ //============================================================================ public function get_all_groups() { try { - $sql = "SELECT * FROM ". self::groupTable ." ORDER BY group_name"; - $retval = $this->db->run_query($sql); + $retval = $this->dbTableHandler->get_records(); } catch(Exception $e) { throw new exception(__METHOD__ .":: failed to retrieve groups, DETAILS::: ". $e->getMessage()); @@ -102,8 +107,7 @@ public function get_group_by_id($groupId) { try { if(!is_null($groupId) && is_numeric($groupId)) { - $sql = "SELECT * FROM ". self::groupTable ." WHERE group_id='". $groupId ."'"; - $retval = $this->db->run_query($sql); + $retval = $this->dbTableHandler->get_record_by_id($groupId); } else { throw new exception(__METHOD__ .":: invalid group ID (". $groupId .")"); Modified: trunk/0.4/abstract/cs_genericUserGroup.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_genericUserGroup.abstract.class.php 2011-01-27 05:04:56 UTC (rev 200) +++ trunk/0.4/abstract/cs_genericUserGroup.abstract.class.php 2011-01-27 06:18:09 UTC (rev 201) @@ -1,8 +1,6 @@ <?php /* - * Created on June 18, 2010 - * * FILE INFORMATION: * * $HeadURL$ @@ -15,14 +13,22 @@ abstract class cs_genericUserGroupAbstract extends cs_genericGroupAbstract { /** Table name used to store user_group records. */ - const ugTable = "cswal_user_group_table"; + protected $ugTable = "cswal_user_group_table"; /** Sequence for user_group table. */ - const ugSeq = "cswal_user_group_table_user_group_id_seq"; + protected $ugSeq = "cswal_user_group_table_user_group_id_seq"; + /** dbTableHandler{} object for simplifying SQL. */ + private $dbTableHandler; + //============================================================================ public function __construct(cs_phpDB $db) { parent::__construct($db); + $cleanString = array( + 'user_id' => 'integer', + 'group_id' => 'integer' + ); + $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->ugTable, $this->ugSeq, 'user_group_id', $cleanString); }//end __construct() //============================================================================ @@ -32,8 +38,7 @@ public function create_user_group($userId, $groupId) { if(is_numeric($userId) && is_numeric($groupId) && $userId >= 0 && $groupId >= 0) { try { - $sql = "INSERT INTO ". self::ugTable ." (user_id, group_id) VALUES (". $userId .", ". $groupId .")"; - $newId = $this->db->run_insert($sql, self::ugSeq); + $newId = $this->dbTableHandler->create_record(array('user_id'=>$userId,'group_id'=>$groupId)); } catch(Exception $e) { throw new exception(__METHOD__ .":: failed to create user group, DETAILS::: ". $e->getMessage()); @@ -52,9 +57,7 @@ public function get_user_groups($userId) { if(is_numeric($userId) && $userId >= 0) { try { - $sql = "SELECT ug.*, g.group_name, g.group_admin FROM ". self::ugTable ." AS ug INNER " - ."JOIN ". parent::groupTable ." as g USING (group_id) WHERE user_id=". $userId; - $retval = $this->db->run_query($sql, 'group_id'); + $retval = $this->dbTableHandler->get_records(array('user_id'=>$userId)); } catch(Exception $e) { throw new exception(__METHOD__ .":: failed to locate groups for user_id=(". $userId ."), DETAILS::: ". $e->getMessage()); @@ -73,8 +76,11 @@ public function is_group_member($userId, $groupId) { $groupList = $this->get_user_groups($userId); $retval = false; - if(isset($groupList[$groupId])) { - $retval = true; + if(is_array($groupList)) { + $keys = array_keys($groupList); + if($groupList[$keys[0]]['group_id'] == $groupId) { + $retval = true; + } } return($retval); }//end is_group_member() Modified: trunk/0.4/cs_genericPermission.class.php =================================================================== --- trunk/0.4/cs_genericPermission.class.php 2011-01-27 05:04:56 UTC (rev 200) +++ trunk/0.4/cs_genericPermission.class.php 2011-01-27 06:18:09 UTC (rev 201) @@ -20,19 +20,29 @@ public $gfObj; /** Table name used to store permissions. */ - const objTable = "cswal_object_table"; + protected $permTable = "cswal_permission_table"; /** Sequence for permissions table. */ - const objSeq = "cswal_object_table_object_id_seq"; + protected $permSeq = "cswal_permission_table_permission_id_seq"; /** List of valid keys... */ protected $keys = array(); + /** Determine object path pieces based on this... */ + protected $objectDelimiter="/"; + + /** How to clean the path (if at all); boolean true = use cs_globalFunctions::clean_url(); boolean false will + cause it to not be cleaned at all; a string will use cs_globalFunctions::cleanString({string})*/ + protected $pathCleaner=true; + + /** dbTableHandler{} object for easier SQL. */ + private $dbTableHandler; + //============================================================================ /** * Generic permission system based on *nix filesystem permissions. */ - public function __construct(cs_phpDB $db) { + public function __construct(cs_phpDB $db, $objectDelimiter=NULL, $useUrlCleaner=true) { $this->db = $db; parent::__construct($db); $this->gfObj = new cs_globalFunctions; @@ -47,6 +57,29 @@ 7 => 'o_w', 8 => 'o_x' ); + if(!is_null($objectDelimiter) && is_string($objectDelimiter) && strlen($objectDelimiter)) { + $this->objectDelimiter=$objectDelimiter; + } + if(is_bool($useUrlCleaner) || (is_string($useUrlCleaner) && strlen($useUrlCleaner))) { + $this->pathCleaner = $useUrlCleaner; + } + $cleanString = array( + 'system_name' => 'integer', + 'object_path' => 'text', + 'user_id' => 'integer', + 'group_id' => 'integer', + 'inherit' => 'bool', + 'u_r' => 'bool', + 'u_w' => 'bool', + 'u_x' => 'bool', + 'g_r' => 'bool', + 'g_w' => 'bool', + 'g_x' => 'bool', + 'o_r' => 'bool', + 'o_w' => 'bool', + 'o_x' => 'bool', + ); + $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->permTable, $this->permSeq, 'permission_id', $cleanString); }//end __construct() //============================================================================ @@ -98,6 +131,9 @@ */ protected function build_permission_string(array $perms) { $this->_sanityCheck(); + + //NOTE:: the incoming $perms must have more (or equal) items vs. $this->keys so that it can accept arrays with extra + // items, but can disregard those that obviously do not have enough. if(is_array($perms) && count($perms) >= count($this->keys)) { $retval = ""; foreach($this->keys as $dbColName) { @@ -118,7 +154,11 @@ } } else { - throw new exception(__METHOD__ .":: invalid permission set."); + $extraInfo=""; + if(!is_array($perms)) { + $extraInfo = " (expected array, received ". gettype($perms) ." '". $perms ."')"; + } + throw new exception(__METHOD__ .":: invalid permission set". $extraInfo); } return($retval); }//end build_permission_string(); @@ -144,7 +184,7 @@ public function create_permission($name, $userId, $groupId, $permString) { if(is_string($name) && strlen($name) && is_numeric($userId) && $userId >= 0 && is_numeric($groupId) && $groupId >= 0) { $cleanStringArr = array( - 'object_name' => 'sql', + 'object_path' => 'sql', 'user_id' => 'numeric', 'group_id' => 'numeric', 'u_r' => 'bool', @@ -159,13 +199,11 @@ ); try{ $insertArr = $this->parse_permission_string($permString); - $insertArr['object_name'] = $this->gfObj->cleanString($name, 'sql', 0); + $insertArr['object_path'] = $this->gfObj->cleanString($name, 'sql', 0); $insertArr['user_id'] = $userId; $insertArr['group_id'] = $groupId; - $insertSql = $this->gfObj->string_from_array($insertArr, 'insert', null, $cleanStringArr); - $sql = "INSERT INTO ". self::objTable ." ". $insertSql; - $newId = $this->db->run_insert($sql, self::objSeq); + $newId = $this->dbTableHandler->create_record($insertArr); } catch(Exception $e) { throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage()); @@ -183,24 +221,11 @@ //============================================================================ /** - * Same as get_permission(). - */ - public function get_object($name) { - return($this->get_permission($name)); - }//end get_object() - //============================================================================ - - - - //============================================================================ - /** * Retrieves a permission object by name from the database, exception on failure. */ public function get_permission($name) { try { - $name = $this->gfObj->cleanString($name, 'sql', 0); - $sql = "SELECT * FROM ". self::objTable ." WHERE object_name='". $name ."'"; - $retval = $this->db->run_query($sql); + $retval = $this->dbTableHandler->get_single_record(array('object_path'=>$name)); } catch(Exception $e) { throw new exception(__METHOD__ .":: error while locating permission '". $name ."', DETAILS::: ". $e->getMessage()); @@ -214,24 +239,12 @@ //============================================================================ /** - * Same as get_permission_by_id(). - */ - public function get_object_by_id($objectId) { - return($this->get_permission_by_id($objectId)); - }//end get_object_by_id() - //============================================================================ - - - - //============================================================================ - /** * Retrieves a permission object from the database based on an ID. */ public function get_permission_by_id($permId) { try { if(!is_null($permId) && is_numeric($permId)) { - $sql = "SELECT * FROM ". self::objTable ." WHERE object_id='". $permId ."'"; - $retval = $this->db->run_query($sql); + $retval = $this->dbTableHandler->get_record_by_id($permId); } else { throw new exception(__METHOD__ .":: invalid permission ID (". $permId .")"); @@ -298,7 +311,6 @@ if(preg_match('/'. $type .'_[rwx]$/',$myKey)) { //chop the last character off (i.e. 'r' from 'u_r') $myPermChar = substr($myKey, -1); - #$retval[$myPermChar] = $this->gfObj->interpret_bool($permData[$myKey], array('f', 't')); $retval[$myPermChar] = $this->evaluate_perm_value($permData[$myKey], $type); } } Modified: trunk/0.4/setup/genericPermissions.pgsql.sql =================================================================== --- trunk/0.4/setup/genericPermissions.pgsql.sql 2011-01-27 05:04:56 UTC (rev 200) +++ trunk/0.4/setup/genericPermissions.pgsql.sql 2011-01-27 06:18:09 UTC (rev 201) @@ -40,13 +40,11 @@ -- -- Object table -- Unique set of names which should be chained together to create an object path; for a URL of "/member/blog/edit", the pieces would be created --- with ID's, such as "member"=1, "blog"=2, "edit"=3; the object path would then be ":1::2::3:"; an extra prefix element might be created to --- define a default, inheritable set of permissions, such as "{root}"=10; the path might then be ":10::1::2::3:". +-- with ID's, such as "member"=1, "blog"=2, "edit"=3; the object path would then be ":1::2::3:". -- CREATE TABLE cswal_object_table ( object_id integer NOT NULL PRIMARY KEY, object_name text NOT NULL UNIQUE, - is_hidden boolean NOT NULL DEFAULT FALSE, created TIMESTAMPTZ NOT NULL DEFAULT NOW() ); @@ -84,8 +82,8 @@ INSERT INTO cswal_group_table (group_name) VALUES ('blogs'); INSERT INTO cswal_group_table (group_name) VALUES ('admin'); -INSERT INTO cswal_object_table (object_id, object_name,is_hidden) VALUES (0, '/', true); -INSERT INTO cswal_object_table (object_id, object_name,is_hidden) VALUES (1, 'member', false); +INSERT INTO cswal_object_table (object_id, object_name) VALUES (0, '{APPURL}'); +INSERT INTO cswal_object_table (object_id, object_name) VALUES (1, 'member'); INSERT INTO cswal_permission_table (object_path,user_id, group_id) Modified: trunk/0.4/tests/testOfCSGenericPermissions.php =================================================================== --- trunk/0.4/tests/testOfCSGenericPermissions.php 2011-01-27 05:04:56 UTC (rev 200) +++ trunk/0.4/tests/testOfCSGenericPermissions.php 2011-01-27 06:18:09 UTC (rev 201) @@ -89,9 +89,9 @@ $groupList = $this->permObj->get_all_groups(); - foreach($groupList as $groupData) { - $this->assertEqual($this->permObj->get_group_by_id($groupData['group_id']), $groupData); - $this->assertEqual($this->permObj->get_group($groupData['group_name']), $groupData); + foreach($groupList as $groupId=>$groupData) { + $this->assertEqual($this->permObj->get_group_by_id($groupId), $groupData, "failed to get group (". $groupData['group_name'] .") by ID (". $groupId .")"); + $this->assertEqual($this->permObj->get_group($groupData['group_name']), $groupData, "failed to get group (". $groupData['group_name'] .") by name"); } } @@ -100,8 +100,7 @@ $newId = $this->permObj->create_user_group($this->validUsers[$myKey]['uid'],$newGroupId); $this->assertTrue(is_numeric($newId)); $this->assertTrue($this->permObj->is_group_member($this->validUsers[$myKey]['uid'],$newGroupId), "user (". - $this->validUsers[$myKey]['uid'] .") isn't member of group (". $newGroupId .") after ". - "being added to it... "); + $this->validUsers[$myKey]['uid'] .") isn't member of group (". $newGroupId .") after being added to it... "); $ugList = $this->permObj->get_user_groups($this->validUsers[$myKey]['uid']); $this->assertTrue(is_array($ugList)); @@ -175,9 +174,7 @@ //the method 'build_permissions_string()' should disregard extra indices in the array & build the string. $this->assertEqual($this->permObj->make_perm_string($this->permObj->get_permission_by_id($permId)), $usePermString); - $this->assertEqual($this->permObj->make_perm_string($this->permObj->get_object_by_id($permId)), $usePermString); $this->assertEqual($this->permObj->make_perm_string($this->permObj->get_permission($usePermName)), $usePermString); - $this->assertEqual($this->permObj->make_perm_string($this->permObj->get_object($usePermName)), $usePermString); //check to make sure individual permission requests work as expected. $this->assertTrue($this->permObj->has_read_permission($myUid, $usePermName)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-01-27 15:04:30
|
Revision: 203 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=203&view=rev Author: crazedsanity Date: 2011-01-27 15:04:24 +0000 (Thu, 27 Jan 2011) Log Message: ----------- Fix naming of cs_genericObject, cs_genericPermission now extends it. Modified Paths: -------------- trunk/0.4/cs_genericPermission.class.php Added Paths: ----------- trunk/0.4/abstract/cs_genericObject.abstract.class.php Removed Paths: ------------- trunk/0.4/abstract/cs_genericObject.class.php Copied: trunk/0.4/abstract/cs_genericObject.abstract.class.php (from rev 202, trunk/0.4/abstract/cs_genericObject.class.php) =================================================================== --- trunk/0.4/abstract/cs_genericObject.abstract.class.php (rev 0) +++ trunk/0.4/abstract/cs_genericObject.abstract.class.php 2011-01-27 15:04:24 UTC (rev 203) @@ -0,0 +1,92 @@ +<?php + +/* + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +abstract class cs_genericObjectAbstract extends cs_genericUserGroupAbstract { + + /** Table name used to store object records. */ + protected $oTable = "cswal_object_table"; + + /** Sequence for object table. */ + protected $oSeq = "cswal_object_table_object_id_seq"; + + /** dbTableHandler{} object for simplifying SQL. */ + private $dbTableHandler; + + //============================================================================ + public function __construct(cs_phpDB $db) { + parent::__construct($db); + $cleanString = array( + 'object_name' => 'text' + ); + $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->oTable, $this->oSeq, 'group_id', $cleanString); + }//end __construct() + //============================================================================ + + + + //============================================================================ + public function create_object($objectName) { + if(strlen($objectName)) { + $newId = $this->dbTableHandler->create_record(array('object_name', $objectName)); + } + else { + throw new exception(__METHOD__ .": invalid object name (". $objectName .")"); + } + return($newId); + }//end create_object() + //============================================================================ + + + + //============================================================================ + public function get_object_by_name($objectName) { + if(strlen($objectName)) { + try { + $retval = $this->dbTableHandler->get_single_record(array('object_name'=>$objectName)); + } + catch(Exception $e) { + throw new exception(__METHOD__ .":: failed to object from name=(". $objectName ."), DETAILS::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .":: invalid object name (". $objectName .")"); + } + return($retval); + }//end get_object_by_name() + //============================================================================ + + + + //============================================================================ + public function get_object_by_id($objectId) { + if(strlen($objectName)) { + try { + $retval = $this->dbTableHandler->get_record_by_id($objectId); + } + catch(Exception $e) { + throw new exception(__METHOD__ .":: failed to object for ID=(". $objectId ."), DETAILS::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .":: invalid object ID (". $objectId .")"); + } + return($retval); + }//end get_object_by_id() + //============================================================================ + + + + //============================================================================ + //============================================================================ + +} +?> Deleted: trunk/0.4/abstract/cs_genericObject.class.php =================================================================== --- trunk/0.4/abstract/cs_genericObject.class.php 2011-01-27 14:53:53 UTC (rev 202) +++ trunk/0.4/abstract/cs_genericObject.class.php 2011-01-27 15:04:24 UTC (rev 203) @@ -1,92 +0,0 @@ -<?php - -/* - * FILE INFORMATION: - * - * $HeadURL$ - * $Id$ - * $LastChangedDate$ - * $LastChangedBy$ - * $LastChangedRevision$ - */ - -abstract class cs_genericObject extends cs_genericUserGroupAbstract { - - /** Table name used to store object records. */ - protected $oTable = "cswal_object_table"; - - /** Sequence for object table. */ - protected $oSeq = "cswal_object_table_object_id_seq"; - - /** dbTableHandler{} object for simplifying SQL. */ - private $dbTableHandler; - - //============================================================================ - public function __construct(cs_phpDB $db) { - parent::__construct($db); - $cleanString = array( - 'object_name' => 'text' - ); - $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->oTable, $this->oSeq, 'group_id', $cleanString); - }//end __construct() - //============================================================================ - - - - //============================================================================ - public function create_object($objectName) { - if(strlen($objectName)) { - $newId = $this->dbTableHandler->create_record(array('object_name', $objectName)); - } - else { - throw new exception(__METHOD__ .": invalid object name (". $objectName .")"); - } - return($newId); - }//end create_object() - //============================================================================ - - - - //============================================================================ - public function get_object_by_name($objectName) { - if(strlen($objectName)) { - try { - $retval = $this->dbTableHandler->get_single_record(array('object_name'=>$objectName)); - } - catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to object from name=(". $objectName ."), DETAILS::: ". $e->getMessage()); - } - } - else { - throw new exception(__METHOD__ .":: invalid object name (". $objectName .")"); - } - return($retval); - }//end get_object_by_name() - //============================================================================ - - - - //============================================================================ - public function get_object_by_id($objectId) { - if(strlen($objectName)) { - try { - $retval = $this->dbTableHandler->get_record_by_id($objectId); - } - catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to object for ID=(". $objectId ."), DETAILS::: ". $e->getMessage()); - } - } - else { - throw new exception(__METHOD__ .":: invalid object ID (". $objectId .")"); - } - return($retval); - }//end get_object_by_id() - //============================================================================ - - - - //============================================================================ - //============================================================================ - -} -?> Modified: trunk/0.4/cs_genericPermission.class.php =================================================================== --- trunk/0.4/cs_genericPermission.class.php 2011-01-27 14:53:53 UTC (rev 202) +++ trunk/0.4/cs_genericPermission.class.php 2011-01-27 15:04:24 UTC (rev 203) @@ -11,7 +11,7 @@ * $LastChangedRevision$ */ -class cs_genericPermission extends cs_genericUserGroupAbstract { +class cs_genericPermission extends cs_genericObjectAbstract { /** Database object. */ public $db; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-02-01 03:29:28
|
Revision: 204 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=204&view=rev Author: crazedsanity Date: 2011-02-01 03:29:22 +0000 (Tue, 01 Feb 2011) Log Message: ----------- Use ID paths instead of string-based paths. /cs_genericPermission.class.php: * __construct(): -- change "object_path" to use the "email_plus" style of string cleaning (there should really be a more extensible way of using that) * create_object() [DELETED]: -- unnecessary alias method * create_permission(): -- call create_id_path() to set the value for 'object_path'. -- throw an exception if creating the ID path fails. -- NOTE::: the new exception is caught by the outer exception, which will not display those details... * get_permission(): -- create an ID path to find the object. -- translates the ID path into an actual path. * explode_path(): -- separates the given real path into bits so that it can be turned into an ID path * create_id_path(): -- creates the ID path for a given normal path. /abstract/cs_genericGroup.abstract.class.php: * __construct(): -- 'group_name' gets cleaned like email * create_group(): -- ARG CHANGE: NEW ARG: #2 ($adminUid) -- requires the admin's UID when creating the record. /abstract/cs_genericObject.abstract.class.php: * __construct(): -- change cleaning of object_name from text to sql * create_object(): -- catch exception if create_record() throws one * get_object_ids() [NEW]: -- build an array of object ID's based on the given names * create_id_path_part() [NEW]: -- basically surrounds the given number with colons (i.e. '2' -> ':2:') * create_id_path_from_objects() [NEW]: -- creates an ID path from an array of object names. * clean_object_name() [NEW]: -- special cleaning so the colons don't get stripped. * is_id_path() [NEW]: -- determines if the given string is an ID path or not * explode_id_path() [NEW]: -- breaks up an ID path into IDs * get_object_names() [NEW]: -- retrieves a list of names associated with the id's in the passed array. Modified Paths: -------------- trunk/0.4/abstract/cs_genericGroup.abstract.class.php trunk/0.4/abstract/cs_genericObject.abstract.class.php trunk/0.4/cs_genericPermission.class.php Modified: trunk/0.4/abstract/cs_genericGroup.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_genericGroup.abstract.class.php 2011-01-27 15:04:24 UTC (rev 203) +++ trunk/0.4/abstract/cs_genericGroup.abstract.class.php 2011-02-01 03:29:22 UTC (rev 204) @@ -35,7 +35,7 @@ //setup table handler. $cleanString = array( - 'group_name' => 'text', + 'group_name' => 'email', 'group_admin' => 'integer' ); $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->groupTable, $this->groupSeq, 'group_id', $cleanString); @@ -59,9 +59,13 @@ //============================================================================ - public function create_group($name) { + public function create_group($name, $adminUid) { try{ - $newId = $this->dbTableHandler->create_record(array('group_name'=>$this->clean_group_name($name))); + $insertData = array( + 'group_name' => $this->clean_group_name($name), + 'group_admin' => $adminUid + ); + $newId = $this->dbTableHandler->create_record($insertData); } catch(Exception $e) { throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage()); Modified: trunk/0.4/abstract/cs_genericObject.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_genericObject.abstract.class.php 2011-01-27 15:04:24 UTC (rev 203) +++ trunk/0.4/abstract/cs_genericObject.abstract.class.php 2011-02-01 03:29:22 UTC (rev 204) @@ -25,7 +25,7 @@ public function __construct(cs_phpDB $db) { parent::__construct($db); $cleanString = array( - 'object_name' => 'text' + 'object_name' => 'sql' ); $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->oTable, $this->oSeq, 'group_id', $cleanString); }//end __construct() @@ -36,7 +36,12 @@ //============================================================================ public function create_object($objectName) { if(strlen($objectName)) { - $newId = $this->dbTableHandler->create_record(array('object_name', $objectName)); + try { + $newId = $this->dbTableHandler->create_record(array('object_name' => $objectName)); + } + catch(Exception $e) { + throw new exception(__METHOD__ .": failed to create object, DETAILS::: ". $e->getMessage()); + } } else { throw new exception(__METHOD__ .": invalid object name (". $objectName .")"); @@ -86,7 +91,189 @@ //============================================================================ + public function get_object_ids(array $objectNames, $createMissing=true) { + $nvpArray = array(); + if(is_array($objectNames) && count($objectNames)) { + $sql = "SELECT object_id, object_name FROM ". $this->oTable ." WHERE " + . "object_name IN "; + + $myFilter = ""; + foreach($objectNames as $n) { + $tString = "'". $this->clean_object_name($n) ."'"; + $myFilter = $this->gfObj->create_list($myFilter, $tString); + } + $sql .= '('. $myFilter .')'; + + try { + $nvpArray = $this->dbTableHandler->dbObj->run_query($sql, 'object_id', 'object_name'); + } + catch(Exception $e) { + throw new exception(__METHOD__ .": failed to retrieve object list, DETAILS::: ". $e->getMessage()); + } + + try { + if($createMissing === true) { + //clean object names... + foreach($objectNames as $i=>$n) { + $objectNames[$i] = $this->clean_object_name($n); + } + //pull the missing indexes out so they can be created... + if(!is_array($nvpArray)) { + $nvpArray = array(); + } + $missingIndexes = array_diff($objectNames, $nvpArray); + + if(count($missingIndexes)) { +$this->gfObj->debug_print(__METHOD__ .": MISSING INDEXES::: ". $this->gfObj->debug_print($missingIndexes,0,1)); + foreach($missingIndexes as $newObjectName) { + $newId = $this->create_object($newObjectName); + $nvpArray[$newId] = $newObjectName; + } + } +$this->gfObj->debug_print(__METHOD__ .": createMissing=(". $createMissing ."), counts=(". count($objectNames) ."/". count($nvpArray) ."/". count($missingIndexes)."), SQL::: ". $sql); + } + if(!is_array($nvpArray) || !count($nvpArray)) { +$this->gfObj->debug_print(__METHOD__ .": objectNames::: ". $this->gfObj->debug_print($objectNames,0,1)); +$this->gfObj->debug_print(__METHOD__ .": nvpArray::: ". $this->gfObj->debug_print($nvpArray,0,1)); +$this->gfObj->debug_print(__METHOD__ .": missingIndexes::: ". $this->gfObj->debug_print($missingIndexes,0,1)); +cs_debug_backtrace(1); + throw new exception(__METHOD__ .": no data returned"); + } + } + catch(Exception $e) { + throw new exception(__METHOD__ .": error while creating missing objects, DETAILS::: ". $e->getMessage()); + } + } + return($nvpArray); + }//end get_object_ids() //============================================================================ + + + //============================================================================ + public function create_id_path_part($id) { + if(is_numeric($id)) { + $retval = ':'. $id .':'; + } + else { + throw new exception(__METHOD__ .": invalid id (". $id .")"); + } + return($retval); + }//end create_id_path_part() + //============================================================================ + + + + //============================================================================ + public function create_id_path_from_objects(array $objects) { + try { + $myIds = $this->get_object_ids($objects,true); + + $idPath = ""; + if(is_array($myIds) && count($myIds)) { + foreach($myIds as $id=>$name) { + try { + $idPath = $this->gfObj->create_list($idPath, $this->create_id_path_part($id), ''); + } + catch(Exception $e) { + throw new exception($e->getMessage()); + } + } + } + else { + throw new exception(__METHOD__ .": failed to create any IDs"); + } + } + catch(Exception $e) { + throw new exception(__METHOD__ .": failed to create id path, DETAILS::: ". $e->getMessage()); + } + return($idPath); + }//end create_id_path_from_objects() + //============================================================================ + + + + //============================================================================ + protected function clean_object_name($n) { + //pulled from cs-content, cs_globalFunctions::cleanString(), style="query"; modified to allow the brackets. + $evilChars = array("\$", ":", "%", "~", "*",">", "<", "-", "[", "]", ")", "(", "&", "#", "?", ".", "\,","\/","\\","\"","\|","!","^","+","`","\n","\r"); + $n = preg_replace("/\|/","",$n); + $n = preg_replace("/\'/", "", $n); + $n = str_replace($evilChars,"", $n); + $n = stripslashes(addslashes($n)); + + return($n); + }//end clean_object_name($n) + //============================================================================ + + + + //============================================================================ + public function is_id_path($path) { + $isPath = false; + if(is_string($path) && strlen($path)) { + if(preg_match('/^(:-{0,1}[0-9]{1,}:){1,}$/', $path)) { + $isPath = true; + } + } + return($isPath); + }//end is_id_path() + //============================================================================ + + + + //============================================================================ + public function explode_id_path($idPath) { + //make the expected string into something that be broken into an array of numbers. + $chunktify = preg_replace('/^:(.*):$/', '$1', $idPath); + $chunktify = preg_replace('/:{2,}/', ':', $chunktify); + $bits = explode(':', $chunktify); + return($bits); + }//end explode_id_path() + //============================================================================ + + + + //============================================================================ + public function translate_id_path($idPath) { + if($this->is_id_path($idPath)) { + $bits = $this->explode_id_path($idPath); + $translatedPath = $this->get_object_names($this->explode_id_path($idPath)); + } + else { + throw new exception(__METHOD__ .": invalid path (". $idPath .")"); + } + return($translatedPath); + }//end translate_id_path() + //============================================================================ + + + + //============================================================================ + public function get_object_names(array $idList) { + if(is_array($idList) && count($idList)) { + $sql = "SELECT object_id, object_name FROM ". $this->oTable ." WHERE object_id IN "; + + $idListString = ""; + foreach($idList as $id) { + $idListString = $this->gfObj->create_list($idListString, $id, ", "); + } + $sql .= "(". $idListString .")"; + + //run it. + try { + $objectNames = $this->dbTableHandler->dbObj->run_query($sql, 'object_id', 'object_name'); + } + catch(Exception $e) { + throw new exception(__METHOD__ .": error while retrieving object names, DETAILS::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .": invalid data type (". gettype($idList) .") or empty array"); + } + return($objectNames); + }//end get_object_names() + //============================================================================ + } ?> Modified: trunk/0.4/cs_genericPermission.class.php =================================================================== --- trunk/0.4/cs_genericPermission.class.php 2011-01-27 15:04:24 UTC (rev 203) +++ trunk/0.4/cs_genericPermission.class.php 2011-02-01 03:29:22 UTC (rev 204) @@ -36,7 +36,7 @@ protected $pathCleaner=true; /** dbTableHandler{} object for easier SQL. */ - private $dbTableHandler; + protected $dbTableHandler; //============================================================================ /** @@ -65,7 +65,7 @@ } $cleanString = array( 'system_name' => 'integer', - 'object_path' => 'text', + 'object_path' => 'email_plus', 'user_id' => 'integer', 'group_id' => 'integer', 'inherit' => 'bool', @@ -167,46 +167,21 @@ //============================================================================ - /** - * Same as create_permission(). - */ - public function create_object($name, $userId, $groupId, $permString) { - return($this->create_permission($name, $userId, $groupId, $permString)); - }//end create_object() - //============================================================================ - - - - //============================================================================ /** * Creates a permission object record. */ public function create_permission($name, $userId, $groupId, $permString) { if(is_string($name) && strlen($name) && is_numeric($userId) && $userId >= 0 && is_numeric($groupId) && $groupId >= 0) { - $cleanStringArr = array( - 'object_path' => 'sql', - 'user_id' => 'numeric', - 'group_id' => 'numeric', - 'u_r' => 'bool', - 'u_w' => 'bool', - 'u_x' => 'bool', - 'g_r' => 'bool', - 'g_w' => 'bool', - 'g_x' => 'bool', - 'o_r' => 'bool', - 'o_w' => 'bool', - 'o_x' => 'bool' - ); try{ $insertArr = $this->parse_permission_string($permString); - $insertArr['object_path'] = $this->gfObj->cleanString($name, 'sql', 0); + $insertArr['object_path'] = $this->create_id_path($name); $insertArr['user_id'] = $userId; $insertArr['group_id'] = $groupId; $newId = $this->dbTableHandler->create_record($insertArr); } catch(Exception $e) { - throw new exception(__METHOD__ .":: failed to create new record, DETAILS::: ". $e->getMessage()); + throw new exception(__METHOD__ .":: failed to create new record, name=(". $name ."), permString=(". $permString .") DETAILS::: ". $e->getMessage()); } } else { @@ -225,7 +200,14 @@ */ public function get_permission($name) { try { + if(!$this->is_id_path($name)) { + $name = $this->create_id_path($name); + } $retval = $this->dbTableHandler->get_single_record(array('object_path'=>$name)); + + //now translate the object_path... + // TODO: this could be a resource hog if called in rapid succession; consider creating an object cache or whatnot + $retval['translated_path'] = $this->translate_id_path($retval['object_path']); } catch(Exception $e) { throw new exception(__METHOD__ .":: error while locating permission '". $name ."', DETAILS::: ". $e->getMessage()); @@ -265,6 +247,9 @@ * Check available permissions... */ public function check_permission($objectName, $userId) { + if(!$this->is_id_path($objectName)) { + $objectName = $this->create_id_path($objectName,false); + } $availablePerms = array( 'r' => false, 'w' => false, @@ -410,5 +395,38 @@ return($retval); }//end has_execute_permission() //============================================================================ + + + + //============================================================================ + public function explode_path($path) { + if(is_string($path) && strlen($path)) { + $path = preg_replace('/^'. addcslashes($this->objectDelimiter, '/') .'/', '', $path); + $path = preg_replace('/'. addcslashes($this->objectDelimiter, '/') .'{2,}/', $this->objectDelimiter, $path); + $bits = explode($this->objectDelimiter, $path); + } + else { + throw new exception(__METHOD__ .": invalid path (". $path .")"); + } + return($bits); + }//end explode_path() + //============================================================================ + + + + //============================================================================ + public function create_id_path($path) { + //Get the list of objects from the path. + $bits = $this->explode_path($path); + + //now create the path. + $newPath = $this->create_id_path_from_objects($bits); + if(!$this->is_id_path($newPath)) { + throw new exception(__METHOD__ .": failed to create ID path from (". $path .")"); + } + + return($newPath); + }//end create_id_path() + //============================================================================ } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-02-01 03:51:44
|
Revision: 205 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=205&view=rev Author: crazedsanity Date: 2011-02-01 03:51:37 +0000 (Tue, 01 Feb 2011) Log Message: ----------- Updated tests & schema. /setup/genericPermissions.pgsql.sql: * cswal_group_table: -- group_admin: changed to NOT NULL * cswal_object_table: -- object_id: changed to serial (instead of integer) * cswal_permission_table: -- object_path: removed UNIQUE constraint * MAIN... -- remove arbitrary INSERT statements -- add a constraint to the cswal_permission_table /tests/testOfCSGenericPermissions.php: * setUp(): -- supplement all the arbitrary insertsfrom the setup file with code before each run... * get_valid_users(): -- set some internal vars for later testing. * test_userGroups(): -- more tests... * test_object_paths() [NEW]: -- testing creation & manipulation of ID and object paths * test_permissions(): -- build a larger list of permissions for testing * _gpTester{}: -- create testDbTableHandler object for SQL stuff. Modified Paths: -------------- trunk/0.4/setup/genericPermissions.pgsql.sql trunk/0.4/tests/testOfCSGenericPermissions.php Modified: trunk/0.4/setup/genericPermissions.pgsql.sql =================================================================== --- trunk/0.4/setup/genericPermissions.pgsql.sql 2011-02-01 03:29:22 UTC (rev 204) +++ trunk/0.4/setup/genericPermissions.pgsql.sql 2011-02-01 03:51:37 UTC (rev 205) @@ -6,7 +6,7 @@ CREATE TABLE cswal_group_table ( group_id serial NOT NULL PRIMARY KEY, group_name text NOT NULL UNIQUE, - group_admin integer REFERENCES cs_authentication_table(uid), + group_admin integer NOT NULL REFERENCES cs_authentication_table(uid), created TIMESTAMPTZ NOT NULL DEFAULT NOW() ); @@ -43,7 +43,7 @@ -- with ID's, such as "member"=1, "blog"=2, "edit"=3; the object path would then be ":1::2::3:". -- CREATE TABLE cswal_object_table ( - object_id integer NOT NULL PRIMARY KEY, + object_id serial NOT NULL PRIMARY KEY, object_name text NOT NULL UNIQUE, created TIMESTAMPTZ NOT NULL DEFAULT NOW() ); @@ -60,7 +60,7 @@ CREATE TABLE cswal_permission_table ( permission_id serial NOT NULL PRIMARY KEY, system_name integer NOT NULL DEFAULT 0 REFERENCES cswal_system_table(system_id), - object_path text NOT NULL UNIQUE, + object_path text NOT NULL, user_id integer NOT NULL REFERENCES cs_authentication_table(uid), group_id integer NOT NULL REFERENCES cswal_group_table(group_id), inherit boolean NOT NULL DEFAULT FALSE, @@ -78,20 +78,6 @@ INSERT INTO cswal_system_table (system_id, system_name) VALUES (0, 'DEFAULT'); -INSERT INTO cswal_group_table (group_name) VALUES ('www'); -INSERT INTO cswal_group_table (group_name) VALUES ('blogs'); -INSERT INTO cswal_group_table (group_name) VALUES ('admin'); +ALTER TABLE ONLY cswal_permission_table + ADD CONSTRAINT cswal_permission_table_system_path_key UNIQUE (system_name, object_path); -INSERT INTO cswal_object_table (object_id, object_name) VALUES (0, '{APPURL}'); -INSERT INTO cswal_object_table (object_id, object_name) VALUES (1, 'member'); - -INSERT INTO cswal_permission_table - (object_path,user_id, group_id) - VALUES - (':0:', 101, 1); - -INSERT INTO cswal_permission_table - (object_path, user_id, group_id, g_r, g_w) - VALUES - (':0::1:', 101, 2, true, true); - Modified: trunk/0.4/tests/testOfCSGenericPermissions.php =================================================================== --- trunk/0.4/tests/testOfCSGenericPermissions.php 2011-02-01 03:29:22 UTC (rev 204) +++ trunk/0.4/tests/testOfCSGenericPermissions.php 2011-02-01 03:51:37 UTC (rev 205) @@ -29,6 +29,39 @@ $this->permObj = new _gpTester($this->db); $this->permObj->do_schema(); $this->get_valid_users(); + + $this->defaultGroupId = null; + + //create some groups. + { + $myGroupList = array('www', 'blogs', 'admin', __METHOD__); + #$newGroupId = $this->permObj->create_group(__METHOD__); + $userKeys = array_keys($this->validUsers); + foreach($myGroupList as $tName) { + $newGroupId = $this->permObj->create_group($tName, $this->chosenOneUid); + if(is_null($this->defaultGroupId)) { + $this->defaultGroupId = $newGroupId; + } + $this->assertTrue(is_numeric($newGroupId)); + } + + $groupList = $this->permObj->get_all_groups(); + + foreach($groupList as $groupId=>$groupData) { + $this->assertEqual($this->permObj->get_group_by_id($groupId), $groupData, "failed to get group (". $groupData['group_name'] .") by ID (". $groupId .")"); + $this->assertEqual($this->permObj->get_group($groupData['group_name']), $groupData, "failed to get group (". $groupData['group_name'] .") by name"); + } + } + + //create some objects... + { + $requiredItems = array('{APPURL}', 'member'); + foreach($requiredItems as $name) { + $newId = $this->permObj->create_object($name); + $this->assertTrue(is_numeric($newId)); + } + } + }//end setUp() //-------------------------------------------------------------------------- @@ -55,6 +88,11 @@ $sql = "SELECT uid,username FROM cs_authentication_table ORDER BY uid"; try { $this->validUsers = $this->db->run_query($sql); + + $userKeys = array_keys($this->validUsers); + $myUser = $this->validUsers[$userKeys[0]]; + $this->chosenOneUid = $myUser['uid']; + $this->defaultUid = $this->chosenOneUid; } catch(Exception $e) { cs_debug_backtrace(1); @@ -82,25 +120,12 @@ $this->assertTrue(isset($groupList[$myKey]['group_id'])); } - //create some groups. - { - $newGroupId = $this->permObj->create_group(__METHOD__); - $this->assertTrue(is_numeric($newGroupId)); - - $groupList = $this->permObj->get_all_groups(); - - foreach($groupList as $groupId=>$groupData) { - $this->assertEqual($this->permObj->get_group_by_id($groupId), $groupData, "failed to get group (". $groupData['group_name'] .") by ID (". $groupId .")"); - $this->assertEqual($this->permObj->get_group($groupData['group_name']), $groupData, "failed to get group (". $groupData['group_name'] .") by name"); - } - } - //create & test user_group relationships. { - $newId = $this->permObj->create_user_group($this->validUsers[$myKey]['uid'],$newGroupId); + $newId = $this->permObj->create_user_group($this->validUsers[$myKey]['uid'],$this->defaultGroupId); $this->assertTrue(is_numeric($newId)); - $this->assertTrue($this->permObj->is_group_member($this->validUsers[$myKey]['uid'],$newGroupId), "user (". - $this->validUsers[$myKey]['uid'] .") isn't member of group (". $newGroupId .") after being added to it... "); + $this->assertTrue($this->permObj->is_group_member($this->validUsers[$myKey]['uid'],$this->defaultGroupId), "user (". + $this->validUsers[$myKey]['uid'] .") isn't member of group (". $this->defaultGroupId .") after being added to it... "); $ugList = $this->permObj->get_user_groups($this->validUsers[$myKey]['uid']); $this->assertTrue(is_array($ugList)); @@ -113,7 +138,73 @@ //-------------------------------------------------------------------------- + public function test_object_paths() { + //basic functionality test for ID Path creation. + { + $expectThis = ':5::30::2::18::5:'; + + //make the expected string into something that be broken into an array of numbers. + $chunktify = preg_replace('/^:(.*):$/', '$1', $expectThis); + $chunktify = preg_replace('/:{2,}/', ':', $chunktify); + $bits = explode(':', $chunktify); + + $this->assertEqual($bits, $this->permObj->explode_id_path($expectThis)); + + $this->assertEqual(count($bits), 5, 'could not break string into id bits'); + + $derivedIdPath = ""; + foreach($bits as $id) { + $derivedIdPath .= $this->permObj->create_id_path_part($id); + } + $this->assertEqual($derivedIdPath, $expectThis, 'Invalid idPath, expected=('. $expectThis .'), actual=('. $derivedIdPath .')'); + + $idPathList = array(':9:', ':9::5:', ':0::0::0:', ':-1:', ':-1::-1:', ':-400::1::3:', ':51041::600000::8109223::999999999999999999999999999999999:'); + foreach($idPathList as $tPath) { + $this->assertTrue($this->permObj->is_id_path($tPath), "valid path (". $tPath .") not recognized as such"); + } + + $invalidIdPathList = array('', ':--1:', '1::3::4:', ':1::3::4', ':1:3:4:'); + foreach($invalidIdPathList as $tPath) { + $this->assertFalse($this->permObj->is_id_path($tPath), "invalid path (". $tPath .") evaluated as valid"); + } + } + + //Search for existing items (should have been created from setUp()) + { + $requiredItems = array('{APPURL}', 'member'); + $existingItems = $this->permObj->get_object_ids($requiredItems, false); + $this->assertEqual(count($existingItems), 2, 'Required items not present... '. $this->gfObj->debug_print($existingItems,0,1)); + + //in the event the required items aren't there, create them. + $testExistingItems = $this->permObj->get_object_ids($requiredItems, true); + $this->assertEqual(count($requiredItems), count($testExistingItems), 'failed to create some existing items'); + $this->assertEqual(count($testExistingItems), count($existingItems), 'WARNING: some required items were not found'); + } + + //Build new ID paths... + { + $newObjects = array('admin', 'logs', 'view'); + $idPath = $this->permObj->create_id_path('/admin/logs/view'); + $this->assertTrue(preg_match('/^:[0-9]{1,}::[0-9]{1,}::[0-9]{1,}:/', $idPath), 'path appears syntactically incorrect ('. $idPath .')'); + + //make sure the manually-created ID Path matches what was actually created. + $idList = $this->permObj->get_object_ids($newObjects, false); + $this->assertEqual(count($idList), count($newObjects), "there must be missing objects, counts don't match"); + + $expectedIdPath = ""; + foreach($idList as $id=>$n) { + $expectedIdPath .= $this->permObj->create_id_path_part($id); + } + $this->assertEqual($expectedIdPath, $idPath, "Manually created path (". $expectedIdPath .") does not match idPath (". $idPath .")"); + } + }//end test_object_paths() + //-------------------------------------------------------------------------- + + + + //-------------------------------------------------------------------------- public function test_permissions() { + #$GLOBALS['keepDb'] = true; //Test permission string parsing. { @@ -169,7 +260,9 @@ $usePermName = __METHOD__ .'/test1'; $this->assertFalse($this->permObj->permission_exists($usePermName)); $permId = $this->permObj->create_permission($usePermName, $myUid, 1, $usePermString); - $this->assertTrue($this->permObj->permission_exists($usePermName)); + if(!$this->assertTrue($this->permObj->permission_exists($usePermName), "Permission ('". $usePermName ."', id=". $permId .") does not exist")) { + $this->gfObj->debug_print($this->permObj->testDbTableHandler->get_records()); + } $this->assertTrue(is_numeric($permId)); //the method 'build_permissions_string()' should disregard extra indices in the array & build the string. @@ -199,14 +292,57 @@ $this->assertEqual($this->permObj->has_write_permission(0,$usePermName), $this->permObj->has_write_permission($thirdUser,$usePermName)); $this->assertEqual($this->permObj->has_execute_permission(0,$usePermName), $this->permObj->has_execute_permission($thirdUser,$usePermName)); } + + //create a huge list of permissions to test different scenarios. + { + $testPaths = array( + '/member', + '/member/ttorp', + '/member/ttorp/character', + '/member/ttorp/character/sheet', + '/member/ttorp/character/sheet/44', + '/admin/x', + '/admin/logs', + '/test/scripts/1/2/3/magicMarker', + '/api/system/test/212312300231223.21231/get/333', + '/content/dev/corner/cs/project', + '/content/dev/corner/cs/web/app/libs', + '/content/dev', + '/content/dev/corner', + '/content/dev/coner/cs', + + //The following items fail for no apparent reason (that I can find)... + '/admin', + '/cntenx', + '/content/dev/corner/cs/content', //fails due to duplicate objects in path ("content" is in there twice). + ); + $testPerms = array( + 'rwxrwxrwx', + 'rwxrwx---', + 'rwx---rwx', + '---rwxrwx', + 'rwx------', + '---------', + 'r--r--r--', + '-w--w--w-', + '--x--x--x' + ); + foreach($testPaths as $tPath) { + $tPermString = 'rwxrwx---'; + $newPermId = $this->permObj->create_permission($tPath, $this->chosenOneUid, $this->defaultGroupId, $tPermString); + $this->assertTrue(is_numeric($newPermId)); + } + }///*/ }//end test_permissions //-------------------------------------------------------------------------- } class _gpTester extends cs_genericPermission { + public $testDbTableHandler; public function __construct($db) { parent::__construct($db); + $this->testDbTableHandler = $this->dbTableHandler; } public function do_schema() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-03-26 00:57:40
|
Revision: 211 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=211&view=rev Author: crazedsanity Date: 2011-03-26 00:57:34 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Generic chat libraries. Added Paths: ----------- trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php trunk/0.4/setup/genericChat.pgsql.sql trunk/0.4/tests/testOfCSGenericChat.php Copied: trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php (from rev 208, trunk/0.4/abstract/cs_genericGroup.abstract.class.php) =================================================================== --- trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php (rev 0) +++ trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php 2011-03-26 00:57:34 UTC (rev 211) @@ -0,0 +1,109 @@ +<?php +/* + * Created on February 25, 2011 + * + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +abstract class cs_genericChatCategoryAbstract extends cs_webapplibsAbstract { + + /** Database object. */ + public $db; + + /** cs_globalFunctions object, for cleaning strings & such. */ + public $gfObj; + + /** Table name used to store categories. */ + protected $myTable = "cswal_chat_category_table"; + + /** Sequence for chat category table. */ + protected $mySeq = "cswal_chat_category_table_change_category_id_seq"; + + /** Table handler object for simple SQL handling */ + private $dbTableHandler; + + /** Internal categoryId to use... */ + private $categoryId=0; + + //============================================================================ + public function __construct(cs_phpDB $db) { + $this->db = $db; + $this->gfObj = new cs_globalFunctions; + + //setup table handler. + $cleanString = array( + 'category_name' => "text" + ); + $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->myTable, $this->mySeq, 'chat_category_id', $cleanString); + }//end __construct() + //============================================================================ + + + + //============================================================================ + public function set_category_id($categoryId) { + if(is_numeric($categoryId)) { + $this->categoryId=$categoryId; + } + else{ + throw new exception(__METHOD__ .": invalid categoryId (". $categoryId .")"); + } + return($this->categoryId); + }//end set_category_id() + //============================================================================ + + + + //============================================================================ + /** + * Build the schema for the generic chat system. + */ + protected function build_schema() { + try { + $result = $this->db->run_sql_file(dirname(__FILE__) .'/../setup/genericChat.pgsql.sql'); + } + catch(Exception $e) { + throw new exception(__METHOD__ .":: failed to create schema, DETAILS::: ". $e->getMessage()); + } + if($result !== true) { + throw new exception(__METHOD__ .":: failed to create schema (no details)"); + } + }//end build_schema() + //============================================================================ + + + + //============================================================================ + public function create_category($name) { + try { + $result = $this->dbTableHandler->create_record(array('category_name' => $name)); + } + catch(Exception $e) { + throw new exception(__METHOD__ .":: failed to create record, DETAILS::: ". $e->getMessage()); + } + return($result); + }//end create_category() + //============================================================================ + + + + //============================================================================ + public function update_category($id, $name) { + try { + $result = $this->update_record($id, array('category_name' => $name)); + } + catch(Exception $e) { + throw new exception(__METHOD__ .":: failed to update record, DETAILS::: ". $e->getMessage()); + } + return($result); + }//end update_category() + //============================================================================ + +} + Property changes on: trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php ___________________________________________________________________ Added: svn:keywords + Id Author Revision HeadURL Date Added: svn:mergeinfo + Copied: trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php (from rev 208, trunk/0.4/abstract/cs_genericGroup.abstract.class.php) =================================================================== --- trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php (rev 0) +++ trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php 2011-03-26 00:57:34 UTC (rev 211) @@ -0,0 +1,123 @@ +<?php +/* + * Created on March 8, 2011 + * + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +abstract class cs_genericChatMessageAbstract extends cs_genericChatRoomAbstract { + + /** Database object. */ + public $db; + + /** cs_globalFunctions object, for cleaning strings & such. */ + public $gfObj; + + /** Table name used to store list of chat messages. */ + protected $myTable = "cswal_chat_message_table"; + + /** Sequence for chat message table. */ + protected $mySeq = "cswal_chat_message_table_change_message_id_seq"; + + /** Table handler object for simple SQL handling */ + private $dbTableHandler; + + /** */ + private $categoryId=null; + + /** */ + protected $uid; + + /** */ + protected $chatRoomId; + + //============================================================================ + public function __construct(cs_phpDB $db, $uid, $chatRoomId) { + $this->db = $db; + $this->gfObj = new cs_globalFunctions; + + //setup table handler. + $cleanString = array( + 'uid' => 'int', + 'chat_room_id' => 'int', + 'private_message_uid' => 'int', + 'message' => 'int' + ); + + if(is_numeric($uid)) { + $this->uid = $uid; + } + else { + throw new exception(__METHOD__ .": invalid UID (". $uid .")"); + } + if(is_numeric($chatRoomId)) { + $this->chatRoomId = $chatRoomId; + } + else { + throw new exception(__METHOD__ .": invalid room ID (". $chatRoomId .")"); + } + $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->myTable, $this->mySeq, 'chat_message_id', $cleanString); + }//end __construct() + //============================================================================ + + + + //============================================================================ + public function create_message($messageText, $privateMessageUid=NULL) { + if(is_string($messageName) && strlen($message)) { + try { + $sqlArr = array( + 'uid' => $this->uid, + 'chat_room_id' => $this->chatRoomId, + + //TODO: should messageText be encoded? + 'message' => $messageText + ); + if(!is_null($privateMessageUid) && is_numeric($privateMessageUid)) { + $sqlArr['private_message_uid'] = $privateMessageUid; + } + $messageId = $this->dbTableHandler->create_record($sqlArr); + } + catch(Exception $e) { + throw new exception(__METHOD__ .": failed to create record, DETAILS::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .": (". $messageName .")"); + } + + return($messageId); + }//end create() + //============================================================================ + + + + //============================================================================ + public function get_messages($lastMessageId=NULL, $limit=NULL) { + $messages = array(); + try { + //get_records(array $filter=null, $orderBy=null, $limit=null, $offset=null) + $filterArr = array(); + if(!is_null($lastMessageId) && $lastMessageId > 0) { + $filterArr['message_id'] => '> '. $lastMessageId; + } + $messages = $this->dbTableHandler->get_records_using_custom_filter($filter, NULL, $limit); + if(!is_array($messages) && $messages === false) { + $messages = array(); + } + } + catch(Exception $e) { + throw new exception(__METHOD__ .": error while retrieving messages, DETAILS::: ". $e->getMessages()); + } + return($messages); + }//end get_messages() + //============================================================================ + +} + Property changes on: trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php ___________________________________________________________________ Added: svn:keywords + Id Author Revision HeadURL Date Added: svn:mergeinfo + Copied: trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php (from rev 208, trunk/0.4/abstract/cs_genericGroup.abstract.class.php) =================================================================== --- trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php (rev 0) +++ trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php 2011-03-26 00:57:34 UTC (rev 211) @@ -0,0 +1,110 @@ +<?php +/* + * Created on February 25, 2011 + * + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +abstract class cs_genericChatRoomAbstract extends cs_chatCategoryAbstract { + + /** Database object. */ + public $db; + + /** cs_globalFunctions object, for cleaning strings & such. */ + public $gfObj; + + /** Table name used to store list of chat rooms. */ + protected $myTable = "cswal_chat_room_table"; + + /** Sequence for chat room table. */ + protected $mySeq = "cswal_chat_room_table_change_room_id_seq"; + + /** Table handler object for simple SQL handling */ + private $dbTableHandler; + + //============================================================================ + public function __construct(cs_phpDB $db) { + $this->db = $db; + $this->gfObj = new cs_globalFunctions; + + //setup table handler. + $cleanString = array( + 'category_id' => "int", + 'room_name' => "text", + 'room_description' => "text", + 'is_private' => "bool", + 'is_closed' => "bool", + //'encoding' => "text" + ); + $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->myTable, $this->mySeq, 'chat_room_id', $cleanString); + }//end __construct() + //============================================================================ + + + + //============================================================================ + public function create_room($roomName, $roomDescription=null, $isPrivate=false) { + if(is_string($roomName) && strlen($room)) { + try { + if(!is_bool($isPrivate)) { + $isPrivate=false; + } + $insertArr = array( + 'room_name' => $roomName, + 'room_description' => $roomDescription, + 'is_private' => $isPrivate + ); + if(is_numeric($this->categoryId)) { + $insertArr['category_id'] = $this->categoryId; + } + $roomId = $this->dbTableHandler->create_record($insertArr); + } + catch(Exception $e) { + throw new exception(__METHOD__ .": failed to create record, DETAILS::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .": invalid room name (". $roomName .")"); + } + + return($roomId); + }//end create_room() + //============================================================================ + + + + //============================================================================ + public function update_room($roomId, array $updates) { + try { + $retval = $this->dbTableHandler->update_record($roomId, $updates); + } + catch(Exception $e) { + throw new exception(__METHOD__ .": failed to update room, DETAILS::: ". $e->getMessage()); + } + return($retval); + }//end update_room(); + //============================================================================ + + + + //============================================================================ + public function close_room($roomId) { + if(is_numeric($roomId)) { + $retval = $this->update_room($roomId, array('is_closed'=>true)); + } + else { + throw new exception(__METHOD__ .": roomId (". $roomId .")"); + } + return($retval); + }//end close_room() + //============================================================================ + + +} + Property changes on: trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php ___________________________________________________________________ Added: svn:keywords + Id Author Revision HeadURL Date Added: svn:mergeinfo + Added: trunk/0.4/setup/genericChat.pgsql.sql =================================================================== --- trunk/0.4/setup/genericChat.pgsql.sql (rev 0) +++ trunk/0.4/setup/genericChat.pgsql.sql 2011-03-26 00:57:34 UTC (rev 211) @@ -0,0 +1,54 @@ +BEGIN; + +-- +-- chat categories (ways to insulate chat rooms) +-- +CREATE TABLE cswal_chat_category_table ( + chat_category_id serial NOT NULL PRIMARY KEY, + category_name text NOT NULL +); + +INSERT INTO cswal_chat_category_table (chat_category_id, category_name) VALUES (0, 'DEFAULT'); + +-- +-- Chat rooms +-- +CREATE TABLE cswal_chat_room_table ( + chat_room_id serial NOT NULL PRIMARY KEY, + chat_category_id integer NOT NULL REFERENCES cswal_chat_category_table(chat_category_id) DEFAULT 0, + room_name text NOT NULL, + room_description text, + creation timestamptz NOT NULL DEFAULT NOW(), + is_private boolean NOT NULL DEFAULT false, + is_closed boolean NOT NULL DEFAULT false, + encoding text +); + + +-- +-- Chat messages +-- NOTE::: change the reference on "uid" and "private_message_uid" to match your database schema. +-- NOTE::: the "private_message_uid" field is for sending private messages (intended for a specific user). +-- +CREATE TABLE cswal_chat_message_table ( + chat_message_id serial NOT NULL PRIMARY KEY, + uid integer NOT NULL REFERENCES cs_authentication_table(uid), + private_message_uid integer DEFAULT NULL REFERENCES cs_authentication_table(uid), + chat_room_id integer NOT NULL REFERENCES cswal_chat_room_table(chat_room_id), + creation timestamptz NOT NULL DEFAULT NOW(), + message text NOT NULL +); + + +-- +-- Participant table +-- NOTE: this is a *transient* table; it only has data when the chat room is active. +-- +CREATE TABLE cswal_chat_participant_table ( + chat_participant_id serial NOT NULL PRIMARY KEY, + chat_room_id integer NOT NULL REFERENCES cswal_chat_room_table(chat_room_id), + uid integer NOT NULL REFERENCES cs_authentication_table(uid), + enter_timestamp timestamptz NOT NULL DEFAULT NOW(), + last_received_message_id integer REFERENCES cswal_chat_message_table(chat_message_id) +); + Copied: trunk/0.4/tests/testOfCSGenericChat.php (from rev 210, trunk/0.4/tests/testOfCSGenericPermissions.php) =================================================================== --- trunk/0.4/tests/testOfCSGenericChat.php (rev 0) +++ trunk/0.4/tests/testOfCSGenericChat.php 2011-03-26 00:57:34 UTC (rev 211) @@ -0,0 +1,53 @@ +<?php +/* + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +class testOfCSGenericChat extends testDbAbstract { + + + //-------------------------------------------------------------------------- + public function __construct() { + }//end __construct() + //-------------------------------------------------------------------------- + + + + //-------------------------------------------------------------------------- + function setUp() { + $this->gfObj = new cs_globalFunctions; + $this->gfObj->debugPrintOpt=1; + parent::__construct('postgres','', 'localhost', '5432'); + + }//end setUp() + //-------------------------------------------------------------------------- + + + + //-------------------------------------------------------------------------- + public function tearDown() { + if(isset($GLOBALS['keepDb'])) { + unset($GLOBALS['keepDb']); + } + else { + $this->destroy_db(); + } + } + //-------------------------------------------------------------------------- + + + + //-------------------------------------------------------------------------- + public function test_chatCategories() { + }//end test_chatCategories() + //-------------------------------------------------------------------------- + + + +} Property changes on: trunk/0.4/tests/testOfCSGenericChat.php ___________________________________________________________________ Added: svn:keywords + Id Author Revision HeadURL Date Added: svn:mergeinfo + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2011-04-03 18:17:54
|
Revision: 212 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=212&view=rev Author: crazedsanity Date: 2011-04-03 18:17:47 +0000 (Sun, 03 Apr 2011) Log Message: ----------- Fixes for table handling and some permissions stuff. Modified Paths: -------------- trunk/0.4/abstract/cs_genericObject.abstract.class.php trunk/0.4/abstract/cs_singleTableHandler.abstract.class.php trunk/0.4/cs_genericPermission.class.php trunk/0.4/setup/genericPermissions.pgsql.sql trunk/0.4/tests/example_test.php trunk/0.4/tests/testOfCSGenericPermissions.php Modified: trunk/0.4/abstract/cs_genericObject.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_genericObject.abstract.class.php 2011-03-26 00:57:34 UTC (rev 211) +++ trunk/0.4/abstract/cs_genericObject.abstract.class.php 2011-04-03 18:17:47 UTC (rev 212) @@ -98,8 +98,9 @@ . "object_name IN "; $myFilter = ""; - foreach($objectNames as $n) { - $tString = "'". $this->clean_object_name($n) ."'"; + foreach($objectNames as $i=>$n) { + $tCleanName = $this->clean_object_name($n); + $tString = "'". $tCleanName ."'"; $myFilter = $this->gfObj->create_list($myFilter, $tString); } $sql .= '('. $myFilter .')'; @@ -165,13 +166,11 @@ $idPath = ""; if(is_array($myIds) && count($myIds)) { - foreach($myIds as $id=>$name) { - try { - $idPath = $this->gfObj->create_list($idPath, $this->create_id_path_part($id), ''); - } - catch(Exception $e) { - throw new exception($e->getMessage()); - } + $nameToId = array_flip($myIds); + foreach($objects as $i=>$name) { + $cleanName = $this->clean_object_name($name); + $tId = $nameToId[$cleanName]; + $idPath = $this->gfObj->create_list($idPath, $this->create_id_path_part($tId), ''); } } else { @@ -181,6 +180,7 @@ catch(Exception $e) { throw new exception(__METHOD__ .": failed to create id path, DETAILS::: ". $e->getMessage()); } +#$this->gfObj->debug_print(__METHOD__ .": returning=(". $idPath ."), objects::: ". $this->gfObj->debug_print($objects,0,1) ."\n<BR> myIds::: ". $this->gfObj->debug_print($myIds,0,1)); return($idPath); }//end create_id_path_from_objects() //============================================================================ @@ -188,7 +188,7 @@ //============================================================================ - protected function clean_object_name($n) { + public function clean_object_name($n) { //pulled from cs-content, cs_globalFunctions::cleanString(), style="query"; modified to allow the brackets. $evilChars = array("\$", ":", "%", "~", "*",">", "<", "-", "[", "]", ")", "(", "&", "#", "?", ".", "\,","\/","\\","\"","\|","!","^","+","`","\n","\r"); $n = preg_replace("/\|/","",$n); @@ -229,10 +229,19 @@ //============================================================================ - public function translate_id_path($idPath) { + public function translate_id_path($idPath, $debug=0) { if($this->is_id_path($idPath)) { $bits = $this->explode_id_path($idPath); - $translatedPath = $this->get_object_names($this->explode_id_path($idPath)); + $translatedBits = $this->get_object_names($this->explode_id_path($idPath)); + + $translatedPath = ""; + foreach($bits as $id) { + $translatedPath = $this->gfObj->create_list($translatedPath, $translatedBits[$id], '/'); + } + #foreach($translatedBits as $id=>$name) { + # $translatedPath = $this->gfObj->create_list($translatedPath, $name, '/'); + #} + $translatedPath = '/'. $translatedPath; } else { throw new exception(__METHOD__ .": invalid path (". $idPath .")"); @@ -269,5 +278,18 @@ }//end get_object_names() //============================================================================ + + + //============================================================================ + public function clean_object_path($path) { + $bits = $this->explode_id_path($path); + $newPath = ""; + foreach($bits as $k=>$v) { + $newPath = $this->gfObj->create_list($newPath, $this->clean_object_name($v), '/'); + } + return($newPath); + }//end clean_object_path() + //============================================================================ + } ?> Modified: trunk/0.4/abstract/cs_singleTableHandler.abstract.class.php =================================================================== --- trunk/0.4/abstract/cs_singleTableHandler.abstract.class.php 2011-03-26 00:57:34 UTC (rev 211) +++ trunk/0.4/abstract/cs_singleTableHandler.abstract.class.php 2011-04-03 18:17:47 UTC (rev 212) @@ -224,6 +224,41 @@ //------------------------------------------------------------------------- + public function get_records_using_custom_filter($filter, $orderBy=null, $limit=null, $offset=null) { + if(is_string($filter) && strlen($filter)) { + $limitOffsetStr = ''; + if(is_numeric($limit) && $limit > 0) { + $limitOffsetStr = ' LIMIT '. $limit; + + //using an offset without a limit seems silly... + if(is_numeric($limitOffsetStr) && $offset > 0) { + $limitOffsetStr .= ' OFFSET '. $offset; + } + } + + $orderBYStr = ' ORDER BY '. $this->pkeyField; + if($is_string($orderBy) && strlen($orderBy)) { + $orderByStr = ' ORDER BY '. $orderBy; + } + + $sql = 'SELECT * FROM '. $this->tableName . $filter . $orderByStr . $limitOffsetStr; + try { + $data = $this->dbObj->run_query($sql, $this->pkeyField); + } + catch(Exception $e) { + throw new exception(__METHOD__ .":: failed to retrieve records, DETAILS::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .": invalid filter (". $filter .")"); + } + return($data); + }//end get_records_using_custom_filter() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- /** * Update a single record with the given changes. * Modified: trunk/0.4/cs_genericPermission.class.php =================================================================== --- trunk/0.4/cs_genericPermission.class.php 2011-03-26 00:57:34 UTC (rev 211) +++ trunk/0.4/cs_genericPermission.class.php 2011-04-03 18:17:47 UTC (rev 212) @@ -174,11 +174,11 @@ if(is_string($name) && strlen($name) && is_numeric($userId) && $userId >= 0 && is_numeric($groupId) && $groupId >= 0) { try{ $insertArr = $this->parse_permission_string($permString); - $insertArr['object_path'] = $this->create_id_path($name); + $insertArr['id_path'] = $this->create_id_path($name); $insertArr['user_id'] = $userId; $insertArr['group_id'] = $groupId; - $newId = $this->dbTableHandler->create_record($insertArr); + $newId = $this->dbTableHandler->create_record($insertArr,false); } catch(Exception $e) { throw new exception(__METHOD__ .":: failed to create new record, name=(". $name ."), permString=(". $permString .") DETAILS::: ". $e->getMessage()); @@ -203,11 +203,11 @@ if(!$this->is_id_path($name)) { $name = $this->create_id_path($name); } - $retval = $this->dbTableHandler->get_single_record(array('object_path'=>$name)); + $retval = $this->dbTableHandler->get_single_record(array('id_path'=>$name)); //now translate the object_path... - // TODO: this could be a resource hog if called in rapid succession; consider creating an object cache or whatnot - $retval['translated_path'] = $this->translate_id_path($retval['object_path']); + $retval['object_path'] = $this->translate_id_path($retval['id_path']); + $retval['perm_string'] = $this->build_permission_string($retval); } catch(Exception $e) { throw new exception(__METHOD__ .":: error while locating permission '". $name ."', DETAILS::: ". $e->getMessage()); @@ -404,6 +404,7 @@ $path = preg_replace('/^'. addcslashes($this->objectDelimiter, '/') .'/', '', $path); $path = preg_replace('/'. addcslashes($this->objectDelimiter, '/') .'{2,}/', $this->objectDelimiter, $path); $bits = explode($this->objectDelimiter, $path); +#$this->gfObj->debug_print(__METHOD__ .": path=(". $path ."), bits::: ". $this->gfObj->debug_print($bits,0,1)); } else { throw new exception(__METHOD__ .": invalid path (". $path .")"); @@ -421,6 +422,7 @@ //now create the path. $newPath = $this->create_id_path_from_objects($bits); +#$this->gfObj->debug_print(__METHOD__ .": newPath=(". $newPath ."), bits::: ". $this->gfObj->debug_print($bits,0,1)); if(!$this->is_id_path($newPath)) { throw new exception(__METHOD__ .": failed to create ID path from (". $path .")"); } @@ -428,5 +430,12 @@ return($newPath); }//end create_id_path() //============================================================================ + + + + //============================================================================ + public function update_permission() { + }//end update_permission() + //============================================================================ } ?> Modified: trunk/0.4/setup/genericPermissions.pgsql.sql =================================================================== --- trunk/0.4/setup/genericPermissions.pgsql.sql 2011-03-26 00:57:34 UTC (rev 211) +++ trunk/0.4/setup/genericPermissions.pgsql.sql 2011-04-03 18:17:47 UTC (rev 212) @@ -60,7 +60,7 @@ CREATE TABLE cswal_permission_table ( permission_id serial NOT NULL PRIMARY KEY, system_name integer NOT NULL DEFAULT 0 REFERENCES cswal_system_table(system_id), - object_path text NOT NULL, + id_path text NOT NULL, user_id integer NOT NULL REFERENCES cs_authentication_table(uid), group_id integer NOT NULL REFERENCES cswal_group_table(group_id), inherit boolean NOT NULL DEFAULT FALSE, @@ -79,5 +79,5 @@ INSERT INTO cswal_system_table (system_id, system_name) VALUES (0, 'DEFAULT'); ALTER TABLE ONLY cswal_permission_table - ADD CONSTRAINT cswal_permission_table_system_path_key UNIQUE (system_name, object_path); + ADD CONSTRAINT cswal_permission_table_system_path_key UNIQUE (system_name, id_path); Modified: trunk/0.4/tests/example_test.php =================================================================== --- trunk/0.4/tests/example_test.php 2011-03-26 00:57:34 UTC (rev 211) +++ trunk/0.4/tests/example_test.php 2011-04-03 18:17:47 UTC (rev 212) @@ -12,8 +12,22 @@ */ -require_once(dirname(__FILE__) .'/testOfCSVersionParse.php'); +require_once(dirname(__FILE__) .'/tests/testOfCSGenericChat.php'); +require_once(dirname(__FILE__) .'/tests/testOfCSGenericPermissions.php'); +require_once(dirname(__FILE__) .'/tests/testOfCSPHPDB.php'); +require_once(dirname(__FILE__) .'/tests/testOfCSWebAppLibs.php'); +/* +tests/testOfCSGenericChat.php:class testOfCSGenericChat extends testDbAbstract { +tests/testOfCSGenericPermissions.php:class testOfCSGenericPermissions extends testDbAbstract { +tests/testOfCSGenericPermissions.php:class _gpTester extends cs_genericPermission { +tests/testOfCSPHPDB.php:class TestOfCSPHPDB extends UnitTestCase { +tests/testOfCSWebAppLibs.php:class testOfCSWebAppLibs extends testDbAbstract { +tests/testOfCSWebAppLibs.php:class authTokenTester extends cs_authToken { +*/ -$test = &new TestOfA2P(); -$test->run(new HtmlReporter()) +$test = new TestSuite('Tests for CS-WebAppLibs'); +$test->addTestCase(new TestOfCSPHPDB()); +$test->addTestCase(new testOfCSWebAppLibs()); +$test->addTestCase(new testOfCSGenericChat()); +$test->addTestCase(new testOfCSGenericPermissions()); ?> Modified: trunk/0.4/tests/testOfCSGenericPermissions.php =================================================================== --- trunk/0.4/tests/testOfCSGenericPermissions.php 2011-03-26 00:57:34 UTC (rev 211) +++ trunk/0.4/tests/testOfCSGenericPermissions.php 2011-04-03 18:17:47 UTC (rev 212) @@ -250,6 +250,126 @@ $this->assertEqual($this->permObj->get_perm_list($myPermArr,'o'), $permByType['o']); } + //test ALL (or at least close to all) variations of permission strings... + { + $allVariations = array( + 'rwxrwxrwx' => array( + 'u_r' => true, + 'u_w' => true, + 'u_x' => true, + 'g_r' => true, + 'g_w' => true, + 'g_x' => true, + 'o_r' => true, + 'o_w' => true, + 'o_x' => true + ), + 'rwxrwxrw-' => array( + 'u_r' => true, + 'u_w' => true, + 'u_x' => true, + 'g_r' => true, + 'g_w' => true, + 'g_x' => true, + 'o_r' => true, + 'o_w' => true, + 'o_x' => false + ), + 'rwxrwxr--' => array( + 'u_r' => true, + 'u_w' => true, + 'u_x' => true, + 'g_r' => true, + 'g_w' => true, + 'g_x' => true, + 'o_r' => true, + 'o_w' => false, + 'o_x' => false + ), + 'rwxrwx---' => array( + 'u_r' => true, + 'u_w' => true, + 'u_x' => true, + 'g_r' => true, + 'g_w' => true, + 'g_x' => true, + 'o_r' => false, + 'o_w' => false, + 'o_x' => false + ), + 'rwxrw----' => array( + 'u_r' => true, + 'u_w' => true, + 'u_x' => true, + 'g_r' => true, + 'g_w' => true, + 'g_x' => false, + 'o_r' => false, + 'o_w' => false, + 'o_x' => false + ), + 'rwxr-----' => array( + 'u_r' => true, + 'u_w' => true, + 'u_x' => true, + 'g_r' => true, + 'g_w' => false, + 'g_x' => false, + 'o_r' => false, + 'o_w' => false, + 'o_x' => false + ), + 'rwx------' => array( + 'u_r' => true, + 'u_w' => true, + 'u_x' => true, + 'g_r' => false, + 'g_w' => false, + 'g_x' => false, + 'o_r' => false, + 'o_w' => false, + 'o_x' => false + ), + 'rw-------' => array( + 'u_r' => true, + 'u_w' => true, + 'u_x' => false, + 'g_r' => false, + 'g_w' => false, + 'g_x' => false, + 'o_r' => false, + 'o_w' => false, + 'o_x' => false + ), + 'r--------' => array( + 'u_r' => true, + 'u_w' => false, + 'u_x' => false, + 'g_r' => false, + 'g_w' => false, + 'g_x' => false, + 'o_r' => false, + 'o_w' => false, + 'o_x' => false + ), + '---------' => array( + 'u_r' => false, + 'u_w' => false, + 'u_x' => false, + 'g_r' => false, + 'g_w' => false, + 'g_x' => false, + 'o_r' => false, + 'o_w' => false, + 'o_x' => false + ), + ); + foreach($allVariations as $permString=>$testPermArray) { + $parsedPerms = $this->permObj->parse_perm_string($permString); + $this->assertEqual($parsedPerms, $testPermArray); + } + } + //create some permissions. { $userKeys = array_keys($this->validUsers); @@ -310,27 +430,27 @@ '/content/dev', '/content/dev/corner', '/content/dev/coner/cs', - - //The following items fail for no apparent reason (that I can find)... '/admin', '/cntenx', - '/content/dev/corner/cs/content', //fails due to duplicate objects in path ("content" is in there twice). + '/content/dev/corner/cs/content', ); - $testPerms = array( - 'rwxrwxrwx', - 'rwxrwx---', - 'rwx---rwx', - '---rwxrwx', - 'rwx------', - '---------', - 'r--r--r--', - '-w--w--w-', - '--x--x--x' - ); foreach($testPaths as $tPath) { - $tPermString = 'rwxrwx---'; + $tPermString = '-w--w----'; $newPermId = $this->permObj->create_permission($tPath, $this->chosenOneUid, $this->defaultGroupId, $tPermString); $this->assertTrue(is_numeric($newPermId)); + + //retrieve the permission & check some things out... + $permData = $this->permObj->get_permission($tPath); + $this->assertEqual($permData['permission_id'], $newPermId); + if(!$this->assertEqual($permData['object_path'], $this->permObj->clean_object_path($tPath))) { + #$this->permObj->translate_id_path($permData['id_path'], 1); + $this->gfObj->debug_print($permData); + } + $this->assertEqual($permData['perm_string'], $tPermString); + if(!$this->assertEqual($this->permObj->parse_perm_string($tPermString), $this->permObj->parse_perm_string($permData['perm_string']))) { + $this->gfObj->debug_print($this->permObj->parse_perm_string($tPermString)); + $this->gfObj->debug_print($this->permObj->parse_perm_string($permData['perm_string'])); + } } }///*/ }//end test_permissions This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |