AclHelper.php 10 KB

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