Jelajahi Sumber

fixed getAcl by TypeName or Namespace

Piotr Labudda 9 tahun lalu
induk
melakukan
5fdebcb42c

+ 4 - 16
SE/se-lib/Core/AclBase.php

@@ -3,6 +3,7 @@
 Lib::loadClass('Api_WfsNs');
 Lib::loadClass('Api_WfsException');
 Lib::loadClass('User');
+Lib::loadClass('Core_AclHelper');
 
 // TODO: replace every methods using $idZasob to use $fieldName
 /* TODO: fetch ACL from acl tables:
@@ -454,7 +455,7 @@ class Core_AclBase {
           $fieldType = $this->getXsdFieldType($fieldName);
           if ('ref:p5_objects:' == substr($fieldType, 0, 15)) {
             if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " F.".__FUNCTION__." TODO: -------> validateInsertXml(\$field) \$field:";print_r($field);echo "\n";}
-            $acl = $this->getAclFromTypeName(substr($fieldType, 4));
+            $acl = Core_AclHelper::getAclByTypeName(substr($fieldType, 4));
             $action['fields'][$fieldName][$idx] = $acl->validateInsertXml($field);
           }
         }
@@ -566,19 +567,6 @@ class Core_AclBase {
     return "{$wktType}({$wkt})";
   }
 
-  public function getAclFromTypeName($typeName) {// TODO: mv to another class, duplicate from Api_WfsServerBase::getAclFromTypeName($typeName)
-		$typeEx = explode(':', $typeName);
-		if (2 != count($typeEx)) throw new Exception("Could not get acl for '{$typeName}' - syntax error");
-		if ('p5_' != substr($typeEx[0], 0, 3)) throw new Exception("Could not get acl for '{$typeName}' - prefix error");
-		$sourceName = substr($typeEx[0], 3);
-		$objName = $typeEx[1];
-		$acl = User::getAcl()->getObjectAcl($sourceName, $objName);
-		if (!$acl) throw new Exception("Could not get acl for '{$typeName}'");
-		$forceTblAclInit = 0;//('1' == V::get('_force', '', $_GET));
-		$acl->init($forceTblAclInit);
-		return $acl;
-	}
-
   public function insertXml($action) {// @param $action = [ 'typeName' => '*:*', 'fields'=>[ `name`=>[`fld`, `fld`, ...], ... ] ]
     $DBG = V::get('DBG_XML', 0, $_GET, 'int');
     if (empty($action['typeName'])) throw new Exception("Error Processing Request - missing typeName", 500);
@@ -599,7 +587,7 @@ class Core_AclBase {
         if ('complete' == $field['type']) {
           $sqlInsert[$fieldName][$idx] = $field['value'];
         } else if ('open' == $field['type']) {
-          $childAcl = $this->getAclFromTypeName($field['typeName']);// TODO: or $fieldType = $this->getXsdFieldType($fieldName);// TODO: ref:p5_objects:File
+          $childAcl = Core_AclHelper::getAclByTypeName($field['typeName']);// TODO: or $fieldType = $this->getXsdFieldType($fieldName);// TODO: ref:p5_objects:File
           $sqlChildInsert[$fieldName][$idx] = $childAcl->insertXml($field);
         } else throw new Exception("Error Processing Request - BUG Unrecognized type '{$field['type']}'", 500);
       }
@@ -619,7 +607,7 @@ class Core_AclBase {
 
     foreach ($sqlChildInsert as $fieldName => $childFields) {
       foreach ($childFields as $idx => $childInsertedId) {
-        $childAcl = $this->getAclFromTypeName($action['fields'][$fieldName][$idx]['typeName']);// TODO: or $fieldType = $this->getXsdFieldType($fieldName);// TODO: ref:p5_objects:File
+        $childAcl = Core_AclHelper::getAclByTypeName($action['fields'][$fieldName][$idx]['typeName']);// TODO: or $fieldType = $this->getXsdFieldType($fieldName);// TODO: ref:p5_objects:File
         // $this->_insertRef($this->getRootTableName(), $childAcl->getRootTableName(), $insertedId, $childInsertedId);
         $this->_insertRef($fieldName, $insertedId, $childInsertedId);
       }

+ 40 - 36
SE/se-lib/Core/AclHelper.php

@@ -43,44 +43,47 @@ class Core_AclHelper {// Helper class for Acl
 		return $exportFields;
   }
 
+  public static function getAclByTypeName($typeName, $forceTblAclInit = false) {// TODO: replace getAclFromTypeName in WFS
+    return self::getAclByNamespace(str_replace(':', '/', $typeName), $forceTblAclInit);
+	}
   public static function getAclByNamespace($namespace, $forceTblAclInit = false) {
-		if ('http' != substr($namespace, 0, 4)) $namespace = Api_WfsNs::getBaseWfsUri() . '/' . $namespace;//Request::getHostUri() . '/' . $namespace;
-
-		$baseNsUri = Api_WfsNs::getBaseWfsUri();
-		if ("{$baseNsUri}/" == substr($namespace, 0, strlen($baseNsUri) + 1)) {
-			$schemaNs = substr($namespace, strlen($baseNsUri) + 1);
-			$ns = explode('/', $schemaNs);// "http://biuro.biall-net.pl/wfs/  default_db/{$nazwa_tabeli}/{$nazwa_obj}
-			$sourceName = array_shift($ns);// remove first element - source name
-			if ('default_db' == $sourceName || 'p5_default_db' == $sourceName) {
-				$sourceName = 'default_db';
-				$objName = $ns[0];
-				if (1 == count($ns)) {
-					$acl = User::getAcl()->getObjectAcl($sourceName, $objName);
-					if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
-					$acl->init($forceTblAclInit);
-					return $acl;
-				} else if (2 == count($ns)) {
+    if ('http' != substr($namespace, 0, 4)) $namespace = Api_WfsNs::getBaseWfsUri() . '/' . $namespace;//Request::getHostUri() . '/' . $namespace;
+
+    $baseNsUri = Api_WfsNs::getBaseWfsUri();
+    if ("{$baseNsUri}/" == substr($namespace, 0, strlen($baseNsUri) + 1)) {
+    	$schemaNs = substr($namespace, strlen($baseNsUri) + 1);
+    	$ns = explode('/', $schemaNs);// "http://biuro.biall-net.pl/wfs/  default_db/{$nazwa_tabeli}/{$nazwa_obj}
+    	$sourceName = array_shift($ns);// remove first element - source name
+      if ('default_db' == $sourceName || 'p5_default_db' == $sourceName) {
+      	$sourceName = 'default_db';
+      	$objName = $ns[0];
+      	if (1 == count($ns)) {
+      		$acl = User::getAcl()->getObjectAcl($sourceName, $objName);
+      		if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
+      		$acl->init($forceTblAclInit);
+      		return $acl;
+      	} else if (2 == count($ns)) {
 
           throw new Exception("TODO: default_db: '{$schemaNs}' ns:[ ".implode(", ", $ns)." ]", 501);
-				} else throw new Exception("Nieznany namespace default_db: '{$schemaNs}'", 501);
-			}
-			else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName || 'p5_objects' == $sourceName) {
-				$sourceName = 'objects';
-				$objName = $ns[0];
-				if (1 == count($ns)) {
-					$acl = User::getAcl()->getObjectAcl($sourceName, $objName);
-					if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
-					$acl->init($forceTblAclInit);
-					return $acl;
-				} else throw new Exception("Nieznany namespace SystemObjects: '{$schemaNs}'", 501);
-			}
-			else if ('zasob_' == substr($sourceName, 0, 6)) {
-				$dbName = substr($sourceName, 6);
-				throw new Exception("TODO db[{$dbName}] namespace '{$schemaNs}'", 501);
-			}
-			else throw new Exception("Nieznany namespace '{$schemaNs}'", 501);
-		}
-		else throw new HttpException("Zasoby zewnętrzenj systemu nie są jeszcze zaimplementowane", 501);
+      	} else throw new Exception("Nieznany namespace default_db: '{$schemaNs}'", 501);
+      }
+      else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName || 'p5_objects' == $sourceName) {
+      	$sourceName = 'objects';
+      	$objName = $ns[0];
+      	if (1 == count($ns)) {
+      		$acl = User::getAcl()->getObjectAcl($sourceName, $objName);
+      		if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
+      		$acl->init($forceTblAclInit);
+      		return $acl;
+      	} else throw new Exception("Nieznany namespace SystemObjects: '{$schemaNs}'", 501);
+      }
+      else if ('zasob_' == substr($sourceName, 0, 6)) {
+      	$dbName = substr($sourceName, 6);
+      	throw new Exception("TODO db[{$dbName}] namespace '{$schemaNs}'", 501);
+      }
+      else throw new Exception("Nieznany namespace '{$schemaNs}'", 501);
+    }
+    else throw new HttpException("Zasoby zewnętrzenj systemu nie są jeszcze zaimplementowane", 501);
 
 		throw new HttpException("TODO L.".__LINE__." ns({$namespace})", 501);
 	}
@@ -220,7 +223,8 @@ class Core_AclHelper {// Helper class for Acl
     // SE/se-lib/Schema/FileStorageAcl.php:class Schema_FileStorageAcl extends Core_AclBase {
     // SE/se-lib/Schema/KorespondencjaStorageAcl.php:class Schema_KorespondencjaStorageAcl extends Core_AclBase {
     // SE/se-lib/Schema/TestPermsStorageAcl.php:class Schema_TestPermsStorageAcl extends Core_AclBase {
-    $aclList[] = 'default_objects:AccessGroup';
+    $aclList[] = 'default_objects:AccessGroupRead';
+    $aclList[] = 'default_objects:AccessGroupWrite';
     $aclList[] = 'default_objects:AccessOwner';
     $aclList[] = 'default_objects:File';
     $aclList[] = 'default_objects:Korespondencja';

+ 1 - 18
SE/se-lib/Route/ViewTableAjax.php

@@ -151,7 +151,7 @@ class Route_ViewTableAjax extends RouteBase {
 		if (!$idHist) throw new Exception("Wrong param idHist");
 		$fieldName = V::get('fieldName', '', $_REQUEST, 'word');
 		if (!$fieldName) throw new Exception("Wrong param fieldName");
-		$acl = $this->getAclFromTypeName($typeName);
+		$acl = Core_AclHelper::getAclByTypeName($typeName);
 
 		$item = $acl->getItem($id);
 		if (!$item) throw new HttpException("Item not found", 404);
@@ -440,21 +440,4 @@ class Route_ViewTableAjax extends RouteBase {
 		Response::sendTryCatchJson(array($tbl, 'ajaxData'), $args = $_GET);
 	}
 
-	/**
-	 * @param string $typeName - 'p5_default_db:TEST_PERMS'
-	 */
-	public function getAclFromTypeName($typeName, $forceTblAclInit) {
-		$userAcl = User::getAcl();
-		$userAcl->fetchGroups();
-		$typeEx = explode(':', $typeName);
-		if (2 != count($typeEx)) throw new Exception("Could not get acl for '{$typeName}' - syntax error");
-		if ('p5_' != substr($typeEx[0], 0, 3)) throw new Exception("Could not get acl for '{$typeName}' - prefix error");
-		$sourceName = substr($typeEx[0], 3);
-		$objName = $typeEx[1];
-		$acl = $userAcl->getObjectAcl($sourceName, $objName);
-		if (!$acl) throw new Exception("Could not get acl for '{$typeName}'");
-		$acl->init($forceTblAclInit);
-		return $acl;
-	}
-
 }

+ 2 - 0
SE/se-lib/Schema/AccessGroupStorageAcl.php

@@ -94,6 +94,8 @@ class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
         $queryWhereBuilder->addComparisonFieldToValue('id', 'GreaterThen', substr($filterId, 1));
       } else if ('<' == substr($filterId, 0, 1) && is_numeric(substr($filterId, 1))) {
         $queryWhereBuilder->addComparisonFieldToValue('id', 'LessThen', substr($filterId, 1));
+      } else if ('=' == substr($filterId, 0, 1) && is_numeric(substr($filterId, 1))) {
+        $queryWhereBuilder->addComparisonFieldToValue('id', '=', substr($filterId, 1));
       } else {
         $filterId = null;// TODO: BUG uniimplemented comparison sign
       }

+ 2 - 1
SE/se-lib/Schema/KorespondencjaStorageAcl.php

@@ -1,6 +1,7 @@
 <?php
 
 Lib::loadClass('Core_AclBase');
+Lib::loadClass('Core_AclHelper');
 Lib::loadClass('FileStorage');
 
 class Schema_KorespondencjaStorageAcl extends Core_AclBase {
@@ -107,7 +108,7 @@ class Schema_KorespondencjaStorageAcl extends Core_AclBase {
     $baseRefTableName = $this->getRootTableName() . "__#REF__";
     $refRows = array();// $fieldName => [ pk, ... ]
     foreach ($refs as $fieldName => $type) {
-      $acl = $this->getAclFromTypeName($type);
+      $acl = Core_AclHelper::getAclByTypeName($type);
       $refTableName = $this->getRootTableName() . "__#REF__" . $acl->getRootTableName();
       $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
         select r.*

+ 2 - 1
SE/se-lib/Schema/TestPermsStorageAcl.php

@@ -1,6 +1,7 @@
 <?php
 
 Lib::loadClass('Core_AclBase');
+Lib::loadClass('Core_AclHelper');
 Lib::loadClass('FileStorage');
 
 class Schema_TestPermsStorageAcl extends Core_AclBase {
@@ -118,7 +119,7 @@ class Schema_TestPermsStorageAcl extends Core_AclBase {
     $sqlPk = array(); foreach ($pkList as $pk) { $sqlPk[] = DB::getPDO()->quote($pk, PDO::PARAM_STR); } $sqlPk = implode(", ", $sqlPk);
     $refRows = array();// $fieldName => [ pk, ... ]
     foreach ($refs as $fieldName => $type) {
-      $acl = $this->getAclFromTypeName($type);
+      $acl = Core_AclHelper::getAclByTypeName($type);
       // TODO: Core_AclBase->fetchRefs($fieldName, $pkList = array());// $refPk[$fieldName] = $this->fetchRefs($fieldName, $pkList);
       $refTableName = $this->createRefTable($fieldName);
       if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName})";echo"\n";}