Skip to content
Snippets Groups Projects
Commit 44d0923e authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

add User::hasPermission(), fixes #3453

Closes #3453

Merge request studip/studip!2348
parent c0791ae8
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
## Neue Features ## Neue Features
- Der Stud.IP-Cache ist nun kompatibel zu PSR-6. ([TIC #3701](https://gitlab.studip.de/studip/studip/-/issues/3701)) - Der Stud.IP-Cache ist nun kompatibel zu PSR-6. ([TIC #3701](https://gitlab.studip.de/studip/studip/-/issues/3701))
- Das `User`-Model hat die Methode `hasPermissionLevel()` erhalten, um einfach abfragen zu können, ob eine Person einen bestimmten Berechtigungsstatus hat. ([Issue #3453](https://gitlab.studip.de/studip/studip/-/issues/3453))
## Breaking changes ## Breaking changes
......
...@@ -1622,4 +1622,29 @@ class User extends AuthUserMd5 implements Range, PrivacyObject, Studip\Calendar\ ...@@ -1622,4 +1622,29 @@ class User extends AuthUserMd5 implements Range, PrivacyObject, Studip\Calendar\
return ''; return '';
} }
} }
/*
* Returns whether the user has the given permission (for the given range).
*
* @param string $permission
* @param Range|null $for_range
*
* @return bool
*/
public function hasPermissionLevel(string $permission, ?Range $for_range = null): bool
{
if (func_num_args() === 1) {
return $GLOBALS['perm']->have_perm($permission, $this->id);
}
if ($for_range === null) {
throw new Exception('No valid range given');
}
if ($for_range instanceof User) {
return $GLOBALS['perm']->have_profile_perm($permission, $for_range->id, $this->id);
}
return $GLOBALS['perm']->have_studip_perm($permission, $for_range->id, $this->id);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment