فهرست منبع

Acl fix proces init by table for current user

Piotr Labudda 10 سال پیش
والد
کامیت
044fd8b70f
5فایلهای تغییر یافته به همراه196 افزوده شده و 153 حذف شده
  1. 151 0
      SE/se-lib/ACL.php
  2. 20 20
      SE/se-lib/TableAjax.php
  3. 23 131
      SE/se-lib/UserAcl.php
  4. 1 0
      SE/se-lib/bootstrap.php
  5. 1 2
      SE/superedit-PROCES_MENU.php

+ 151 - 0
SE/se-lib/ACL.php

@@ -0,0 +1,151 @@
+<?php
+
+
+class ACL {
+
+	/**
+	 * Ids List of Proces Init for given tabel (skip filters)
+	 */
+	public function getTableProcesInitIds($idTable) {// TODO: use in TableAjax
+		$procesInitList = self::getTableProcesInitList($idTable);
+		return array_keys($procesInitList);
+	}
+
+	/**
+	 * List of Proces Init for given table (skip filters)
+	 */
+	public function getTableProcesInitList($idTable) {// TODO: use in TableAjax
+		$tableProcesInitList = array();
+		$sqlIdProcesListSql = <<<SQL
+			select tpv.`ID_PROCES`
+				from `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW` tpv
+				where tpv.`ID_TABLE`='{$idTable}'
+SQL;
+		$fetchTableProcesInitListSql = <<<SQL
+			-- time ~0.07 -- no goto and return
+			select p.`ID`, p.`DESC`
+			from `CRM_PROCES` p
+			where p.`ID` in(
+						select i.`idx_PROCES_INIT_ID`
+						from `CRM_PROCES_idx` i
+						where i.`ID_PROCES` in({$sqlIdProcesListSql})
+				)
+				and p.`TYPE`='PROCES_INIT'
+			order by p.`SORT_PRIO`
+SQL;
+		/*
+			SELECT p.`ID` , p.`DESC`
+			FROM  `CRM_PROCES` p
+			WHERE p.`ID`
+			IN (
+					SELECT i.`idx_PROCES_INIT_ID`
+					FROM  `CRM_PROCES_idx` i
+					WHERE i.`ID_PROCES`
+					IN (
+							SELECT tpv.`ID_PROCES`
+							FROM  `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW` tpv
+							WHERE tpv.`ID_TABLE` =  '13051'
+					)
+			)
+			AND p.`TYPE` =  'PROCES_INIT'
+			order by p.`SORT_PRIO`
+		*/
+		$fetchTableProcesInitListSql = <<<SQL
+			-- time ~0.15s
+			select p.`ID`, p.`DESC`
+			from `CRM_PROCES` p
+			where p.`ID` in(
+						select i.`idx_PROCES_INIT_ID`
+						from `CRM_PROCES_idx` i
+						where i.`ID_PROCES` in({$sqlIdProcesListSql})
+					union
+						select ig.`idx_PROCES_INIT_ID`
+						from `CRM_PROCES_idx` i
+							join `CRM_PROCES_idx` ig on(ig.`ID_PROCES`=i.`idx_PROCES_WITH_GROUPS_ID`)
+						where i.`ID_PROCES` in({$sqlIdProcesListSql})
+				)
+				and p.`TYPE`='PROCES_INIT'
+			order by p.`SORT_PRIO`
+SQL;
+		$fetchTableProcesInitListSql = <<<SQL
+			-- time ~0.14
+			select p.`ID`, p.`DESC`
+			from `CRM_PROCES` p
+			where p.`ID` in(
+					select i.`idx_PROCES_INIT_ID`
+					from `CRM_PROCES_idx` i
+					where i.`ID_PROCES` in({$sqlIdProcesListSql})
+						or i.`ID_PROCES` in(
+							select ig.`idx_PROCES_WITH_GROUPS_ID`
+							from `CRM_PROCES_idx` ig
+							where ig.`ID_PROCES` in({$sqlIdProcesListSql})
+						)
+				)
+				and p.`TYPE`='PROCES_INIT'
+			order by p.`SORT_PRIO`
+SQL;
+		//echo'<pre>$fetchTableProcesInitListSql('.$idTable.') ';print_r($fetchTableProcesInitListSql);echo'</pre>';
+		$tableProcesInitList = array();
+		$db = DB::getDB();
+		$res = $db->query($fetchTableProcesInitListSql);
+		while ($r = $db->fetch($res)) {
+			$tableProcesInitList[$r->ID] = $r->DESC;
+		}
+		return $tableProcesInitList;
+	}
+
+	public static function getProcesInitMapTreeOnlyIds($ids) {
+		$mapTree = array();
+		$map = self::getProcesInitMapOnlyIds($ids);
+		foreach ($map as $r) {
+			if ('PROCES_INIT' == $r->TYPE) {
+				$mapTree[$r->ID_PROCES] = array();
+			}
+		}
+		foreach ($map as $r) {
+			if ('GOTO_AND_RETURN' == $r->TYPE) {
+				$mapTree[$r->idx_MAIN_PROCES_INIT_ID][$r->ID_PROCES] = array();
+			}
+		}
+		foreach ($map as $r) {
+			if ('GOTO_AND_RETURN_LVL2' == $r->TYPE) {
+				$mapTree[$r->idx_MAIN_PROCES_INIT_ID][$r->idx_GOTO_LVL2_INIT_ID][$r->ID_PROCES] = true;
+			}
+		}
+		return $mapTree;
+	}
+
+	public static function getProcesInitMapOnlyIds($ids) {
+		$map = array();
+		$sqlIds = V::filter($ids, array('V', 'filterPositiveInteger'));
+		$sqlIds = implode(',', $sqlIds);
+		if (empty($sqlIds)) return $map;
+		$sql = <<<SQL
+			select i.`ID_PROCES`
+				, i.`PARENT_ID`
+				, i.`TYPE`
+				, i.`idx_PROCES_INIT_ID`
+				, i.`idx_MAIN_PROCES_INIT_ID`
+				, i.`idx_PROCES_WITH_GROUPS_ID`
+				, IF(i.`TYPE`='GOTO_AND_RETURN_LVL2'
+					, (select ig.`idx_PROCES_INIT_ID`
+						from `CRM_PROCES_idx` ig
+						where ig.`ID_PROCES`=i.`PARENT_ID`
+						limit 1)
+					, 0
+				) as idx_GOTO_LVL2_INIT_ID
+			from `CRM_PROCES_idx` i
+			where i.`ID_PROCES` in({$sqlIds})
+				and i.`idx_MAIN_PROCES_INIT_ID` in({$sqlIds})
+SQL;
+		DBG::_('DBG_MAP', '1', "MAP SQL", $sql, __CLASS__, __FUNCTION__, __LINE__);
+		$db = DB::getDB();
+		$res = $db->query($sql);
+		while ($r = $db->fetch($res)) {
+			$map[] = $r;
+		}
+		//DBG::table("MAP", $map, __CLASS__, __FUNCTION__, __LINE__);
+		return $map;
+	}
+
+}

+ 20 - 20
SE/se-lib/TableAjax.php

@@ -204,15 +204,6 @@ class TableAjax extends ViewAjax {
 		return $userAcl->getPermsFiltrProcesId();
 	}
 
-	private function _fetchConnectedProcesInitList() {
-		$pInitList = array();// [proces_init_id] => label (DESC)
-		if (!$this->_showProcesInit) {
-			return $pInitList;
-		}
-		$userAcl = User::getAcl();
-		return $userAcl->getTableProcesInitList($this->_zasobID);
-	}
-
 	public function allowTreeView() {
 		if ($this->_tbl == 'CRM_LISTA_ZASOBOW') return true;
 		if ($this->_tbl == 'CRM_PROCES') return true;
@@ -385,6 +376,7 @@ class TableAjax extends ViewAjax {
 		<div class="AjaxTableCont">
 			<ul class="breadcrumb">
 				<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a></li>
+				<?php if ($this->_showProcesInit) : ?>
 				<div class="btn-group pull-right">
 					<a class="btn btn-xs btn-info dropdown-toggle"
 						 data-toggle="dropdown"
@@ -397,6 +389,7 @@ class TableAjax extends ViewAjax {
 						<li class="disabled"><a href="#" onclick="return false;"> loading ... </a></li>
 					</ul>
 				</div>
+				<?php endif; ?>
 				<?php if ($this->_tbl == 'IN7_MK_BAZA_DYSTRYBUCJI') : ?>
 					<a class="pull-right" style="padding:0 20px 0 0;" href="<?php echo "index.php?MENU_INIT=TREEJS&ZASOB_ID={$this->_zasobID}"; ?>"><i class="glyphicon glyphicon-eye-open"></i> Drzewo</a>
 				<?php elseif ($this->allowTreeView()) : ?>
@@ -5389,19 +5382,26 @@ jQuery(document).ready(function(){
 	private function ajaxProcesInitFiltr($args) {// ajax task 'PROCES_INIT_FILTR'
 		$response = new stdClass();
 
-		$pInitList = $this->_fetchConnectedProcesInitList();
+		$pInitList = array();// [proces_init_id] => label (DESC)
+		if (!$this->_showProcesInit) {
+			$response->type = 'error';
+			return $response;
+		}
 		$userAcl = User::getAcl();
-		$procesIds = array_keys($pInitList);
-		$mapTree = $userAcl->getProcesInitMapTreeOnlyIds($procesIds);
-		DBG::_('DBG_MAP', '1', "mapTree", $mapTree, __CLASS__, __FUNCTION__, __LINE__);
-		DBG::_('DBG_MAP', '1', "pInitList", $pInitList, __CLASS__, __FUNCTION__, __LINE__);
-		$pInitListSelected = $this->getProcesInitSelected();
-
+		$pInitList = $userAcl->getTableProcesInitList($this->_zasobID);
+
+		if (!empty($pInitList)) {
+			$procesIds = array_keys($pInitList);
+			$mapTree = ACL::getProcesInitMapTreeOnlyIds($procesIds);
+			DBG::_('DBG_MAP', '1', "mapTree", $mapTree, __CLASS__, __FUNCTION__, __LINE__);
+			DBG::_('DBG_MAP', '1', "pInitList", $pInitList, __CLASS__, __FUNCTION__, __LINE__);
+			$pInitListSelected = $this->getProcesInitSelected();
+			$response->pInitData = new stdClass();
+			$response->pInitData->pInitList = $pInitList;
+			$response->pInitData->mapTree = $mapTree;
+			$response->pInitData->pInitListSelected = $pInitListSelected;
+		}
 		$response->type = 'success';
-		$response->pInitData = new stdClass();
-		$response->pInitData->pInitList = $pInitList;
-		$response->pInitData->mapTree = $mapTree;
-		$response->pInitData->pInitListSelected = $pInitListSelected;
 
 		return $response;
 	}

+ 23 - 131
SE/se-lib/UserAcl.php

@@ -505,7 +505,7 @@ SQL;
 	/**
 	 * Ids List of Proces Init for given tabel (skip filters)
 	 */
-	public function getTableProcesInitIds($idTable) {// TODO: use in TableAjax
+	public function getTableProcesInitIds($idTable) {
 		$procesInitList = $this->getTableProcesInitList($idTable);
 		return array_keys($procesInitList);
 	}
@@ -513,82 +513,28 @@ SQL;
 	/**
 	 * List of Proces Init for given table (skip filters)
 	 */
-	public function getTableProcesInitList($idTable) {// TODO: use in TableAjax
-		$tableProcesInitList = array();
-		$sqlIdProcesListSql = <<<SQL
-			select tpv.`ID_PROCES`
-				from `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW` tpv
-				where tpv.`ID_TABLE`='{$idTable}'
-SQL;
-		$fetchTableProcesInitListSql = <<<SQL
-			-- time ~0.07 -- no goto and return
-			select p.`ID`, p.`DESC`
-			from `CRM_PROCES` p
-			where p.`ID` in(
-						select i.`idx_PROCES_INIT_ID`
-						from `CRM_PROCES_idx` i
-						where i.`ID_PROCES` in({$sqlIdProcesListSql})
-				)
-				and p.`TYPE`='PROCES_INIT'
-			order by p.`SORT_PRIO`
-SQL;
-		/*
-			SELECT p.`ID` , p.`DESC`
-			FROM  `CRM_PROCES` p
-			WHERE p.`ID`
-			IN (
-					SELECT i.`idx_PROCES_INIT_ID`
-					FROM  `CRM_PROCES_idx` i
-					WHERE i.`ID_PROCES`
-					IN (
-							SELECT tpv.`ID_PROCES`
-							FROM  `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW` tpv
-							WHERE tpv.`ID_TABLE` =  '13051'
-					)
-			)
-			AND p.`TYPE` =  'PROCES_INIT'
-			order by p.`SORT_PRIO`
-		*/
-		$fetchTableProcesInitListSql = <<<SQL
-			-- time ~0.15s
-			select p.`ID`, p.`DESC`
-			from `CRM_PROCES` p
-			where p.`ID` in(
-						select i.`idx_PROCES_INIT_ID`
-						from `CRM_PROCES_idx` i
-						where i.`ID_PROCES` in({$sqlIdProcesListSql})
-					union
-						select ig.`idx_PROCES_INIT_ID`
-						from `CRM_PROCES_idx` i
-							join `CRM_PROCES_idx` ig on(ig.`ID_PROCES`=i.`idx_PROCES_WITH_GROUPS_ID`)
-						where i.`ID_PROCES` in({$sqlIdProcesListSql})
-				)
-				and p.`TYPE`='PROCES_INIT'
-			order by p.`SORT_PRIO`
-SQL;
-		$fetchTableProcesInitListSql = <<<SQL
-			-- time ~0.14
-			select p.`ID`, p.`DESC`
-			from `CRM_PROCES` p
-			where p.`ID` in(
-					select i.`idx_PROCES_INIT_ID`
-					from `CRM_PROCES_idx` i
-					where i.`ID_PROCES` in({$sqlIdProcesListSql})
-						or i.`ID_PROCES` in(
-							select ig.`idx_PROCES_WITH_GROUPS_ID`
-							from `CRM_PROCES_idx` ig
-							where ig.`ID_PROCES` in({$sqlIdProcesListSql})
-						)
-				)
-				and p.`TYPE`='PROCES_INIT'
-			order by p.`SORT_PRIO`
-SQL;
-		//echo'<pre>$fetchTableProcesInitListSql('.$idTable.') ';print_r($fetchTableProcesInitListSql);echo'</pre>';
-		$tableProcesInitList = array();
-		$db = DB::getDB();
-		$res = $db->query($fetchTableProcesInitListSql);
-		while ($r = $db->fetch($res)) {
-			$tableProcesInitList[$r->ID] = $r->DESC;
+	public function getTableProcesInitList($idTable) {
+		$tableProcesInitList = ACL::getTableProcesInitList($idTable);
+		if (!empty($tableProcesInitList)) {
+			$filteredTableProcesInitList = array();
+			DBG::_('DBG_MAP', '1', "tableProcesInitList({$idTable})", $tableProcesInitList, __CLASS__, __FUNCTION__, __LINE__);
+			$procesIds = array_keys($tableProcesInitList);
+			$sqlProcesIds = implode(",", $procesIds);
+			$userLogin = User::getLogin();
+			$sql = "select uiv.`ID_PROCES_INIT`, uiv.`DESC`
+				from `CRM_PROCES_idx_USER_to_INIT_VIEW` uiv
+				where uiv.`ADM_ACCOUNT`='{$userLogin}'
+					and uiv.`ID_PROCES_INIT` in({$sqlProcesIds})
+				group by uiv.`ID_PROCES_INIT`
+			";
+			DBG::_('DBG_MAP', '1', "tableProcesInitList({$idTable}):sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
+			$db = DB::getDB();
+			$res = $db->query($sql);
+			while ($r = $db->fetch($res)) {
+				$filteredTableProcesInitList[$r->ID_PROCES_INIT] = $r->DESC;
+			}
+			$tableProcesInitList = $filteredTableProcesInitList;
+			DBG::_('DBG_MAP', '1', "tableProcesInitList({$idTable}):filteredTableProcesInitList", $filteredTableProcesInitList, __CLASS__, __FUNCTION__, __LINE__);
 		}
 		return $tableProcesInitList;
 	}
@@ -616,58 +562,4 @@ SQL;
 		return $canExecuteProcesInit;
 	}
 
-	public function getProcesInitMapTreeOnlyIds($ids) {
-		$mapTree = array();
-		$map = $this->getProcesInitMapOnlyIds($ids);
-		foreach ($map as $r) {
-			if ('PROCES_INIT' == $r->TYPE) {
-				$mapTree[$r->ID_PROCES] = array();
-			}
-		}
-		foreach ($map as $r) {
-			if ('GOTO_AND_RETURN' == $r->TYPE) {
-				$mapTree[$r->idx_MAIN_PROCES_INIT_ID][$r->ID_PROCES] = array();
-			}
-		}
-		foreach ($map as $r) {
-			if ('GOTO_AND_RETURN_LVL2' == $r->TYPE) {
-				$mapTree[$r->idx_MAIN_PROCES_INIT_ID][$r->idx_GOTO_LVL2_INIT_ID][$r->ID_PROCES] = true;
-			}
-		}
-		return $mapTree;
-	}
-
-	public function getProcesInitMapOnlyIds($ids) {
-		$map = array();
-		$sqlIds = V::filter($ids, array('V', 'filterPositiveInteger'));
-		$sqlIds = implode(',', $sqlIds);
-		if (empty($sqlIds)) return $map;
-		$sql = <<<SQL
-			select i.`ID_PROCES`
-				, i.`PARENT_ID`
-				, i.`TYPE`
-				, i.`idx_PROCES_INIT_ID`
-				, i.`idx_MAIN_PROCES_INIT_ID`
-				, i.`idx_PROCES_WITH_GROUPS_ID`
-				, IF(i.`TYPE`='GOTO_AND_RETURN_LVL2'
-					, (select ig.`idx_PROCES_INIT_ID`
-						from `CRM_PROCES_idx` ig
-						where ig.`ID_PROCES`=i.`PARENT_ID`
-						limit 1)
-					, 0
-				) as idx_GOTO_LVL2_INIT_ID
-			from `CRM_PROCES_idx` i
-			where i.`ID_PROCES` in({$sqlIds})
-				and i.`idx_MAIN_PROCES_INIT_ID` in({$sqlIds})
-SQL;
-		DBG::_('DBG_MAP', '1', "MAP SQL", $sql, __CLASS__, __FUNCTION__, __LINE__);
-		$db = DB::getDB();
-		$res = $db->query($sql);
-		while ($r = $db->fetch($res)) {
-			$map[] = $r;
-		}
-		//DBG::table("MAP", $map, __CLASS__, __FUNCTION__, __LINE__);
-		return $map;
-	}
-
 }

+ 1 - 0
SE/se-lib/bootstrap.php

@@ -12,6 +12,7 @@ Lib::loadClass('DBG');
 Lib::loadClass('V');
 Lib::loadClass('Config');
 Lib::loadClass('DB');
+Lib::loadClass('ACL');
 Lib::loadClass('User');
 Lib::loadClass('SE_Layout');
 Lib::loadClass('S');

+ 1 - 2
SE/superedit-PROCES_MENU.php

@@ -101,8 +101,7 @@ function PROCES_MENU() {
 		}
 		case 'PROCES_FOR_TABLE': {
 			$tblId = V::get('tblId', 0, $_REQUEST, 'int');
-			$userAcl = User::getAcl();
-			$tableProcesInitIds = $userAcl->getTableProcesInitIds($tblId);
+			$tableProcesInitIds = ACL::getTableProcesInitIds($tblId);
 			$tableProcesIdsCSV = implode(",", $tableProcesInitIds);
 			$url = $_SERVER['SCRIPT_URI'];
 			$url = substr($url, 0, strrpos($url, '/'));