AccessGroupStorageAcl.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 ($pk = V::get('primaryKey', '', $params, 'int')) {// [primaryKey] => 2948
  53. if (!array_key_exists($pk, $items)) return array();
  54. return array($pk => $items[$pk]);
  55. }
  56. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  57. return $items;
  58. }
  59. public function addItem($itemTodo) { throw new Exception("Insert not allowed"); }
  60. public function updateItem($itemPatch) { throw new Exception("Update not allowed"); }
  61. public function getGeomFieldType($fieldName) { return null; }
  62. public function getPrimaryKeyField() { return 'id'; }
  63. public function getID() { return 0; }
  64. public function getAttributesFromZasoby() { return array(); }
  65. public function isEnumerationField($fieldName) { return false; }
  66. public function getEnumerations($fieldName) { return null; }
  67. public function getXsdFieldType($fieldName) {
  68. if ('id' == $fieldName) return 'xsd:string';
  69. if ('name' == $fieldName) return 'xsd:string';
  70. if ('uid' == $fieldName) return 'xsd:string';
  71. }
  72. public function isGeomField($fldName) { return false; }
  73. }