Piotr Labudda 8 лет назад
Родитель
Сommit
9bbb3a8d97
1 измененных файлов с 144 добавлено и 0 удалено
  1. 144 0
      SE/se-lib/Route/Storage.php

+ 144 - 0
SE/se-lib/Route/Storage.php

@@ -862,6 +862,145 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 		UI::dol();
 	}
 
+	public function aclUsageAction() {
+		UI::gora();
+		UI::menu();
+		UI::startContainer();
+		try {
+			$namespace = V::get('namespace', '', $_GET, 'word');
+			if (!$namespace) {
+				$typeName = V::get('typeName', '', $_GET, 'word');
+				if (!$typeName) throw new Exception("Wrong param typeName");
+				$namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
+			}
+			$acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
+
+			$tableName = $acl->getName();
+			$idTable = $acl->getID();
+
+			UI::tag('h2', [], "Uprawnienia tabeli '{$tableName}'");
+			UI::tag('p', [], "ID Zasobu [{$idTable}]");
+			if ($idTable > 0) {
+				$aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
+				UI::startTag('details');
+				echo UI::h('summary', ['style'=>"cursor:pointer"], "Wszystkie powiązania komórek z procesami - szczegóły");
+				UI::table([
+					'rows' => array_map(function ($row) {
+						$splitPos = strpos($row['TABLE_DESCRIPTION'], ' ', 20);
+						if ($splitPos > 30) $splitPos = 20;
+						$row['TABLE_DESCRIPTION'] = UI::h('details', [], [
+							UI::h('summary', [ 'style' => "white-space:nowrap" ], substr($row['TABLE_DESCRIPTION'], 0, $splitPos)),
+							UI::h('p', [], substr($row['TABLE_DESCRIPTION'], $splitPos)),
+						]);
+						return $row;
+					}, $aclTableRows)
+				]);
+				UI::endTag('details');
+
+				$csvIdProces = array();
+				foreach ($aclTableRows as $row) {
+					if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
+				}
+			}
+
+			$databaseName = DB::getPDO()->getDatabaseName();
+			UI::table([
+				'caption' => "Powiązania komórek z procesem",
+				'rows' => array_map(
+					function ($row) use ($aclTableRows, $idTable) {
+						$fieldName = $row['COLUMN_NAME'];
+						$item = [];
+						$item['name'] = $fieldName;
+						$item['typ'] = UI::h('details', [], [
+							UI::h('summary', ['style'=>"cursor:pointer"], $row['DATA_TYPE']),
+							UI::h('p', [], $row['COLUMN_TYPE']),
+						]);
+						$item['proces'] = array();
+						$item['id_zasob'] = 0;
+						$item['PERM_R'] = 0;
+						$item['PERM_W'] = 0;
+						$item['PERM_X'] = 0;
+						$item['PERM_C'] = 0;
+						$item['PERM_S'] = 0;
+						$item['PERM_O'] = 0;
+						$item['PERM_V'] = 0;
+						$item['PERM_E'] = 0;
+						foreach ($aclTableRows as $aclInfo) {
+							if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
+								$item['proces'][] = $aclInfo['ID_PROCES'];
+								$item['id_zasob'] = $aclInfo['ID_CELL'];
+								$item['PERM_R'] += $aclInfo['PERM_R'];
+								$item['PERM_W'] += $aclInfo['PERM_W'];
+								$item['PERM_X'] += $aclInfo['PERM_X'];
+								$item['PERM_C'] += $aclInfo['PERM_C'];
+								$item['PERM_S'] += $aclInfo['PERM_S'];
+								$item['PERM_O'] += $aclInfo['PERM_O'];
+								$item['PERM_V'] += $aclInfo['PERM_V'];
+								$item['PERM_E'] += $aclInfo['PERM_E'];
+							}
+						}
+						$item['proces'] = (empty($item['proces']))
+							? "<i style=\"color:red\">Brak</i>"
+							: UI::h('span', ['style'=>"white-space:nowrap"], implode(", ", $item['proces']));
+						if (!$item['id_zasob']) $item['id_zasob'] = DB::getPDO()->fetchValue("select ID from CRM_LISTA_ZASOBOW where `DESC` = '{$fieldName}' and PARENT_ID = {$idTable} limit 1");
+						return $item;
+					}, DB::getPDO()->fetchAll("
+						select t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
+						from `information_schema`.`COLUMNS` t
+						where t.TABLE_SCHEMA = '{$databaseName}'
+							and t.TABLE_NAME like '{$tableName}'
+					")
+				)
+			]);
+
+			if (!empty($csvIdProces)) {
+				$userLogin = User::getLogin();
+				$csvIdProces = implode(",", $csvIdProces);
+				UI::tag('h4', [], "Procesy dla '{$userLogin}': [{$csvIdProces}] <small><i>(z tabeli CRM_PROCES_idx_USER_to_PROCES_VIEW)</i></small>");
+				$rows = DB::getPDO()->fetchAll("
+					select ID_PROCES
+					from `CRM_PROCES_idx_USER_to_PROCES_VIEW`
+					where ADM_ACCOUNT = '{$userLogin}'
+						and ID_PROCES in({$csvIdProces})
+					group by ID_PROCES
+				");
+				// UI::table([
+				// 	'caption' => "Procesy dla '{$userLogin}' <small>CRM_PROCES_idx_USER_to_PROCES_VIEW</small>",
+				// 	'rows' => $rows
+				// ]);
+				$userIdProces = array(); foreach ($rows as $row) $userIdProces[] = $row['ID_PROCES'];
+				$userTablePerms = array();
+				foreach ($aclTableRows as $row) {
+					if (!in_array($row['ID_PROCES'], $userIdProces)) continue;
+					if (array_key_exists($row['CELL_NAME'], $userTablePerms)) {
+						$userTablePerms[ $row['CELL_NAME'] ][ 'PERM_R' ] += $row['PERM_R'];
+						$userTablePerms[ $row['CELL_NAME'] ][ 'PERM_W' ] += $row['PERM_W'];
+						$userTablePerms[ $row['CELL_NAME'] ][ 'PERM_X' ] += $row['PERM_X'];
+						$userTablePerms[ $row['CELL_NAME'] ][ 'PERM_C' ] += $row['PERM_C'];
+						$userTablePerms[ $row['CELL_NAME'] ][ 'PERM_S' ] += $row['PERM_S'];
+						$userTablePerms[ $row['CELL_NAME'] ][ 'PERM_O' ] += $row['PERM_O'];
+						$userTablePerms[ $row['CELL_NAME'] ][ 'PERM_V' ] += $row['PERM_V'];
+						$userTablePerms[ $row['CELL_NAME'] ][ 'PERM_E' ] += $row['PERM_E'];
+					} else {
+						$userTablePerms[ $row['CELL_NAME'] ] = $row;
+						unset($userTablePerms[ $row['CELL_NAME'] ][ 'TABLE_DESCRIPTION' ]);
+						unset($userTablePerms[ $row['CELL_NAME'] ][ 'ID_PROCES' ]);
+						unset($userTablePerms[ $row['CELL_NAME'] ][ 'FORM_TREAT' ]);
+					}
+				}
+				UI::table([
+					'caption' => "Uprawniena dla usera '{$userLogin}'",
+					'rows' => $userTablePerms
+				]);
+			} else UI::alert('warning', "brak \$csvIdProces");
+		} catch (Exception $e) {
+			UI::alert('danger', $e->getMessage());
+			DBG::log($e);
+		}
+		UI::endContainer();
+		UI::dol();
+	}
+
 	public function tableStructAction() {
 		UI::gora();
 		UI::menu();
@@ -974,6 +1113,11 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 						'class' => "btn btn-md btn-link",
 						'title' => "Procesy dla aktualnie przeglądanej tabeli"
 					], "Procesy"),
+					UI::h('a', [
+						'href' => $this->getLink('aclUsage', [ 'namespace' => "default_db/{$tblName}" ]),
+						'class' => "btn btn-md btn-link",
+						'title' => "Uprawnienia - analiza użycia komórek w procesach"
+					], "Uprawnienia (analiza użycia)"),
 				]),
 				'cols' => array_keys($emptyItem),
 				'rows' => $tableList