summaryrefslogtreecommitdiff
path: root/classes/User.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/User.php')
-rw-r--r--classes/User.php103
1 files changed, 32 insertions, 71 deletions
diff --git a/classes/User.php b/classes/User.php
index 4ddf94916..f905ea2b7 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -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();
+ }
}