aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorMikael Nordfeldth <mmn@hethane.se>2016-02-12 14:47:49 +0100
committerMikael Nordfeldth <mmn@hethane.se>2016-02-12 14:47:49 +0100
commit83f679fb577fd8da2496e3672721a801b50f58d4 (patch)
tree30de74e5e5ecf9a7a2d211614d5c874aa0b38b94 /classes
parent3cef75bcac999487fe88b5bd3250abb408c4c4a9 (diff)
downloadgnu-social-83f679fb577fd8da2496e3672721a801b50f58d4.tar
gnu-social-83f679fb577fd8da2496e3672721a801b50f58d4.zip
Profile->isPrivileged() to check if users have more rights than to post etc.
Diffstat (limited to 'classes')
-rw-r--r--classes/Profile.php22
1 files 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?
*