PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/web/concrete/core/models/permission/keys/custom/edit_page_properties.php

https://github.com/glockops/concrete5
PHP | 143 lines | 123 code | 20 blank | 0 comment | 57 complexity | 4c2d62999b3325e57ed83d535d9b2461 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, BSD-3-Clause
  1. <?
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. class Concrete5_Model_EditPagePropertiesPagePermissionKey extends PagePermissionKey {
  4. protected function getAllAttributeKeyIDs() {
  5. $db = Loader::db();
  6. $allAKIDs = $db->GetCol('select akID from AttributeKeys inner join AttributeKeyCategories on AttributeKeys.akCategoryID = AttributeKeyCategories.akCategoryID where akCategoryHandle = \'collection\'');
  7. return $allAKIDs;
  8. }
  9. public function getMyAssignment() {
  10. $u = new User();
  11. $asl = new EditPagePropertiesPagePermissionAccessListItem();
  12. if ($u->isSuperUser()) {
  13. $asl->setAllowEditName(1);
  14. $asl->setAllowEditDateTime(1);
  15. $asl->setAllowEditUserID(1);
  16. $asl->setAllowEditDescription(1);
  17. $asl->setAllowEditPaths(1);
  18. $asl->setAttributesAllowedArray($this->getAllAttributeKeyIDs());
  19. $asl->setAttributesAllowedPermission('A');
  20. return $asl;
  21. }
  22. $pae = $this->getPermissionAccessObject();
  23. if (!is_object($pae)) {
  24. return $asl;
  25. }
  26. $accessEntities = $u->getUserAccessEntityObjects();
  27. $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
  28. $list = $pae->getAccessListItems(PagePermissionKey::ACCESS_TYPE_ALL, $accessEntities);
  29. $list = PermissionDuration::filterByActive($list);
  30. $properties = array();
  31. $excluded = array();
  32. $akIDs = array();
  33. $u = new User();
  34. if (count($list) > 0) {
  35. $allAKIDs = $this->getAllAttributeKeyIDs();
  36. }
  37. foreach($list as $l) {
  38. if ($l->allowEditName() && (!in_array('name', $excluded))) {
  39. $asl->setAllowEditName(1);
  40. }
  41. if ($l->allowEditDateTime() && (!in_array('date', $excluded))) {
  42. $asl->setAllowEditDateTime(1);
  43. }
  44. if ($l->allowEditUserID() && (!in_array('uID', $excluded))) {
  45. $asl->setAllowEditUserID(1);
  46. }
  47. if ($l->allowEditDescription() && (!in_array('description', $excluded))) {
  48. $asl->setAllowEditDescription(1);
  49. }
  50. if ($l->allowEditPaths() && (!in_array('paths', $excluded))) {
  51. $asl->setAllowEditPaths(1);
  52. }
  53. if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditName()) {
  54. $asl->setAllowEditName(0);
  55. $excluded[] = 'name';
  56. }
  57. if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditDateTime()) {
  58. $asl->setAllowEditDateTime(0);
  59. $excluded[] = 'date';
  60. }
  61. if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditUserID()) {
  62. $asl->setAllowEditUserID(0);
  63. $excluded[] = 'uID';
  64. }
  65. if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditDescription()) {
  66. $asl->setAllowEditDescription(0);
  67. $excluded[] = 'description';
  68. }
  69. if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditPaths()) {
  70. $asl->setAllowEditPaths(0);
  71. $excluded[] = 'paths';
  72. }
  73. if ($l->getAttributesAllowedPermission() == 'N') {
  74. $akIDs = array();
  75. $asl->setAttributesAllowedPermission('N');
  76. }
  77. if ($l->getAttributesAllowedPermission() == 'C') {
  78. $asl->setAttributesAllowedPermission('C');
  79. if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE) {
  80. $akIDs = array_values(array_diff($akIDs, $l->getAttributesAllowedArray()));
  81. } else {
  82. $akIDs = array_unique(array_merge($akIDs, $l->getAttributesAllowedArray()));
  83. }
  84. }
  85. if ($l->getAttributesAllowedPermission() == 'A') {
  86. $akIDs = $allAKIDs;
  87. $asl->setAttributesAllowedPermission('A');
  88. }
  89. }
  90. $asl->setAttributesAllowedArray($akIDs);
  91. return $asl;
  92. }
  93. public function validate($obj = false) {
  94. $u = new User();
  95. if ($u->isSuperUser()) {
  96. return true;
  97. }
  98. $asl = $this->getMyAssignment();
  99. if (is_object($obj)) {
  100. if ($obj instanceof CollectionAttributeKey) {
  101. if ($asl->getAttributesAllowedPermission() == 'A') {
  102. return true;
  103. }
  104. if ($asl->getAttributesAllowedPermission() == 'C' && in_array($obj->getAttributeKeyID(), $asl->getAttributesAllowedArray())) {
  105. return true;
  106. } else {
  107. return false;
  108. }
  109. }
  110. }
  111. if (
  112. $asl->allowEditName() ||
  113. $asl->allowEditDescription() ||
  114. $asl->allowEditDateTime() ||
  115. $asl->allowEditUserID() ||
  116. $asl->allowEditPaths() ||
  117. ($asl->getAttributesAllowedPermission() == 'A' || ($asl->getAttributesAllowedPermission() == 'C' && count($asl->getAttributesAllowedArray() > 0)))) {
  118. return true;
  119. } else {
  120. return false;
  121. }
  122. }
  123. }