TestPermsStorageAcl.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. Lib::loadClass('Core_AclBase');
  3. Lib::loadClass('Core_AclHelper');
  4. Lib::loadClass('FileStorage');
  5. class Schema_TestPermsStorageAcl extends Core_AclBase {
  6. public function __construct() {
  7. $this->parentAcl = User::getAcl()->getObjectAcl('default_db', 'TEST_PERMS');
  8. // DBG::_(true, true, "parentAcl", $this->parentAcl, __CLASS__, __FUNCTION__, __LINE__);
  9. }
  10. public function getNamespace() { return 'default_objects/' . $this->getName(); }
  11. public function getSourceName() { return 'default_objects'; }
  12. public function init($force = false) {}
  13. public function isInitialized() { return true; }
  14. public function getName() { return 'TestPerms'; }
  15. public function getRootTableName() { return 'TEST_PREMS'; }
  16. public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  17. public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  18. public function getVirtualFieldListByIdZasob() { return array(); }
  19. public function getRealFieldListByIdZasob($force = false) {
  20. $cols = $this->parentAcl->getRealFieldListByIdZasob();
  21. $cols[100000] = 'File';
  22. // $cols[100010] = 'File1';
  23. // $cols[100011] = 'File2';
  24. // $cols[100001] = 'NestedObjectTest';
  25. $cols[100002] = 'AccessGroupRead';
  26. $cols[100003] = 'AccessGroupWrite';
  27. $cols[100004] = 'AccessOwner';
  28. return $cols;
  29. }
  30. public function getFields() {// @returns array - $this->_fields
  31. $fields = $this->parentAcl->getFields();
  32. $fields[100000] = ['name'=>'File', 'perms'=>'RWXC', 'opis'=>'Plik', 'sort_prio'=>999, 'label'=>'Plik'];
  33. // $fields[100001] = 'NestedObjectTest';
  34. $fields[100002] = ['name'=>'AccessGroupRead', 'perms'=>'RWXC', 'opis'=>'Odczyt dla', 'sort_prio'=>999, 'label'=>'Odczyt dla'];
  35. $fields[100003] = ['name'=>'AccessGroupWrite', 'perms'=>'RWXC', 'opis'=>'Zapis dla', 'sort_prio'=>999, 'label'=>'Zapis dla'];
  36. $fields[100004] = ['name'=>'AccessOwner', 'perms'=>'RWXC', 'opis'=>'Osoba odpowiedzialna', 'sort_prio'=>999, 'label'=>'Osoba odp.'];
  37. return $fields;
  38. }
  39. public function getFieldType($fieldName) {
  40. foreach ($this->getFields() as $field) {
  41. if ($fieldName == $field['name']) return $field;
  42. }
  43. return null;
  44. }
  45. // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
  46. public function canCreateField($fieldName) {
  47. if ('File' == $fieldName) return true;
  48. if ('AccessGroupRead' == $fieldName) return true;
  49. if ('AccessGroupWrite' == $fieldName) return true;
  50. if ('AccessOwner' == $fieldName) return true;
  51. return $this->parentAcl->canCreateField($fieldName);
  52. }
  53. public function canReadField($fieldName) {
  54. if ('File' == $fieldName) return true;
  55. if ('AccessGroupRead' == $fieldName) return true;
  56. if ('AccessGroupWrite' == $fieldName) return true;
  57. if ('AccessOwner' == $fieldName) return true;
  58. return $this->parentAcl->canReadField($fieldName);
  59. }
  60. public function canReadObjectField($fieldName, $record) {
  61. if ('File' == $fieldName) return true;
  62. if ('AccessGroupRead' == $fieldName) return true;
  63. if ('AccessGroupWrite' == $fieldName) return true;
  64. if ('AccessOwner' == $fieldName) return true;
  65. return $this->parentAcl->canReadObjectField($fieldName, $record);
  66. }
  67. public function canWriteField($fieldName) {
  68. if ('File' == $fieldName) return true;
  69. if ('AccessGroupRead' == $fieldName) return true;
  70. if ('AccessGroupWrite' == $fieldName) return true;
  71. if ('AccessOwner' == $fieldName) return true;
  72. return $this->parentAcl->canWriteField($fieldName);
  73. }
  74. public function canWriteObjectField($fieldName, $record) {
  75. if ('File' == $fieldName) return true;
  76. if ('AccessGroupRead' == $fieldName) return true;
  77. if ('AccessGroupWrite' == $fieldName) return true;
  78. if ('AccessOwner' == $fieldName) return true;
  79. return $this->parentAcl->canWriteObjectField($fieldName, $record);
  80. }
  81. public function getTotal($params = array()) {// TODO: use ParseOgcQuery
  82. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  83. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getTotal \$params:";print_r($params);echo "\n";}
  84. return $this->parentAcl->getTotal($params);
  85. }
  86. public function getItem($primaryKey, $params = []) {
  87. $items = $this->getItems(['primaryKey'=>$primaryKey]);
  88. return (!empty($items[$primaryKey])) ? $items[$primaryKey] : null;
  89. }
  90. public function getItems($params = array()) {// TODO: use ParseOgcQuery
  91. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  92. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
  93. $items = array();
  94. $rawItems = $this->parentAcl->getItems($params);
  95. foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item;
  96. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  97. if (empty($items)) return $items;
  98. $this->itemsFetchRefs($items);// TODO: only fields from request
  99. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after itemsFetchRefs \$items:";print_r($items);echo "\n";}
  100. return $items;
  101. }
  102. public function addItem($itemTodo) {
  103. return $this->parentAcl->addItem($itemTodo);
  104. }
  105. public function updateItem($itemPatch) {
  106. return $this->parentAcl->updateItem($itemPatch);
  107. }
  108. public function getGeomFieldType($fieldName) { return ('the_geom' == $fieldName) ? 'polygon' : null; }
  109. public function getPrimaryKeyField() { return 'ID'; }
  110. public function getAttributesFromZasoby() { return array(); }
  111. public function isEnumerationField($fieldName) {
  112. if ('A_STATUS' == $fieldName) return true;
  113. return false;
  114. }
  115. public function getEnumerations($fieldName) {
  116. if ('A_STATUS' == $fieldName) return $this->parentAcl->getEnumerations($fieldName);
  117. return null;
  118. }
  119. public function getXsdFieldType($fieldName) {
  120. if ('File' == $fieldName) return 'ref:default_objects:File';
  121. // if ('File1' == $fieldName) return 'alias_ref:p5_objects:File';
  122. // if ('File2' == $fieldName) return 'alias_ref:p5_objects:File';
  123. // if ('NestedObjectTest' == $fieldName) return 'local_ref:p5_objects:NestedObjectTest';
  124. if ('AccessGroupRead' == $fieldName) return 'ref:default_objects:AccessGroupRead';
  125. if ('AccessGroupWrite' == $fieldName) return 'ref:default_objects:AccessGroupWrite';
  126. if ('AccessOwner' == $fieldName) return 'ref:default_objects:AccessOwner';
  127. return $this->parentAcl->getXsdFieldType($fieldName);
  128. }
  129. public function isGeomField($fldName) {
  130. if ('File' == $fieldName) return false;
  131. if ('AccessGroupRead' == $fieldName) return false;
  132. if ('AccessGroupWrite' == $fieldName) return false;
  133. if ('AccessOwner' == $fieldName) return false;
  134. // if ('NestedObjectTest' == $fieldName) return false;
  135. return $this->parentAcl->isGeomField($fldName);
  136. }
  137. public function getInstanceList() {
  138. return [
  139. 'TestPermsDoUzgodnienia',
  140. 'TestPermsUzgodniony',
  141. 'TestPermsOdrzucony',
  142. 'TestPermsAktywny', // test `matching`
  143. ];
  144. }
  145. public function getInstanceSchema($instance) {
  146. switch ($instance) {
  147. case 'TestPermsDoUzgodnienia': return [
  148. '@extension' => [
  149. '@base' => 'TEST_PERMS',
  150. 'KorespDoUzg' => [ '@ref' => 'default_db/IN7_DZIENNIK_KORESP/KorespDoUzg', '@minOccurs' => 1 ],
  151. ]
  152. ];
  153. case 'TestPermsUzgodniony': return [
  154. '@extension' => [
  155. '@base' => 'TestPermsDoUzgodnienia',
  156. 'KorespDoUzg' => [ '@ref' => 'default_db/IN7_DZIENNIK_KORESP/KorespDoUzg', '@minOccurs' => 0 ],
  157. 'KorespUzg' => [ '@ref' => 'default_db/IN7_DZIENNIK_KORESP/KorespUzg', '@minOccurs' => 1 ],
  158. ]
  159. ];
  160. case 'TestPermsOdrzucony': return [
  161. '@extension' => [
  162. '@base' => 'TestPermsDoUzgodnienia',
  163. 'KorespDoUzg' => [ '@ref' => 'default_db/IN7_DZIENNIK_KORESP/KorespDoUzg', '@minOccurs' => 0 ],
  164. 'KorespOdrzucony' => [ '@ref' => 'default_db/IN7_DZIENNIK_KORESP/KorespOdrzucony', '@minOccurs' => 1 ],
  165. ]
  166. ];
  167. case 'TestPermsAktywny': return [
  168. '@restriction' => [
  169. '@base' => 'TEST_PERMS',
  170. 'A_STATUS' => [ '@fixed' => "NORMAL" ],
  171. ]
  172. ];
  173. }
  174. }
  175. }