[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[212] trunk/0.4
Status: Beta
Brought to you by:
crazedsanity
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. |