]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
allow the cmd installer to load the config file from '/etc/gnusocial/config.d/'....
[quix0rs-gnu-social.git] / classes / Profile.php
index 875ad9ade1bd31851c60394c83e9c985d054d249..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?
      *
@@ -1628,6 +1673,15 @@ class Profile extends Managed_DataObject
         return $profile;
     }
 
+    static function ensureCurrent()
+    {
+        $profile = self::current();
+        if (!$profile instanceof Profile) {
+            throw new AuthorizationException('A currently scoped profile is required.');
+        }
+        return $profile;
+    }
+
     /**
      * Magic function called at serialize() time.
      *