AccessGroupStorageAcl.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. Lib::loadClass('Core_AclBase');
  3. Lib::loadClass('User');
  4. Lib::loadClass('UsersHelper');
  5. class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
  6. public function getSourceName() { return 'objects'; }
  7. public function init($force = false) {}
  8. public function isInitialized() { return true; }
  9. public function getName() { return 'AccessGroup'; }
  10. public function getRootTableName() { return 'CRM_LISTA_ZASOBOW'; }
  11. public function getRealFieldListByIdZasob($force = false) {
  12. $cols[100000] = 'id';// CRM_LISTA_ZASOBOW.ID
  13. $cols[100001] = 'name';// CRM_LISTA_ZASOBOW.DESC
  14. $cols[100002] = 'uid';// Ldap.uid -> value stored in fields: A_ADM_COMPANY, A_CLASSIFIED
  15. return $cols;
  16. }
  17. public function getFields() { return array_values($this->getRealFieldListByIdZasob()); }
  18. public function getFieldType($fieldName) { return null; }
  19. // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
  20. public function canCreateField($fieldName) { return false; }
  21. public function canReadField($fieldName) { return true; }
  22. public function canReadObjectField($fieldName, $record) {return true; }
  23. public function canWriteField($fieldName) { return false; }
  24. public function canWriteObjectField($fieldName, $record) { return false; }
  25. public function getItems($params = array()) {
  26. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  27. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
  28. $items = array();
  29. // TODO: fetch groups connectes with current user
  30. {
  31. $userLdapGroups = UsersHelper::getLDAPGroupByUserName(User::getLogin());
  32. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$userLdapGroups:";print_r($userLdapGroups);echo "\n";}
  33. if (empty($userLdapGroups)) throw new Exception("User groups not found", 404);
  34. foreach ($userLdapGroups as $vLdapGroup) {
  35. $allowGroup = false;
  36. if ('workgroup' == $vLdapGroup->cn) {
  37. $items[1] = ['id'=>0, 'name'=>$vLdapGroup->cn, 'uid'=>$vLdapGroup->cn];
  38. } else {
  39. $cnTest = str_replace('-', '_', $vLdapGroup->cn);
  40. $cnTest = explode('_', $cnTest);
  41. $idZasob = $cnTest[0];
  42. if (!is_numeric($idZasob)) {
  43. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems - skip cn - missing id zasob \$vLdapGroup->cn:";print_r($vLdapGroup->cn);echo "\n";}
  44. continue;
  45. }
  46. $items[$idZasob] = ['id'=>$idZasob, 'name'=>$vLdapGroup->cn, 'uid'=>$vLdapGroup->cn];
  47. }
  48. }
  49. }
  50. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  51. return $items;
  52. }
  53. public function addItem($itemTodo) { throw new Exception("Insert not allowed"); }
  54. public function updateItem($itemPatch) { throw new Exception("Update not allowed"); }
  55. public function getGeomFieldType($fieldName) { return null; }
  56. public function getPrimaryKeyField() { return 'id'; }
  57. public function getID() { return 0; }
  58. public function getAttributesFromZasoby() { return array(); }
  59. public function isEnumerationField($fieldName) { return false; }
  60. public function getEnumerations($fieldName) { return null; }
  61. public function getXsdFieldType($fieldName) {
  62. if ('id' == $fieldName) return 'xsd:string';
  63. if ('name' == $fieldName) return 'xsd:string';
  64. if ('uid' == $fieldName) return 'xsd:string';
  65. }
  66. public function isGeomField($fldName) { return false; }
  67. }