AclHelper.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 getAclByNamespace($namespace, $forceTblAclInit = false) {
  40. if ('http' != substr($namespace, 0, 4)) $namespace = Api_WfsNs::getBaseWfsUri() . '/' . $namespace;//Request::getHostUri() . '/' . $namespace;
  41. $baseNsUri = Api_WfsNs::getBaseWfsUri();
  42. if ("{$baseNsUri}/" == substr($namespace, 0, strlen($baseNsUri) + 1)) {
  43. $schemaNs = substr($namespace, strlen($baseNsUri) + 1);
  44. $ns = explode('/', $schemaNs);// "http://biuro.biall-net.pl/wfs/ default_db/{$nazwa_tabeli}/{$nazwa_obj}
  45. $sourceName = array_shift($ns);// remove first element - source name
  46. if ('default_db' == $sourceName || 'p5_default_db' == $sourceName) {
  47. $sourceName = 'default_db';
  48. $objName = $ns[0];
  49. if (1 == count($ns)) {
  50. $acl = User::getAcl()->getObjectAcl($sourceName, $objName);
  51. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  52. $acl->init($forceTblAclInit);
  53. return $acl;
  54. } else if (2 == count($ns)) {
  55. throw new Exception("TODO: default_db: '{$schemaNs}' ns:[ ".implode(", ", $ns)." ]", 501);
  56. } else throw new Exception("Nieznany namespace default_db: '{$schemaNs}'", 501);
  57. }
  58. else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName || 'p5_objects' == $sourceName) {
  59. $sourceName = 'objects';
  60. $objName = $ns[0];
  61. if (1 == count($ns)) {
  62. $acl = User::getAcl()->getObjectAcl($sourceName, $objName);
  63. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  64. $acl->init($forceTblAclInit);
  65. return $acl;
  66. } else throw new Exception("Nieznany namespace SystemObjects: '{$schemaNs}'", 501);
  67. }
  68. else if ('zasob_' == substr($sourceName, 0, 6)) {
  69. $dbName = substr($sourceName, 6);
  70. throw new Exception("TODO db[{$dbName}] namespace '{$schemaNs}'", 501);
  71. }
  72. else throw new Exception("Nieznany namespace '{$schemaNs}'", 501);
  73. }
  74. else throw new HttpException("Zasoby zewnętrzenj systemu nie są jeszcze zaimplementowane", 501);
  75. throw new HttpException("TODO L.".__LINE__." ns({$namespace})", 501);
  76. }
  77. public static function getMoreFunctionsCell($acl, $args) {
  78. $id = V::get('primary_key', 0, $args, 'int');
  79. if ($id <= 0) throw new HttpException("404", 404);
  80. $record = V::get('record', null, $args);
  81. $rowFunList = array();
  82. $tableName = $acl->getName();
  83. $record = ($record)? $record : $acl->getItem($id);
  84. if(1){// TODO: fetch $totalMsgs from TableMsgs
  85. $msgs = Router::getRoute('Msgs');
  86. $msgsList = $msgs->getActiveMessagesForTableRecord($tableName, $id);
  87. $totalMsgs = count($msgsList);
  88. $rowFunc = new stdClass();
  89. $rowFunc->id = 'msgs';
  90. $rowFunc->ico = 'glyphicon glyphicon-envelope';
  91. $rowFunc->href = 'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $acl->getID() . '&idRow=' . $id;
  92. $rowFunc->title = "Wiadomości ({$totalMsgs})";
  93. $rowFunc->label = "Wiadomości <span class=\"badge\">{$totalMsgs}</span>";
  94. $rowFunList[] = $rowFunc;
  95. }
  96. if ('CRM_PROCES' == $acl->getName()) {// TODO: mv to table gui xml or php class
  97. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  98. $rowFunc = new stdClass();
  99. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  100. $rowFunc->href = "procesy5.php?task=CRM_PROCES&filtr_id={$id}";
  101. $rowFunc->title = "Zobacz na drzewie procesów {{$id}}";
  102. $rowFunList[] = $rowFunc;
  103. $wskazniki = ProcesHelper::get_wskazniki($id);
  104. $connectedZasobyTotal = count($wskazniki);
  105. $rowFunc = new stdClass();
  106. $rowFunc->ico = 'glyphicon glyphicon-random';
  107. $rowFunc->href = "index.php?MENU_INIT=PROCES_ADD_ZASOB&procesID={$id}";
  108. $rowFunc->title = "Powiązane zasoby <span class=\"badge\">{$connectedZasobyTotal}</span>";
  109. $rowFunList[] = $rowFunc;
  110. }
  111. if ('CRM_LISTA_ZASOBOW' == $acl->getName()) {// TODO: mv to table gui xml or php class
  112. // procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
  113. $rowFunc = new stdClass();
  114. $rowFunc->ico = 'glyphicon glyphicon-eye-open';
  115. $rowFunc->href = "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$id}";
  116. $rowFunc->title = "Zobacz na drzewie zasobów [{$id}]";
  117. $rowFunList[] = $rowFunc;
  118. // index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob=22001
  119. $rowFunc = new stdClass();
  120. $rowFunc->ico = 'glyphicon glyphicon-random';
  121. $rowFunc->href = "index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob={$id}";
  122. $rowFunc->title = "Powiązane procesy (OB)";
  123. $rowFunList[] = $rowFunc;
  124. // index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob=22001
  125. $rowFunc = new stdClass();
  126. $rowFunc->ico = 'glyphicon glyphicon-random';
  127. $rowFunc->href = "index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob={$id}";
  128. $rowFunc->title = "Powiązane dane (IDS)";
  129. $rowFunList[] = $rowFunc;
  130. $groupTypeList = array();
  131. $groupTypeList[] = 'STANOWISKO';
  132. $groupTypeList[] = 'PODMIOT';
  133. $groupTypeList[] = 'DZIAL';
  134. if (in_array($record->TYPE, $groupTypeList)) {
  135. $rowFunc = new stdClass();
  136. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  137. $rowFunc->href = "index.php?_route=Users&_task=syncGroup&idGroup={$id}";
  138. $rowFunc->title = "Synchronizuj do LDAP";
  139. $rowFunList[] = $rowFunc;
  140. }
  141. }
  142. if ('ADMIN_USERS' == $acl->getName()) {// TODO: mv to table gui xml
  143. if ($acl->canReadRecord($record) && $acl->canReadObjectField('ADM_ACCOUNT', $record)) {
  144. $rowFunc = new stdClass();
  145. $rowFunc->ico = 'glyphicon glyphicon-user';
  146. $rowFunc->href = 'index.php?_route=Users&_task=userGroups&usrLogin=' . $record->ADM_ACCOUNT;
  147. $rowFunc->title = "Ustal stanowisko";
  148. $rowFunList[] = $rowFunc;
  149. $rowFunc = new stdClass();
  150. $rowFunc->ico = 'glyphicon glyphicon-retweet';
  151. $rowFunc->href = 'index.php?_route=Users&_task=syncUser&usrLogin=' . $record->ADM_ACCOUNT;
  152. $rowFunc->title = "Synchronizuj do LDAP";
  153. $rowFunList[] = $rowFunc;
  154. $rowFunc = new stdClass();
  155. $rowFunc->ico = 'glyphicon glyphicon-minus';
  156. $rowFunc->href = 'index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=' . $record->ADM_ACCOUNT;
  157. $rowFunc->title = "Ocena pracownika";
  158. $rowFunList[] = $rowFunc;
  159. }
  160. }
  161. if ($urlFunctions = Route_UrlAction::getTableFunctions($acl->getID(), $id, $acl->getName(), User::getLogin())) {
  162. foreach ($urlFunctions as $urlFunction) {
  163. // TODO: is allowed to view - test by Router::getRoute('UrlAction')->isFunctionAllowedForRecord($routeName = $urlFunction['name'], $acl->getID(), $id);
  164. $rowFunction = array();
  165. $rowFunction['href'] = $urlFunction['baseLink'];
  166. $rowFunction['ico'] = V::get('ico', 'glyphicon glyphicon-share', $urlFunction);
  167. $rowFunction['label'] = $urlFunction['label'];
  168. $rowFunction['title'] = V::get('title', $urlFunction['label'], $urlFunction);
  169. if (!empty($urlFunction['link_target'])) $rowFunction['target'] = $urlFunction['link_target'];
  170. if (!empty($urlFunction['cell_id_params'])) {
  171. $urlParams = array();// [ "{$urlParamName}={$paramValue}" ]
  172. foreach ($urlFunction['cell_id_params'] as $idField => $urlParamName) {
  173. $paramValue = '';
  174. $fld = $acl->getField($idField);
  175. if ($fld) {
  176. $fldName = $fld['name'];
  177. $paramValue = V::get($fldName, '', $record);
  178. $urlParams[] = "{$urlParamName}={$paramValue}";
  179. }
  180. }
  181. if (!empty($urlParams)) $rowFunction['href'] .= "&" . implode("&", $urlParams);
  182. }
  183. $rowFunList[] = $rowFunction;
  184. }
  185. }
  186. return $rowFunList;
  187. }
  188. public static function getAclList() {// @usage Core_AclHelper::getAclList();// @returns array [ $typeName , ... ]
  189. $aclList = array();
  190. // Schema_AccessGroupStorageAcl, load by User::getAcl()->getObjectAcl('objects', $objName);
  191. // $objClassName = "Schema_{$objName}StorageAcl";
  192. // if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented", 501);
  193. // $ grep -r 'class ' SE/se-lib/Schema/*Acl.php
  194. // SE/se-lib/Schema/AccessGroupStorageAcl.php:class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
  195. // SE/se-lib/Schema/AccessOwnerStorageAcl.php:class Schema_AccessOwnerStorageAcl extends Core_AclBase {
  196. // SE/se-lib/Schema/FileStorageAcl.php:class Schema_FileStorageAcl extends Core_AclBase {
  197. // SE/se-lib/Schema/KorespondencjaStorageAcl.php:class Schema_KorespondencjaStorageAcl extends Core_AclBase {
  198. // SE/se-lib/Schema/TestPermsStorageAcl.php:class Schema_TestPermsStorageAcl extends Core_AclBase {
  199. $aclList[] = 'default_objects:AccessGroup';
  200. $aclList[] = 'default_objects:AccessOwner';
  201. $aclList[] = 'default_objects:File';
  202. $aclList[] = 'default_objects:Korespondencja';
  203. $aclList[] = 'default_objects:TestPerms';
  204. // TODO: read from Database
  205. // $aclList[] = 'default_db__x3A__TEST_PERMS:TEST_PERMS';// uproszczona wersja: default_db:TEST_PERMS
  206. return $aclList;
  207. }
  208. }