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

Language PHP Lines 144
MD5 Hash 6b8e7e4f36021693aba4afd96c8933d3
Repository https://github.com/glockops/concrete5.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?
defined('C5_EXECUTE') or die("Access Denied.");

class Concrete5_Model_EditUserPropertiesUserPermissionKey extends UserPermissionKey  {

	public function getMyAssignment() {
		$u = new User();
		$asl = new EditUserPropertiesUserPermissionAccessListItem();
		
		$db = Loader::db();
		$allAKIDs = $db->GetCol('select akID from UserAttributeKeys order by akID asc');

		if ($u->isSuperUser()) {
			$asl->setAllowEditUserName(1);
			$asl->setAllowEditEmail(1);
			$asl->setAllowEditPassword(1);
			$asl->setAllowEditAvatar(1);
			$asl->setAllowEditTimezone(1);
			$asl->setAllowEditDefaultLanguage(1);
			$asl->setAttributesAllowedArray($allAKIDs);
			$asl->setAttributesAllowedPermission('A');
			return $asl;
		}

		$pae = $this->getPermissionAccessObject();
		if (!is_object($pae)) {
			return $asl;
		}
		
		$accessEntities = $u->getUserAccessEntityObjects();
		$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
		$list = $this->getAccessListItems(UserPermissionKey::ACCESS_TYPE_ALL, $accessEntities);
		$list = PermissionDuration::filterByActive($list);
		$properties = array();
		
		$excluded = array();
		$akIDs = array();
		$u = new User();
		foreach($list as $l) {

			if ($l->allowEditUserName() && (!in_array('uName', $excluded))) {
				$asl->setAllowEditUserName(1);
			}
			if ($l->allowEditEmail() && (!in_array('uEmail', $excluded))) {
				$asl->setAllowEditEmail(1);
			}
			if ($l->allowEditPassword() && (!in_array('uPassword', $excluded))) {
				$asl->setAllowEditPassword(1);
			}
			if ($l->allowEditAvatar() && (!in_array('uAvatar', $excluded))) {
				$asl->setAllowEditAvatar(1);
			}
			if ($l->allowEditTimezone() && (!in_array('uTimezone', $excluded))) {
				$asl->allowEditTimezone(1);
			}
			if ($l->allowEditDefaultLanguage() && (!in_array('uDefaultLanguage', $excluded))) {
				$asl->setAllowEditDefaultLanguage(1);
			}
			if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditUserName()) {
				$asl->setAllowEditUserName(0);
				$excluded[] = 'uName';
			}
			if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditEmail()) {
				$asl->setAllowEditEmail(0);
				$excluded[] = 'uEmail';
			}
			if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditPassword()) {
				$asl->setAllowEditPassword(0);
				$excluded[] = 'uPassword';
			}
			if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditAvatar()) {
				$asl->setAllowEditAvatar(0);
				$excluded[] = 'uAvatar';
			}
			if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditTimezone()) {
				$asl->setAllowEditTimezone(0);
				$excluded[] = 'uTimezone';
			}
			if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditDefaultLanguage()) {
				$asl->setAllowEditDefaultLanguage(0);
				$excluded[] = 'uDefaultLanguage';
			}
			if ($l->getAttributesAllowedPermission() == 'N') {
				$akIDs = array();
				$asl->setAttributesAllowedPermission('N');
			}

			if ($l->getAttributesAllowedPermission() == 'C') {
				$asl->setAttributesAllowedPermission('C');
				if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_EXCLUDE) {
					$akIDs = array_values(array_diff($akIDs, $l->getAttributesAllowedArray()));
				} else { 
					$akIDs = array_unique(array_merge($akIDs, $l->getAttributesAllowedArray()));
				}
			}

			if ($l->getAttributesAllowedPermission() == 'A') {
				$akIDs = $allAKIDs;
				$asl->setAttributesAllowedPermission('A');
			}
		}	
		
		$asl->setAttributesAllowedArray($akIDs);
		return $asl;
	}


	public function validate($obj = false) {
		$u = new User();
		if ($u->isSuperUser()) {
			return true;
		}
		
		$asl = $this->getMyAssignment();

		if (is_object($obj)) {
			if ($obj instanceof UserAttributeKey) {
				if ($asl->getAttributesAllowedPermission() == 'A') {
					return true;
				}
				if ($asl->getAttributesAllowedPermission() == 'C' && in_array($obj->getAttributeKeyID(), $asl->getAttributesAllowedArray())) {
					return true;
				} else {
					return false;
				}				
			}
		}
		
		if (
			$asl->allowEditUserName() || 
			$asl->allowEditAvatar() || 
			$asl->allowEditEmail() || 
			$asl->allowEditPassword() || 
			$asl->allowEditTimezone() || 
			$asl->allowEditDefaultLanguage() || 
			($asl->getAttributesAllowedPermission() == 'A' || ($asl->getAttributesAllowedPermission() == 'C' && count($asl->getAttributesAllowedArray() > 0)))) {
				return true;
		} else {
			return false;
		}
	}
	
	
}
Back to Top