]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Verify that authenticated API calls are made from our domain name.
[quix0rs-gnu-social.git] / classes / Profile.php
index e4ab508c0616c6d802a9cc541c9005391f0562ed..7aae98fb5f171e698ac73cb0dba13c8eab51e99d 100644 (file)
@@ -1174,6 +1174,22 @@ class Profile extends Managed_DataObject
         }
     }
 
+    function silenceAs(Profile $actor)
+    {
+        if (!$actor->hasRight(Right::SILENCEUSER)) {
+            throw new AuthorizationException(_('You cannot silence users on this site.'));
+        }
+        // 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.
+            throw new AlreadyFulfilledException(_('User is already silenced.'));
+        }
+        return $this->silence();
+    }
+
     function unsilence()
     {
         $this->revokeRole(Profile_role::SILENCED);
@@ -1182,6 +1198,19 @@ class Profile extends Managed_DataObject
         }
     }
 
+    function unsilenceAs(Profile $actor)
+    {
+        if (!$actor->hasRight(Right::SILENCEUSER)) {
+            // TRANS: Client error displayed trying to unsilence a user when the user does not have the right.
+            throw new AuthorizationException(_('You cannot unsilence users on this site.'));
+        }
+        if (!$this->isSilenced()) {
+            // TRANS: Client error displayed trying to unsilence a user when the target user has not been silenced.
+            throw new AlreadyFulfilledException(_('User is not silenced.'));
+        }
+        return $this->unsilence();
+    }
+
     function flushVisibility()
     {
         // Get all notices
@@ -1192,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?
      *