Prevent user from impersonating self

This commit is contained in:
Luke Towers 2021-08-21 02:44:32 -06:00
parent 3e81da9f32
commit 53fc77778a

View File

@ -243,14 +243,20 @@ class User extends UserBase
/**
* Check if this user can be impersonated by the provided impersonator
* Super users cannot be impersonated and all users cannot be impersonated unless there is an impersonator
* present and the impersonator has access to `backend.impersonate_users`.
* present and the impersonator has access to `backend.impersonate_users`, and the impersonator is not the
* user being impersonated
*
* @param static|false $impersonator The user attempting to impersonate this user, false when not available
* @return boolean
*/
public function canBeImpersonated($impersonator = false)
{
if ($this->isSuperUser() || !$impersonator || !$impersonator->hasAccess('backend.impersonate_users')) {
if (
$this->isSuperUser() ||
!$impersonator ||
!$impersonator->hasAccess('backend.impersonate_users') ||
$impersonator === $this
) {
return false;
}
return true;