AccessGroupStorageAcl.php 3.5 KB

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