Skip to content

Commit

Permalink
correctly handle non-existing username during permission testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Guite committed Sep 18, 2021
1 parent 38715a0 commit 1adc96e
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -206,7 +206,7 @@ public function test(
$result = $this->trans('Permission check result:') . ' ';
if (!empty($data['user'])) {
$user = $userRepository->findOneBy(['uname' => $data['user']]);
$uid = isset($user) ? $user->getUid() : Constant::USER_ID_ANONYMOUS;
$uid = isset($user) ? $user->getUid() : false;
} else {
$uid = Constant::USER_ID_ANONYMOUS;
}
Expand All @@ -217,7 +217,7 @@ public function test(
$granted = $this->hasPermission($data['component'], $data['instance'], $data['level'], $uid);

$result .= '<span class="' . ($granted ? 'text-success' : 'text-danger') . '">';
$result .= (0 === $uid) ? $this->trans('unregistered user') : $data['user'];
$result .= Constant::USER_ID_ANONYMOUS < $uid && isset($user) ? $user->getUname() : $this->trans('unregistered user');
$result .= ': ';
if ($granted) {
$result .= $this->trans('permission granted.');
Expand Down

0 comments on commit 1adc96e

Please sign in to comment.