summaryrefslogtreecommitdiff
path: root/classes/Profile.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/Profile.php')
-rw-r--r--classes/Profile.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/classes/Profile.php b/classes/Profile.php
index 7c1e9db33..2668efcc7 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -587,4 +587,78 @@ class Profile extends Memcached_DataObject
return $location;
}
+
+ 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;
+ }
+
+ function isSandboxed()
+ {
+ return $this->hasRole(User_role::SANDBOXED);
+ }
+
+ function isSilenced()
+ {
+ return $this->hasRole(User_role::SILENCED);
+ }
+
+ function sandbox()
+ {
+ $this->grantRole(User_role::SANDBOXED);
+ }
+
+ function unsandbox()
+ {
+ $this->revokeRole(User_role::SANDBOXED);
+ }
+
+ function silence()
+ {
+ $this->grantRole(User_role::SILENCED);
+ }
+
+ function unsilence()
+ {
+ $this->revokeRole(User_role::SILENCED);
+ }
}