AclHelper.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. Lib::loadClass('Api_WfsNs');
  3. Lib::loadClass('ProcesHelper');
  4. Lib::loadClass('Router');
  5. Lib::loadClass('Route_UrlAction');
  6. class Core_AclHelper {// Helper class for Acl
  7. public static function hasCreatePerms($acl) {
  8. foreach ($acl->getFieldListByIdZasob() as $fieldName) {// TODO: use getFieldList
  9. // echo"<p>\$acl->canCreateField({$fieldName}): (".$acl->canCreateField($fieldName).")</p>";
  10. if ($acl->canCreateField($fieldName)) return true;
  11. }
  12. return false;
  13. }
  14. public static function hasGeomFields($acl) {
  15. foreach ($acl->getFieldListByIdZasob() as $fieldName) {
  16. // echo"<p>\$acl->isGeomField({$fieldName}): (".$acl->isGeomField($fieldName).") \$acl->canReadField({$fieldName}): (".$acl->canReadField($fieldName).")</p>";
  17. if ($acl->isGeomField($fieldName) && $acl->canReadField($fieldName)) return true;
  18. }
  19. return false;
  20. }
  21. // @returns array [ field => string(perms like 'RWX') ]
  22. public static function getFieldPerms($acl) {// TODO: fetch perms for given Acl by namespace
  23. // TODO:? cache session or only current request (static)
  24. $fieldPerms = array();
  25. foreach ($acl->getFields() as $idField => $field) {
  26. $fieldPerms[ $field['name'] ] = $field['perms'];
  27. }
  28. return $fieldPerms;
  29. }
  30. public static function getExportFieldList($acl) {
  31. $exportFields = array();
  32. foreach (self::getFieldPerms($acl) as $fieldName => $perms) {
  33. if (false !== strpos($perms, 'E')) {
  34. $exportFields[] = $fieldName;
  35. }
  36. }
  37. return $exportFields;
  38. }
  39. public static function getAclByTypeName($typeName, $forceTblAclInit = false) {// TODO: replace getAclFromTypeName in WFS
  40. return self::getAclByNamespace(str_replace(':', '/', $typeName), $forceTblAclInit);
  41. }
  42. public static function getAclByNamespace($namespace, $forceTblAclInit = false) {
  43. if ('http' != substr($namespace, 0, 4)) $namespace = Api_WfsNs::getBaseWfsUri() . '/' . $namespace;//Request::getHostUri() . '/' . $namespace;
  44. $baseNsUri = Api_WfsNs::getBaseWfsUri();
  45. if ("{$baseNsUri}/" == substr($namespace, 0, strlen($baseNsUri) + 1)) {
  46. $schemaNs = substr($namespace, strlen($baseNsUri) + 1);
  47. $ns = explode('/', $schemaNs);// "http://biuro.biall-net.pl/wfs/ default_db/{$nazwa_tabeli}/{$nazwa_obj}
  48. $sourceName = array_shift($ns);// remove first element - source name
  49. $objName = $ns[0];
  50. if ('default_db' == $sourceName || 'p5_default_db' == $sourceName) {
  51. $sourceName = 'default_db';
  52. if (1 == count($ns)) {
  53. $acl = User::getAcl()->getObjectAcl($sourceName, $objName);
  54. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  55. $acl->init($forceTblAclInit);
  56. return $acl;
  57. } else if (2 == count($ns)) {
  58. throw new Exception("TODO: default_db: '{$schemaNs}' ns:[ ".implode(", ", $ns)." ]", 501);
  59. } else throw new Exception("Nieznany namespace default_db: '{$schemaNs}'", 501);
  60. }
  61. else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName || 'p5_objects' == $sourceName) {
  62. $sourceName = 'objects';
  63. if (1 == count($ns)) {
  64. $acl = User::getAcl()->getObjectAcl($sourceName, $objName);
  65. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  66. $acl->init($forceTblAclInit);
  67. return $acl;
  68. } else throw new Exception("Nieznany namespace SystemObjects: '{$schemaNs}'", 501);
  69. }
  70. else if ('default_objects__x3A__' == substr($sourceName, 0, 22)) {// default_objects__x3A__Zaliczka:Zaliczka
  71. $sourceName = 'objects';
  72. if (1 == count($ns)) {
  73. $acl = User::getAcl()->getObjectAcl($sourceName, $objName);
  74. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  75. $acl->init($forceTblAclInit);
  76. return $acl;
  77. } else throw new Exception("Nieznany namespace SystemObjects: '{$schemaNs}'", 501);
  78. }
  79. else if ('zasob_' == substr($sourceName, 0, 6)) {
  80. $dbName = substr($sourceName, 6);
  81. throw new Exception("TODO db[{$dbName}] namespace '{$schemaNs}'", 501);
  82. }
  83. else throw new Exception("Nieznany namespace '{$schemaNs}'", 501);
  84. }
  85. else throw new HttpException("Zasoby zewnętrzenj systemu nie są jeszcze zaimplementowane", 501);
  86. throw new HttpException("TODO L.".__LINE__." ns({$namespace})", 501);
  87. }
  88. public static function getMoreFunctionsCell($acl, $args) {
  89. $id = V::get('primary_key', 0, $args, 'int');
  90. if ($id <= 0) throw new HttpException("404", 404);
  91. $record = V::get('record', null, $args);
  92. $rowFunList = array();
  93. $tableName = $acl->getName();
  94. $record = ($record)? $record : $acl->getItem($id);
  95. if(1){// TODO: fetch $totalMsgs from TableMsgs
  96. $msgs = Router::getRoute('Msgs');
  97. $msgsList = $msgs->getActiveMessagesForTableRecord($tableName, $id);
  98. $totalMsgs = count($msgsList);
  99. $rowFunc = new stdClass();
  100. $rowFunc->id = 'msgs';
  101. $rowFunc->ico = 'glyphicon glyphicon-envelope';
  102. $rowFunc->href = 'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $acl->getID() . '&idRow=' . $id;
  103. $rowFunc->title = "Wiadomości ({$totalMsgs})";
  104. $rowFunc->label = "Wiadomości <span class=\"badge\">{$totalMsgs}</span>";
  105. $rowFunList[] = $rowFunc;
  106. }
  107. if ('CRM_PROCES' == $acl->getName()) {// TODO: mv to table gui xml or php class
  108. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  109. $rowFunc = new stdClass();
  110. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  111. $rowFunc->href = "procesy5.php?task=CRM_PROCES&filtr_id={$id}";
  112. $rowFunc->title = "Zobacz na drzewie procesów {{$id}}";
  113. $rowFunList[] = $rowFunc;
  114. $wskazniki = ProcesHelper::get_wskazniki($id);
  115. $connectedZasobyTotal = count($wskazniki);
  116. $rowFunc = new stdClass();
  117. $rowFunc->ico = 'glyphicon glyphicon-random';
  118. $rowFunc->href = "index.php?MENU_INIT=PROCES_ADD_ZASOB&procesID={$id}";
  119. $rowFunc->title = "Powiązane zasoby <span class=\"badge\">{$connectedZasobyTotal}</span>";
  120. $rowFunList[] = $rowFunc;
  121. }
  122. if ('CRM_LISTA_ZASOBOW' == $acl->getName()) {// TODO: mv to table gui xml or php class
  123. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  124. $rowFunc = new stdClass();
  125. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  126. $rowFunc->href = "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$id}";
  127. $rowFunc->title = "Zobacz na drzewie zasobów [{$id}]";
  128. $rowFunList[] = $rowFunc;
  129. // index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob=22001
  130. $rowFunc = new stdClass();
  131. $rowFunc->ico = 'glyphicon glyphicon-random';
  132. $rowFunc->href = "index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob={$id}";
  133. $rowFunc->title = "Powiązane procesy (OB)";
  134. $rowFunList[] = $rowFunc;
  135. // index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob=22001
  136. $rowFunc = new stdClass();
  137. $rowFunc->ico = 'glyphicon glyphicon-random';
  138. $rowFunc->href = "index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob={$id}";
  139. $rowFunc->title = "Powiązane dane (IDS)";
  140. $rowFunList[] = $rowFunc;
  141. $groupTypeList = array();
  142. $groupTypeList[] = 'STANOWISKO';
  143. $groupTypeList[] = 'PODMIOT';
  144. $groupTypeList[] = 'DZIAL';
  145. if (in_array($record->TYPE, $groupTypeList)) {
  146. $rowFunc = new stdClass();
  147. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  148. $rowFunc->href = "index.php?_route=Users&_task=syncGroup&idGroup={$id}";
  149. $rowFunc->title = "Synchronizuj do LDAP";
  150. $rowFunList[] = $rowFunc;
  151. }
  152. }
  153. if ('ADMIN_USERS' == $acl->getName()) {// TODO: mv to table gui xml
  154. if ($acl->canReadRecord($record) && $acl->canReadObjectField('ADM_ACCOUNT', $record)) {
  155. $rowFunc = new stdClass();
  156. $rowFunc->ico = 'glyphicon glyphicon-user';
  157. $rowFunc->href = 'index.php?_route=Users&_task=userGroups&usrLogin=' . $record->ADM_ACCOUNT;
  158. $rowFunc->title = "Ustal stanowisko";
  159. $rowFunList[] = $rowFunc;
  160. $rowFunc = new stdClass();
  161. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  162. $rowFunc->href = 'index.php?_route=Users&_task=syncUser&usrLogin=' . $record->ADM_ACCOUNT;
  163. $rowFunc->title = "Synchronizuj do LDAP";
  164. $rowFunList[] = $rowFunc;
  165. $rowFunc = new stdClass();
  166. $rowFunc->ico = 'glyphicon glyphicon-minus';
  167. $rowFunc->href = 'index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=' . $record->ADM_ACCOUNT;
  168. $rowFunc->title = "Ocena pracownika";
  169. $rowFunList[] = $rowFunc;
  170. }
  171. }
  172. if ($urlFunctions = Route_UrlAction::getTableFunctions($acl->getID(), $id, $acl->getName(), User::getLogin())) {
  173. foreach ($urlFunctions as $urlFunction) {
  174. // TODO: is allowed to view - test by Router::getRoute('UrlAction')->isFunctionAllowedForRecord($routeName = $urlFunction['name'], $acl->getID(), $id);
  175. $rowFunction = array();
  176. $rowFunction['href'] = $urlFunction['baseLink'];
  177. $rowFunction['ico'] = V::get('ico', 'glyphicon glyphicon-share', $urlFunction);
  178. $rowFunction['label'] = $urlFunction['label'];
  179. $rowFunction['title'] = V::get('title', $urlFunction['label'], $urlFunction);
  180. if (!empty($urlFunction['link_target'])) $rowFunction['target'] = $urlFunction['link_target'];
  181. if (!empty($urlFunction['cell_id_params'])) {
  182. $urlParams = array();// [ "{$urlParamName}={$paramValue}" ]
  183. foreach ($urlFunction['cell_id_params'] as $idField => $urlParamName) {
  184. $paramValue = '';
  185. $fld = $acl->getField($idField);
  186. if ($fld) {
  187. $fldName = $fld['name'];
  188. $paramValue = V::get($fldName, '', $record);
  189. $urlParams[] = "{$urlParamName}={$paramValue}";
  190. }
  191. }
  192. if (!empty($urlParams)) $rowFunction['href'] .= "&" . implode("&", $urlParams);
  193. }
  194. $rowFunList[] = $rowFunction;
  195. }
  196. }
  197. return $rowFunList;
  198. }
  199. public static function getAclList() {// @usage Core_AclHelper::getAclList();// @returns array [ $typeName , ... ]
  200. $aclList = array();
  201. // Schema_AccessGroupStorageAcl, load by User::getAcl()->getObjectAcl('objects', $objName);
  202. // $objClassName = "Schema_{$objName}StorageAcl";
  203. // if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented", 501);
  204. // $ grep -r 'class ' SE/se-lib/Schema/*Acl.php
  205. // SE/se-lib/Schema/AccessGroupStorageAcl.php:class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
  206. // SE/se-lib/Schema/AccessOwnerStorageAcl.php:class Schema_AccessOwnerStorageAcl extends Core_AclBase {
  207. // SE/se-lib/Schema/FileStorageAcl.php:class Schema_FileStorageAcl extends Core_AclBase {
  208. // SE/se-lib/Schema/KorespondencjaStorageAcl.php:class Schema_KorespondencjaStorageAcl extends Core_AclBase {
  209. // SE/se-lib/Schema/TestPermsStorageAcl.php:class Schema_TestPermsStorageAcl extends Core_AclBase {
  210. $aclList[] = 'default_objects:AccessGroupRead';
  211. $aclList[] = 'default_objects:AccessGroupWrite';
  212. $aclList[] = 'default_objects:AccessOwner';
  213. $aclList[] = 'default_objects:File';
  214. $aclList[] = 'default_objects:Korespondencja';
  215. $aclList[] = 'default_objects:TestPerms';
  216. // TODO: read from Database
  217. // $aclList[] = 'default_db__x3A__TEST_PERMS:TEST_PERMS';// uproszczona wersja: default_db:TEST_PERMS
  218. $cleanHostName = str_replace(array(".", "-"), '_', $_SERVER['SERVER_NAME']);
  219. if (file_exists(APP_PATH_SCHEMA . "/gui/company/{$cleanHostName}/get_object_list.php")) {
  220. $objList = include APP_PATH_SCHEMA . "/gui/company/{$cleanHostName}/get_object_list.php";
  221. if (!empty($objList) && is_array($objList)) {
  222. foreach ($objList as $objectName) {
  223. if (!in_array($objectName, $aclList)) $aclList[] = $objectName;
  224. }
  225. }
  226. }
  227. return $aclList;
  228. }
  229. }