]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User.php
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / classes / User.php
index 4ddf949166f2ee6e76ed647b9bd3f43a1776e3e7..f905ea2b72cf3e0b9c3298c440fe5702787dcb7a 100644 (file)
@@ -659,79 +659,10 @@ class User extends Memcached_DataObject
         return Design::staticGet('id', $this->design_id);
     }
 
-    function hasRole($name)
-    {
-        $role = User_role::pkeyGet(array('user_id' => $this->id,
-                                         'role' => $name));
-        return (!empty($role));
-    }
-
-    function grantRole($name)
-    {
-        $role = new User_role();
-
-        $role->user_id = $this->id;
-        $role->role    = $name;
-        $role->created = common_sql_now();
-
-        $result = $role->insert();
-
-        if (!$result) {
-            common_log_db_error($role, 'INSERT', __FILE__);
-            return false;
-        }
-
-        return true;
-    }
-
-    function revokeRole($name)
-    {
-        $role = User_role::pkeyGet(array('user_id' => $this->id,
-                                         'role' => $name));
-
-        if (empty($role)) {
-            throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; does not exist.');
-        }
-
-        $result = $role->delete();
-
-        if (!$result) {
-            common_log_db_error($role, 'DELETE', __FILE__);
-            throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; database error.');
-        }
-
-        return true;
-    }
-
-    /**
-     * Does this user have the right to do X?
-     *
-     * With our role-based authorization, this is merely a lookup for whether the user
-     * has a particular role. The implementation currently uses a switch statement
-     * to determine if the user has the pre-defined role to exercise the right. Future
-     * implementations may allow per-site roles, and different mappings of roles to rights.
-     *
-     * @param $right string Name of the right, usually a constant in class Right
-     * @return boolean whether the user has the right in question
-     */
-
     function hasRight($right)
     {
-        $result = false;
-        if (Event::handle('UserRightsCheck', array($this, $right, &$result))) {
-            switch ($right)
-            {
-            case Right::DELETEOTHERSNOTICE:
-                $result = $this->hasRole(User_role::MODERATOR);
-                break;
-            case Right::CONFIGURESITE:
-                $result = $this->hasRole(User_role::ADMINISTRATOR);
-            default:
-                $result = false;
-                break;
-            }
-        }
-        return $result;
+        $profile = $this->getProfile();
+        return $profile->hasRight($right);
     }
 
     function delete()
@@ -776,4 +707,34 @@ class User extends Memcached_DataObject
         $block->delete();
         // XXX delete group block? Reset blocker?
     }
+
+    function hasRole($name)
+    {
+        $profile = $this->getProfile();
+        return $profile->hasRole($name);
+    }
+
+    function grantRole($name)
+    {
+        $profile = $this->getProfile();
+        return $profile->grantRole($name);
+    }
+
+    function revokeRole($name)
+    {
+        $profile = $this->getProfile();
+        return $profile->revokeRole($name);
+    }
+
+    function isSandboxed()
+    {
+        $profile = $this->getProfile();
+        return $profile->isSandboxed();
+    }
+
+    function isSilenced()
+    {
+        $profile = $this->getProfile();
+        return $profile->isSilenced();
+    }
 }