summaryrefslogtreecommitdiff
path: root/classes/User.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-11-16 15:52:33 +0100
committerEvan Prodromou <evan@status.net>2009-11-16 15:52:33 +0100
commit792590bcdccfabc8565dea138d93f6f3405131da (patch)
treef35092f1df526c0113d2b53f73cf688c4ded98e1 /classes/User.php
parentff88ef407a344749c02d9d1d0dc104b4b720d7ae (diff)
move role functions to Profile class
Diffstat (limited to 'classes/User.php')
-rw-r--r--classes/User.php68
1 files changed, 22 insertions, 46 deletions
diff --git a/classes/User.php b/classes/User.php
index 0e8404377..1dca59f23 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -657,50 +657,6 @@ 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?
*
@@ -779,13 +735,33 @@ class User extends Memcached_DataObject
// 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()
{
- return $this->hasRole(User_role::SANDBOXED);
+ $profile = $this->getProfile();
+ return $profile->isSandboxed();
}
function isSilenced()
{
- return $this->hasRole(User_role::SILENCED);
+ $profile = $this->getProfile();
+ return $profile->isSilenced();
}
}