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