From 83f679fb577fd8da2496e3672721a801b50f58d4 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 12 Feb 2016 14:47:49 +0100 Subject: [PATCH] Profile->isPrivileged() to check if users have more rights than to post etc. --- classes/Profile.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/classes/Profile.php b/classes/Profile.php index 0eaa06120a..7aae98fb5f 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -1179,9 +1179,9 @@ class Profile extends Managed_DataObject if (!$actor->hasRight(Right::SILENCEUSER)) { throw new AuthorizationException(_('You cannot silence users on this site.')); } - // Only administrators can silence other priviliged users (those who have the right to silence as well). - if ($this->hasRight(Right::SILENCEUSER) && !$actor->hasRole(Profile_role::ADMINISTRATOR)) { - throw new AuthorizationException(_('You cannot silence other priviliged users.')); + // Only administrators can silence other privileged users (such as others who have the right to silence). + if ($this->isPrivileged() && !$actor->hasRole(Profile_role::ADMINISTRATOR)) { + throw new AuthorizationException(_('You cannot silence other privileged users.')); } if ($this->isSilenced()) { // TRANS: Client error displayed trying to silence an already silenced user. @@ -1221,6 +1221,22 @@ class Profile extends Managed_DataObject } } + public function isPrivileged() + { + // TODO: An Event::handle so plugins can report if users are privileged. + // The ModHelper is the only one I care about when coding this, and that + // can be tested with Right::SILENCEUSER which I do below: + switch (true) { + case $this->hasRight(Right::SILENCEUSER): + case $this->hasRole(Profile_role::MODERATOR): + case $this->hasRole(Profile_role::ADMINISTRATOR): + case $this->hasRole(Profile_role::OWNER): + return true; + } + + return false; + } + /** * Does this user have the right to do X? * -- 2.39.5