Kaynağa Gözat

added support for AntAcl - se gui

Piotr Labudda 8 yıl önce
ebeveyn
işleme
dad88b7e58

+ 3 - 11
SE/se-lib/AntAclBase.php

@@ -9,7 +9,7 @@ Lib::loadClass('Core_AclBase');
 class AntAclBase extends Core_AclBase {
 
   public function __construct($zasobID = 0) {
-    $this->_zasobID = $zasobID;
+    $this->_zasobID = (int)$zasobID;
     $this->_name = '';
     $this->_namespace = '';
     $this->_rootTableName = '';
@@ -18,6 +18,7 @@ class AntAclBase extends Core_AclBase {
     $this->_primaryKey = '';
     $this->_fields = [];
   }
+  public function getDB() { return $this->_db; }
   public function getName() { return $this->_name; }
   public function getNamespace() { return $this->_namespace; }
   public function getRootNamespace() { return $this->_rootNamespace; }
@@ -189,16 +190,7 @@ class AntAclBase extends Core_AclBase {
       return $_cache[$idZasob];
     }
 
-    if (empty($conf)) {
-      throw new Exception("Brak danych konfiguracyjnych do obiektu ant nr {$idZasob}");
-
-      // TODO: fetch conf by $idZasob (or find $namespace first)
-      // Lib::loadClass('SchemaFactory');
-      // $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
-      // $item = $objectStorage->getItem($namespace, [
-      // 	'propertyName' => '*,field'
-      // ]);
-    }
+    if (empty($conf)) throw new Exception("Brak danych konfiguracyjnych do obiektu ant nr {$idZasob}");
     DBG::log($conf, 'array', 'AntAclBase::buildInstance $conf');
     $acl = new AntAclBase($idZasob);
     $acl->_name = $conf['name'];

+ 29 - 0
SE/se-lib/Core/AclBase.php

@@ -867,4 +867,33 @@ if($DBG){die();}
     return '';
   }
 
+
+	public function getOpis() { return ''; } // $this->_opis; } // TODO: legacy
+	public function getRawOpis() { return ''; // TODO: legacy
+		// $opis = $this->_opis;
+		// if (!$opis) return $this->getRawLabel(100);
+		// $opis = strip_tags($opis);
+		// return $opis;
+	}
+	public function getLongRawLabel($posLimit = 30) { // TODO: legacy
+		return $this->getNamespace();
+		// $longLabel = $this->getRawLabel($posLimit);
+		// $opis = $this->_opis;
+		// if ($longLabel != $this->_name) {
+		// 	$longLabel .= ' ' . $this->_name;
+		// }
+		// return $longLabel;
+	}
+	public function getLongLabel($posLimit = 30) { // TODO: legacy
+    	return $this->getNamespace();
+		// $longLabel = $this->getRawLabel($posLimit);
+		// $opis = $this->_opis;
+		// if ($longLabel != $this->_name) {
+		// 	$longLabel .= ' <em>' . $this->_name . '</em>';
+		// }
+    	//
+		// $longLabel = '<span title="' . htmlspecialchars($opis) . '">' . $longLabel . '</span>';
+		// return $longLabel;
+	}
+
 }

+ 2 - 1
SE/se-lib/Core/AclHelper.php

@@ -227,7 +227,8 @@ class Core_AclHelper {// Helper class for Acl
 		return $rowFunList;
 	}
 
-  public static function getAclList() {// @usage Core_AclHelper::getAclList();// @returns array [ $typeName , ... ]
+  public static function getAclList() { return self::getCustomAclList(); } // TODO: RMME renamed to getCustomAclList
+  public static function getCustomAclList() {// @usage Core_AclHelper::getCustomAclList();// @returns array [ $typeName , ... ]
     $aclList = array();
     // Schema_AccessGroupStorageAcl, load by User::getAcl()->getObjectAcl('default_objects', $objName);
     //    $objClassName = "Schema_{$objName}StorageAcl";

+ 4 - 3
SE/se-lib/Lib.php

@@ -6,21 +6,22 @@ class Lib {
 
 
 	public static function loadClass($clsName) {
-		return self::_loadClass($clsName, true);
+		return self::_loadClass($clsName, $required = true);
 	}
 
 
 	public static function tryLoadClass($clsName) {
-		return self::_loadClass($clsName, false);
+		return self::_loadClass($clsName, $required = false);
 	}
 
 
 	/**
 	 * load Class.
-	 * 
+	 *
 	 * @example Core_Database_Mysql - check Core/Database/Mysql.php or Core_Database_Mysql.php file
 	 */
 	public static function _loadClass($clsName, $required = true) {
+		if (class_exists($clsName)) return true;
 		$path = APP_PATH_LIB . '/' . implode('/', explode('_', $clsName)) . '.php';
 		if (file_exists($path)) {
 			require_once $path;

+ 1 - 1
SE/se-lib/Schema/SystemObjectStorageAcl.php

@@ -221,7 +221,7 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
     }
 
     // // foreach ... DB::getPDO($idDatabase)->fetchAll(select real _rootTableName)
-    // foreach (Core_AclHelper::getAclList() as $typeName) {
+    // foreach (Core_AclHelper::getCustomAclList() as $typeName) {
     //   $ns = Core_AclHelper::parseTypeName($typeName);
     //   $namespace = str_replace('__x3A__', '/', $ns['prefix']) . "/{$ns['name']}";
     //   $sqlNs = DB::getPDO()->quote($namespace, PDO::PARAM_STR);

+ 41 - 5
SE/se-lib/TableAcl.php

@@ -6,6 +6,7 @@ Lib::loadClass('Typespecial');
 Lib::loadClass('ProcesHelper');
 Lib::loadClass('Schema_TableFactory');
 Lib::loadClass('DataSourceFactory');
+Lib::loadClass('SchemaFactory');
 
 /**
  * $_SESSION['TableAcl_cache'][$tableID] = array(
@@ -923,16 +924,44 @@ class TableAcl extends Core_AclBase {
 		if (array_key_exists($idTable, $_cache)) {
 			return $_cache[$idTable];
 		}
+
 		if (!empty($_SESSION['TableAcl_cache'][$idTable])) {
 			$tableAcl = new TableAcl($idTable);
 			$tableAcl->fromArray($_SESSION['TableAcl_cache'][$idTable]);
 			$_cache[$idTable] = $tableAcl;
 			return $_cache[$idTable];
 		}
+		if (!empty($_SESSION['AntAcl_cache'][$idTable])) {
+			try {
+				$objectList = SchemaFactory::loadDefaultObject('SystemObject')->getItems([
+					'propertyName' => "*,field",
+					'f_idZasob' => "={$idTable}",
+				]);
+				if (empty($objectList)) throw new Exception("Acl [{$idTable}] not exists in SystemObject"); // TODO: update Storage object list?
+
+				$objItem = reset($objectList);
+				DBG::log($objItem, 'array', "DBG objItem({$namespace})");
+				if (!in_array($objItem['_type'], [
+					// 'TableAcl', // TODO: TEST - to replace TableAcl by AntAcl or use object with namespace + '/tableName'?
+					'AntAcl',
+				])) throw new Exception("Not Implemented acl type '{$objItem['_type']}'");
+				if (!$objItem['isObjectActive']) {
+					if (!$objItem['hasStruct']) throw new Exception("namespace has no structure '{$namespace}'");
+					if (!$objItem['isStructInstalled']) throw new Exception("namespace structure not installed '{$namespace}'");
+					throw new Exception("namespace is not activated '{$namespace}'");
+				}
+
+				Lib::loadClass('AntAclBase');
+				$_cache[$idTable] = AntAclBase::buildInstance($objItem['idZasob'], $objItem);
+				return $_cache[$idTable];
+			} catch (Exception $e) {
+				DBG::log($e);
+			}
+		}
 		return null;
 	}
 
-	public static function buildInstance($idTable, $tableConfig) {
+	public static function buildInstance($idTable, $tableConfig) { // TODO: move outside - app session cache?
 		static $_cache;
 		if (!$_cache) $_cache = array();
 		if (array_key_exists($idTable, $_cache)) {
@@ -965,10 +994,17 @@ class TableAcl extends Core_AclBase {
 		// 	}
 		// }
 		if (empty($tableConfig)) throw new Exception("Brak danych konfiguracyjnych do tabeli nr {$idTable} #TACL" . __LINE__);
-		$obj = new TableAcl($idTable);
-		$obj->fromArray($tableConfig);
-		$obj->getRootTableName();
-		$obj->save();
+
+		$type = (false !== strpos($tableConfig['name'], '/')) ? 'AntAcl' : 'TableAcl'; // TODO: fix naive check this // $type = DB::getPDO()->fetchValue(" select o._type from `CRM_#CACHE_ACL_OBJECT` o where o.idZasob = '{$idTable}' limit 1 ");
+		if ('AntAcl' === $type) {
+			DBG::log("TODO: AntAcl save config in TableAcl::buildInstance [{$idTable}] '{$tableConfig['name']}'");
+			$_SESSION['AntAcl_cache'][$idTable] = true;
+		} else { // TableAcl
+			$obj = new TableAcl($idTable);
+			$obj->fromArray($tableConfig);
+			$obj->getRootTableName();
+			$obj->save();
+		}
 		$_cache[$idTable] = $obj;
 		return $_cache[$idTable];
 	}