comparison core/modules/user/src/UserAccessControlHandler.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
97 97
98 // Flag to indicate if this user entity is the own user account. 98 // Flag to indicate if this user entity is the own user account.
99 $is_own_account = $items ? $items->getEntity()->id() == $account->id() : FALSE; 99 $is_own_account = $items ? $items->getEntity()->id() == $account->id() : FALSE;
100 switch ($field_definition->getName()) { 100 switch ($field_definition->getName()) {
101 case 'name': 101 case 'name':
102 // Allow view access to anyone with access to the entity. Anonymous 102 // Allow view access to anyone with access to the entity.
103 // users should be able to access the username field during the 103 // The username field is editable during the registration process.
104 // registration process, otherwise the username and email constraints 104 if ($operation == 'view' || ($items && $items->getEntity()->isAnonymous())) {
105 // are not checked.
106 if ($operation == 'view' || ($items && $account->isAnonymous() && $items->getEntity()->isAnonymous())) {
107 return AccessResult::allowed()->cachePerPermissions(); 105 return AccessResult::allowed()->cachePerPermissions();
108 } 106 }
109 // Allow edit access for the own user name if the permission is 107 // Allow edit access for the own user name if the permission is
110 // satisfied. 108 // satisfied.
111 if ($is_own_account && $account->hasPermission('change own username')) { 109 if ($is_own_account && $account->hasPermission('change own username')) {
120 case 'timezone': 118 case 'timezone':
121 case 'mail': 119 case 'mail':
122 // Allow view access to own mail address and other personalization 120 // Allow view access to own mail address and other personalization
123 // settings. 121 // settings.
124 if ($operation == 'view') { 122 if ($operation == 'view') {
125 return $is_own_account ? AccessResult::allowed()->cachePerUser() : AccessResult::neutral(); 123 return AccessResult::allowedIf($is_own_account)->cachePerUser();
126 } 124 }
127 // Anyone that can edit the user can also edit this field. 125 // Anyone that can edit the user can also edit this field.
128 return AccessResult::allowed()->cachePerPermissions(); 126 return AccessResult::allowed()->cachePerPermissions();
129 127
130 case 'pass': 128 case 'pass':