فهرست منبع

Acl fix methods to get proces init list for table and for user (with and without selected filter)

Piotr Labudda 10 سال پیش
والد
کامیت
9a9218dffc
3فایلهای تغییر یافته به همراه181 افزوده شده و 184 حذف شده
  1. 11 25
      SE/se-lib/ProcesMenu.php
  2. 144 158
      SE/se-lib/UserAcl.php
  3. 26 1
      SE/superedit-PROCES_MENU.php

+ 11 - 25
SE/se-lib/ProcesMenu.php

@@ -84,7 +84,7 @@ class ProcesMenu {
 		$testy_arr = array();
 		$ses_cache_key = 'CRM_PROCES_USERA_WYKONANE_TESTY-' . $this->_user_id;
 		if (!$this->_isTestsInCache()) {
-			$usedProcesInitIds = $this->_acl->getUsedUserProcesInitIds();
+			$usedProcesInitIds = $this->_acl->getUserProcesInitIds();
 			DBG::_('DBG_PM', '1', "usedProcesInitIds", $usedProcesInitIds, __CLASS__, __FUNCTION__, __LINE__ );
 			if (!empty($usedProcesInitIds)) {
 				$testy_arr = ProcesTestyHelper::get_tetsy_stats($this->_user_id, 0, $usedProcesInitIds);
@@ -291,7 +291,7 @@ jQuery(document).ready(function() {
 
 	private function getUsedProcesInitGroupedList() {
 		$procesyInitGroup = array();
-		$procesyInitList = $this->_acl->getUsedProcesInitList();
+		$procesyInitList = $this->_acl->getUserProcesInitList();
 		if (empty($procesyInitList)) {
 			return;
 		}
@@ -324,7 +324,7 @@ jQuery(document).ready(function() {
 	function menuAction() {
 		$testy_teoretyczne = $this->get_actual_tests_count('TEORETYCZNY');
 		$testy_praktyczne = $this->get_actual_tests_count('PRAKTYCZNY');
-		$procesy_init_arr = $this->_acl->getUsedProcesInitIds();
+		$procesy_init_arr = $this->_acl->getUserProcesInitIds();
 		$proces_cnt = count($procesy_init_arr);
 		$testy_ok = $this->get_actual_tests_count();
 		$MojeTestyTitle = "Ilość Procesów: {$proces_cnt}, Aktualnych testów: {$testy_ok},  Teoretycznych: {$testy_teoretyczne}, Praktycznych: {$testy_praktyczne}";
@@ -422,9 +422,6 @@ jQuery(document).ready(function() {
 		$treeZasobyFilter = FilterFactory::build('CRM_LISTA_ZASOBOW');
 		$lastZasobyFiltrIds = $treeZasobyFilter->get_arg('filtr_id');
 
-		$userProcesIdsCSV = $this->_acl->getUsedProcesInitIds();
-		$userProcesIdsCSV = implode(',', $userProcesIdsCSV);
-
 		$typeSpecialProces = TypespecialVariable::getInstance(-1, '__PROCES');
 
 		$treeProcesyFilter = FilterFactory::build('CRM_PROCES');
@@ -496,11 +493,9 @@ jQuery(document).ready(function() {
 							</li>
 							<li class="divider"></li>
 						<?php endif; ?>
-						<?php if (!empty($userProcesIdsCSV)) : ?>
-							<li>
-								<a href="procesy5.php?task=CRM_PROCES<?php echo "&filtr_id={$userProcesIdsCSV}&filtr_ids=%2B&filtr_ob=%2B&filtr_img=%2B";  ?>" title="Moje Procesy">Moje Procesy</a>
-							</li>
-						<?php endif; ?>
+						<li>
+							<a href="index.php?FUNCTION_INIT=PROCES_MENU&HEADER_NOT_INIT=YES&_task=PROCES_FOR_USER" title="Moje Procesy">Moje Procesy</a>
+						</li>
 						<?php if ($menuProcesViewedTblId > 0) : ?>
 							<li>
 								<a href="index.php?FUNCTION_INIT=PROCES_MENU&HEADER_NOT_INIT=YES&_task=PROCES_FOR_TABLE&tblId=<?php echo $menuProcesViewedTblId; ?>">Procesy dla aktualnie przeglądanej tabeli</a>
@@ -1186,25 +1181,16 @@ jQuery(document).ready(function() {
 		$userAcl = User::getAcl();
 		if ($userAcl->getPermsFiltrProcesId() == $procesID) {
 			$this->menuAction();
-			echo '<div class="alert alert-info">' . "Uprawnienia dla ID Procesu {$procesID} już zostały ustawione" . '</div>';
-			return;
-		}
-
-		$db = DB::getDB();
-		$proces = $db->get_by_id('CRM_PROCES', $procesID);
-
-		if ($proces->TYPE != 'PROCES_INIT') {
-			$this->menuAction();
-			echo '<div class="alert alert-danger">' . "Proces nie jest typu PROCES_INIT" . '</div>';
+			echo '<div class="alert alert-info">' . "Filtr procesu nr {$procesID} jest już uruchomiony" . '</div>';
 			return;
 		}
 
 		$userAcl = User::getAcl();
-		$procesStepList = $userAcl->getUsedProcesIds($procesID);
-		if (empty($procesStepList)) {
+		if (!$userAcl->canExecuteProcesInit($procesID)) {
 			$this->menuAction();
-			echo '<div class="alert alert-danger">' . "Nie ma takiego procesu dla usera aby ustawic dla niego filtry" . '</div>';
-			return;
+			echo '<div class="alert alert-danger">' . "Brak uprawnień do uruchomienia filtra procesu" . '</div>';
+			SE_Layout::dol();
+			exit;
 		}
 
 		$userAcl->fetchProcesPerms($procesID, true);

+ 144 - 158
SE/se-lib/UserAcl.php

@@ -97,117 +97,6 @@ class UserAcl {
 		return $this->_proces_tree_flat;
 	}
 
-	private function _createUsedProcesMap() {// TODO: RM
-		if (!empty($this->_proces_used_ids)) {
-			return;
-		}
-
-		$this->_proces_used_ids = $this->_cache_read('_proces_used_ids');
-		$this->_proces_used_map = $this->_cache_read('_proces_used_map');
-		if ($this->_proces_used_ids != null && $this->_proces_used_map != null) {
-			return;
-		}
-
-		$this->_proces_used_ids = array();// find path from proces_id connected with user to the end of process
-		$this->_proces_used_map = array();
-		$dbg = false;
-
-		$ID_PROCESOW_USERA = $this->getProcesIds();
-		if (empty($ID_PROCESOW_USERA)) {
-			return;
-		}
-		$CRM_PROCESS_TREE = $this->getProcesTree();
-		// ! rekursywnie szukam sciezek procesow powiazanych dla usera procesow
-		foreach ($ID_PROCESOW_USERA as $proces_id) {
-			$this->_proces_used_ids[$proces_id] = true;
-			if ($dbg) echo '<div style="border:1px solid blue;background-color:#eee;">' . "<b>find_rec(CRM_PROCESS_TREE, {$proces_id}, 'init') {</b>\n";
-			$CRM_PROCES_USERA_UZYTY_FIND = array();
-			$this->find_in_tree_parent_rec($CRM_PROCESS_TREE, $proces_id, $CRM_PROCES_USERA_UZYTY_FIND, $dbg);
-			if ($dbg) echo '</div>';
-			$this->_proces_used_ids[$proces_id] = true;//trzeba dodac sam proces, bo go brakuje w indeksach
-			$this->_proces_used_map[$proces_id][] = $proces_id;//trzeba dodac sam proces, bo go brakowalo w indeksach
-			if (is_array($CRM_PROCES_USERA_UZYTY_FIND)) {
-				foreach ($CRM_PROCES_USERA_UZYTY_FIND as $INDEX => $proces_id_found ) {
-					$this->_proces_used_ids[$proces_id_found] = true;
-					$this->_proces_used_map[$proces_id][] = $proces_id_found;//tworze mape procesow od glownego w dol
-				}
-			}
-		}
-		$this->_proces_used_ids = array_keys($this->_proces_used_ids);
-
-		$this->_cache_save('_proces_used_ids', $this->_proces_used_ids);
-		$this->_cache_save('_proces_used_map', $this->_proces_used_map);
-	}
-
-	public function getUsedProcesMap() {// TODO: RM, used in ProcesMenu (testy) - use view instead
-		$this->_createUsedProcesMap();
-		return $this->_proces_used_map;
-	}
-
-	public function getUsedProcesIds($procesID = null) {// TODO: RM, used in ProcesMenu
-		$this->_createUsedProcesMap();
-		$usedProcesListIds = $this->_proces_used_ids;
-
-		if ($procesID > 0) {
-			$map = $this->getUsedProcesMap();
-			if (!array_key_exists($procesID, $map)) {
-				return false;
-			}
-			$usedProcesListIds = $map[$procesID];
-		}
-
-		return $usedProcesListIds;
-	}
-
-	public function getUsedProcesInitIds($zasobId = 0) {// TODO: RM, used in ProcesMenu
-		if ($zasobId > 0) {
-			$pInitListRaw = $this->getProcesInitList($zasobId);
-			if (!empty($pInitListRaw)) {
-				$pInitListRaw = array_values($pInitListRaw);
-				$pInitListRaw = array_unique($pInitListRaw);
-			}
-			return $pInitListRaw;
-		} else {
-			$usedProcesInitList = $this->getUsedProcesInitList();
-			return array_keys($usedProcesInitList);
-		}
-	}
-
-	public function getUsedProcesInitList() {// TODO: RM, used in ProcesMenu
-		if (!empty($this->_proces_init_used)) {
-			return $this->_proces_init_used;
-		}
-
-		$map = $this->getUsedProcesMap();
-		if (!empty($map)) {
-			$db = DB::getDB();
-			$sql = "select `ID`, `DESC`
-				from `CRM_PROCES`
-				where `TYPE`='PROCES_INIT' and `ID` in (" . implode(",", array_keys($map)) . ") ";
-			$res = $db->query($sql);
-			while ($r = $db->fetch($res)) {
-				$this->_proces_init_used[$r->ID] = $r->DESC;
-			}
-		}
-		return $this->_proces_init_used;
-	}
-
-	function find_in_tree_parent_rec(&$tree, $parent_id, &$ret_array = array(), $dbg = false, $rec_limit = 1) {// TODO: RM used in _createUsedProcesMap
-		if ($dbg) { echo '<p style="margin:0;">' . "find_in_tree_parent_rec(tree, $parent_id, ret, $dbg, $rec_limit) find_in_tree_parent_rec_return: [" . implode(', ', $find_in_tree_parent_rec_return) . "] found(" . in_array($parent_id, $ret_array) . ")"  .'</p>'; }
-
-		if (isset($tree[$parent_id])) {
-			foreach ($tree[$parent_id] as $IND => $CHILD) {
-				if (in_array($CHILD, $ret_array)) {
-					continue;
-				}
-
-				$ret_array[] = $CHILD;
-				if ($dbg) { echo '<p style="margin:0;">' . "-- find_in_tree_parent_rec(tree, $parent_id, ret, $dbg, $rec_limit) crm_proces_usera_uzyty: [" . implode(', ', $ret_array) . "]"  .'</p>'; }
-				$this->find_in_tree_parent_rec($tree, $CHILD, $ret_array, $dbg, $rec_limit);
-			}
-		}
-	}
-
 	function _cache_init() {
 		if (!$this->_use_cache) return;
 
@@ -410,54 +299,52 @@ class UserAcl {
 
 		$this->setFilterIdProces($procesID);//$this->_cache_save('permsByProcesID', $procesID);
 
-		if (1) {
-			$sqlIdProcesListSql = $this->getUsedUserProcesIdsSql();
-
-			$userAccessForTables = array();
-			$sql = <<<SQL
-			select tpvg.`ID_TABLE`
-				, tpvg.`ID_DATABASE` as `db`
-				, tpvg.`TABLE_NAME` as `name`
-				, tpvg.`TABLE_LABEL` as `label`
-				, tpvg.`TABLE_DESCRIPTION` as `opis`
-			from `CRM_PROCES_idx_TABLE_TO_PROCES_GROUPED_VIEW` as tpvg
-			where tpvg.`ID_PROCES` in({$sqlIdProcesListSql})
-			group by tpvg.`ID_TABLE`
+		$sqlIdProcesListSql = $this->getUsedUserProcesIdsSql();
+
+		$userAccessForTables = array();
+		$sql = <<<SQL
+		select tpvg.`ID_TABLE`
+			, tpvg.`ID_DATABASE` as `db`
+			, tpvg.`TABLE_NAME` as `name`
+			, tpvg.`TABLE_LABEL` as `label`
+			, tpvg.`TABLE_DESCRIPTION` as `opis`
+		from `CRM_PROCES_idx_TABLE_TO_PROCES_GROUPED_VIEW` as tpvg
+		where tpvg.`ID_PROCES` in({$sqlIdProcesListSql})
+		group by tpvg.`ID_TABLE`
 SQL;
-			//echo'<pre>$userAccessForTables - $sql ';print_r($sql);echo'</pre>';
-			$db = DB::getDB();
-			$res = $db->query($sql);
-			while ($h = $db->fetch_assoc($res)) {
-				$userAccessForTables[$h['ID_TABLE']] = $h;
-			}
-			DBG::_('DBG_SCH', '1', "userAccessForTables", $userAccessForTables, __CLASS__, __FUNCTION__, __LINE__ );
-			foreach ($userAccessForTables as $idTable => $tableConfig) {
-				if (!array_key_exists($idTable, $foundTbls)) {
-					$foundTbls[$idTable] = $tableConfig;
-				}
+		//echo'<pre>$userAccessForTables - $sql ';print_r($sql);echo'</pre>';
+		$db = DB::getDB();
+		$res = $db->query($sql);
+		while ($h = $db->fetch_assoc($res)) {
+			$userAccessForTables[$h['ID_TABLE']] = $h;
+		}
+		DBG::_('DBG_SCH', '1', "userAccessForTables", $userAccessForTables, __CLASS__, __FUNCTION__, __LINE__ );
+		foreach ($userAccessForTables as $idTable => $tableConfig) {
+			if (!array_key_exists($idTable, $foundTbls)) {
+				$foundTbls[$idTable] = $tableConfig;
 			}
+		}
 
-			$userAccessForUrls = array();
-			$sql = <<<SQL
-			select upvg.`ID_URL`
-				, upvg.`URL_LINK` as `link`
-				, upvg.`URL_LABEL` as `label`
-				, upvg.`URL_DESC` as `opis`
-			from `CRM_PROCES_idx_URL_TO_PROCES_VIEW` as upvg
-			where upvg.`ID_PROCES` in({$sqlIdProcesListSql})
-			group by upvg.`ID_URL`
+		$userAccessForUrls = array();
+		$sql = <<<SQL
+		select upvg.`ID_URL`
+			, upvg.`URL_LINK` as `link`
+			, upvg.`URL_LABEL` as `label`
+			, upvg.`URL_DESC` as `opis`
+		from `CRM_PROCES_idx_URL_TO_PROCES_VIEW` as upvg
+		where upvg.`ID_PROCES` in({$sqlIdProcesListSql})
+		group by upvg.`ID_URL`
 SQL;
-			//echo'<pre>$userAccessForUrls - $sql ';print_r($sql);echo'</pre>';
-			$db = DB::getDB();
-			$res = $db->query($sql);
-			while ($h = $db->fetch_assoc($res)) {
-				$userAccessForUrls[$h['ID_URL']] = $h;
-			}
-			//echo'<pre>$userAccessForUrls ';print_r($userAccessForUrls);echo'</pre>';
-			DBG::_('DBG_SCH', '2', "userAccessForUrls", $userAccessForUrls, __CLASS__, __FUNCTION__, __LINE__ );
-			foreach ($userAccessForUrls as $idUrl => $vUrlConfig) {
-				$foundUrls[$idUrl] = $vUrlConfig['opis'];
-			}
+		//echo'<pre>$userAccessForUrls - $sql ';print_r($sql);echo'</pre>';
+		$db = DB::getDB();
+		$res = $db->query($sql);
+		while ($h = $db->fetch_assoc($res)) {
+			$userAccessForUrls[$h['ID_URL']] = $h;
+		}
+		//echo'<pre>$userAccessForUrls ';print_r($userAccessForUrls);echo'</pre>';
+		DBG::_('DBG_SCH', '2', "userAccessForUrls", $userAccessForUrls, __CLASS__, __FUNCTION__, __LINE__ );
+		foreach ($userAccessForUrls as $idUrl => $vUrlConfig) {
+			$foundUrls[$idUrl] = $vUrlConfig['opis'];
 		}
 
 		$this->_cache_save('foundUrls', $foundUrls);
@@ -555,11 +442,53 @@ SQL;
 		return $maxUpdateDate;
 	}
 
+	/**
+	 * Ids List of Proces Init for user (skip filters)
+	 */
+	public function getUserProcesInitIds() {
+		$procesInitList = $this->getUserProcesInitList();
+		return array_keys($procesInitList);
+	}
+
+	/**
+	 * List of Proces Init for user (skip filters)
+	 */
+	public function getUserProcesInitList() {
+		$userProcesInitList = array();
+		$idUserGroupList = User::getGroupsIds();
+		$sqlIdUserGroupList = implode(",", $idUserGroupList);
+		$sqlIdProcesListSql = <<<SQL
+			select gi.`ID_PROCES`
+				from `CRM_PROCES_idx_GROUP_to_PROCES` gi
+				where gi.`ID_GROUP` in({$sqlIdUserGroupList})
+SQL;
+		$fetchUserProcesInitListSql = <<<SQL
+			select p.`ID`, p.`DESC`
+				from `CRM_PROCES_idx` i
+					join `CRM_PROCES` p on(p.`ID`=i.`idx_PROCES_INIT_ID`)
+				where i.`ID_PROCES` in({$sqlIdProcesListSql})
+				group by p.`ID`
+				order by p.`SORT_PRIO`
+SQL;
+		$db = DB::getDB();
+		$res = $db->query($fetchUserProcesInitListSql);
+		while ($r = $db->fetch($res)) {
+			$userProcesInitList[$r->ID] = $r->DESC;
+		}
+		return $userProcesInitList;
+	}
+
+	/**
+	 * Ids List of Proces Init for user (use filters)
+	 */
 	public function getUsedUserProcesInitIds() {
 		$usedProcesInitList = $this->getUsedUserProcesInitList();
 		return array_keys($usedProcesInitList);
 	}
 
+	/**
+	 * List of Proces Init for user (use filters)
+	 */
 	public function getUsedUserProcesInitList() {
 		$filterIdProces = $this->getFilterIdProces();
 		if ($filterIdProces > 0) {
@@ -567,21 +496,78 @@ SQL;
 		}
 
 		$sqlIdProcesListSql = $this->getUsedUserProcesIdsSql();
-		$getUsedProcesInitListSql = <<<SQL
+		$fetchUsedProcesInitListSql = <<<SQL
 			select p.`ID`, p.`DESC`
 				from `CRM_PROCES` p
 				where p.`ID` in({$sqlIdProcesListSql})
 					and p.`TYPE`='PROCES_INIT'
-				group by p.`ID`
 				order by p.`SORT_PRIO`
 SQL;
 		$usedProcesInitList = array();
 		$db = DB::getDB();
-		$res = $db->query($getUsedProcesInitListSql);
+		$res = $db->query($fetchUsedProcesInitListSql);
 		while ($r = $db->fetch($res)) {
 			$usedProcesInitList[$r->ID] = $r->DESC;
 		}
 		return $usedProcesInitList;
 	}
 
+	/**
+	 * Ids List of Proces Init for given tabel (skip filters)
+	 */
+	public function getTableProcesInitIds($idTable) {// TODO: use in TableAjax
+		$procesInitList = $this->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
+			select p.`ID`, p.`DESC`
+				from `CRM_PROCES_idx` i
+					join `CRM_PROCES` p on(p.`ID`=i.`idx_PROCES_INIT_ID`)
+				where i.`ID_PROCES` in({$sqlIdProcesListSql})
+				group by p.`ID`
+				order by p.`SORT_PRIO`
+SQL;
+		$tableProcesInitList = array();
+		$db = DB::getDB();
+		$res = $db->query($fetchTableProcesInitListSql);
+		while ($r = $db->fetch($res)) {
+			$tableProcesInitList[$r->ID] = $r->DESC;
+		}
+		return $tableProcesInitList;
+	}
+
+	public function canExecuteProcesInit($idProcesInit) {
+		$canExecuteProcesInit = false;
+		$idProcesInit = (int)$idProcesInit;
+		if (!$idProcesInit) return false;
+		$idUserGroupList = User::getGroupsIds();
+		$sqlIdUserGroupList = implode(",", $idUserGroupList);
+		$checkProcesAccessSql = <<<SQL
+			select count(*) as cnt
+				from `CRM_PROCES_idx_GROUP_to_PROCES` gi
+					join `CRM_PROCES` p on(p.`ID`=gi.`ID_PROCES` and p.`TYPE`='PROCES_INIT')
+				where gi.`ID_GROUP` in({$sqlIdUserGroupList})
+					and gi.`ID_PROCES`='{$idProcesInit}'
+SQL;
+		$db = DB::getDB();
+		$res = $db->query($checkProcesAccessSql);
+		if ($r = $db->fetch($res)) {
+			if ($r->cnt > 0) {
+				$canExecuteProcesInit = true;
+			}
+		}
+		return $canExecuteProcesInit;
+	}
+
 }

+ 26 - 1
SE/superedit-PROCES_MENU.php

@@ -102,7 +102,32 @@ function PROCES_MENU() {
 		case 'PROCES_FOR_TABLE': {
 			$tblId = V::get('tblId', 0, $_REQUEST, 'int');
 			$userAcl = User::getAcl();
-			$usedProcesInitIds = $userAcl->getUsedProcesInitIds($tblId);
+			$tableProcesInitIds = $userAcl->getTableProcesInitIds($tblId);
+			$tableProcesIdsCSV = implode(",", $tableProcesInitIds);
+			$url = $_SERVER['SCRIPT_URI'];
+			$url = substr($url, 0, strrpos($url, '/'));
+			$url .= "/procesy5.php?task=CRM_PROCES&filtr_id={$tableProcesIdsCSV}&filtr_ids=%2B&filtr_ob=%2B&filtr_img=%2B";
+			//echo $url; exit;
+			if (!headers_sent()) {
+				header('HTTP/1.1 303 See Other');
+				header('Location: '.$url);
+			} else {
+				?>
+				<script type="text/javascript">
+	window.location.href='<?php echo $url; ?>';
+				</script>
+				<noscript>
+					<meta http-equiv="refresh" content="0;url=<?php echo $url; ?>" />
+				</noscript>
+				<p><a href="<?php echo $url; ?>">dalej</a></p>
+				<?php
+			}
+			exit;
+		}
+		case 'PROCES_FOR_USER': {
+			// 							<a href="procesy5.php?task=CRM_PROCES echo "&filtr_id={$userProcesIdsCSV}&filtr_ids=%2B&filtr_ob=%2B&filtr_img=%2B";  ">Moje Procesy</a>
+			$userAcl = User::getAcl();
+			$usedProcesInitIds = $userAcl->getUserProcesInitIds();
 			//print_r($usedProcesInitIds);
 			$userProcesIdsCSV = implode(",", $usedProcesInitIds);
 			$url = $_SERVER['SCRIPT_URI'];