PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/glockops/concrete5
PHP | 144 lines | 126 code | 18 blank | 0 comment | 62 complexity | 6b8e7e4f36021693aba4afd96c8933d3 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_EditUserPropertiesUserPermissionKey extends UserPermissionKey {
  4. public function getMyAssignment() {
  5. $u = new User();
  6. $asl = new EditUserPropertiesUserPermissionAccessListItem();
  7. $db = Loader::db();
  8. $allAKIDs = $db->GetCol('select akID from UserAttributeKeys order by akID asc');
  9. if ($u->isSuperUser()) {
  10. $asl->setAllowEditUserName(1);
  11. $asl->setAllowEditEmail(1);
  12. $asl->setAllowEditPassword(1);
  13. $asl->setAllowEditAvatar(1);
  14. $asl->setAllowEditTimezone(1);
  15. $asl->setAllowEditDefaultLanguage(1);
  16. $asl->setAttributesAllowedArray($allAKIDs);
  17. $asl->setAttributesAllowedPermission('A');
  18. return $asl;
  19. }
  20. $pae = $this->getPermissionAccessObject();
  21. if (!is_object($pae)) {
  22. return $asl;
  23. }
  24. $accessEntities = $u->getUserAccessEntityObjects();
  25. $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
  26. $list = $this->getAccessListItems(UserPermissionKey::ACCESS_TYPE_ALL, $accessEntities);
  27. $list = PermissionDuration::filterByActive($list);
  28. $properties = array();
  29. $excluded = array();
  30. $akIDs = array();
  31. $u = new User();
  32. foreach($list as $l) {
  33. if ($l->allowEditUserName() && (!in_array('uName', $excluded))) {
  34. $asl->setAllowEditUserName(1);
  35. }
  36. if ($l->allowEditEmail() && (!in_array('uEmail', $excluded))) {
  37. $asl->setAllowEditEmail(1);
  38. }
  39. if ($l->allowEditPassword() && (!in_array('uPassword', $excluded))) {
  40. $asl->setAllowEditPassword(1);
  41. }
  42. if ($l->allowEditAvatar() && (!in_array('uAvatar', $excluded))) {
  43. $asl->setAllowEditAvatar(1);
  44. }
  45. if ($l->allowEditTimezone() && (!in_array('uTimezone', $excluded))) {
  46. $asl->allowEditTimezone(1);
  47. }
  48. if ($l->allowEditDefaultLanguage() && (!in_array('uDefaultLanguage', $excluded))) {
  49. $asl->setAllowEditDefaultLanguage(1);
  50. }
  51. if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditUserName()) {
  52. $asl->setAllowEditUserName(0);
  53. $excluded[] = 'uName';
  54. }
  55. if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditEmail()) {
  56. $asl->setAllowEditEmail(0);
  57. $excluded[] = 'uEmail';
  58. }
  59. if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditPassword()) {
  60. $asl->setAllowEditPassword(0);
  61. $excluded[] = 'uPassword';
  62. }
  63. if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditAvatar()) {
  64. $asl->setAllowEditAvatar(0);
  65. $excluded[] = 'uAvatar';
  66. }
  67. if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditTimezone()) {
  68. $asl->setAllowEditTimezone(0);
  69. $excluded[] = 'uTimezone';
  70. }
  71. if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditDefaultLanguage()) {
  72. $asl->setAllowEditDefaultLanguage(0);
  73. $excluded[] = 'uDefaultLanguage';
  74. }
  75. if ($l->getAttributesAllowedPermission() == 'N') {
  76. $akIDs = array();
  77. $asl->setAttributesAllowedPermission('N');
  78. }
  79. if ($l->getAttributesAllowedPermission() == 'C') {
  80. $asl->setAttributesAllowedPermission('C');
  81. if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE) {
  82. $akIDs = array_values(array_diff($akIDs, $l->getAttributesAllowedArray()));
  83. } else {
  84. $akIDs = array_unique(array_merge($akIDs, $l->getAttributesAllowedArray()));
  85. }
  86. }
  87. if ($l->getAttributesAllowedPermission() == 'A') {
  88. $akIDs = $allAKIDs;
  89. $asl->setAttributesAllowedPermission('A');
  90. }
  91. }
  92. $asl->setAttributesAllowedArray($akIDs);
  93. return $asl;
  94. }
  95. public function validate($obj = false) {
  96. $u = new User();
  97. if ($u->isSuperUser()) {
  98. return true;
  99. }
  100. $asl = $this->getMyAssignment();
  101. if (is_object($obj)) {
  102. if ($obj instanceof UserAttributeKey) {
  103. if ($asl->getAttributesAllowedPermission() == 'A') {
  104. return true;
  105. }
  106. if ($asl->getAttributesAllowedPermission() == 'C' && in_array($obj->getAttributeKeyID(), $asl->getAttributesAllowedArray())) {
  107. return true;
  108. } else {
  109. return false;
  110. }
  111. }
  112. }
  113. if (
  114. $asl->allowEditUserName() ||
  115. $asl->allowEditAvatar() ||
  116. $asl->allowEditEmail() ||
  117. $asl->allowEditPassword() ||
  118. $asl->allowEditTimezone() ||
  119. $asl->allowEditDefaultLanguage() ||
  120. ($asl->getAttributesAllowedPermission() == 'A' || ($asl->getAttributesAllowedPermission() == 'C' && count($asl->getAttributesAllowedArray() > 0)))) {
  121. return true;
  122. } else {
  123. return false;
  124. }
  125. }
  126. }