New events when granting and revoking roles
Four new events for when roles are granted or revoked.
This commit is contained in:
parent
07bc50eaed
commit
1d85bfece1
16
EVENTS.txt
16
EVENTS.txt
@ -1142,3 +1142,19 @@ StartShowNoticeForm: before showing the notice form (before <form>)
|
||||
|
||||
EndShowNoticeForm: after showing the notice form (after <form>)
|
||||
- $action: action being executed
|
||||
|
||||
StartGrantRole: when a role is being assigned
|
||||
- $profile: profile that will have the role
|
||||
- $role: string name of the role
|
||||
|
||||
EndGrantRole: when a role has been successfully assigned
|
||||
- $profile: profile that will have the role
|
||||
- $role: string name of the role
|
||||
|
||||
StartRevokeRole: when a role is being revoked
|
||||
- $profile: profile that will lose the role
|
||||
- $role: string name of the role
|
||||
|
||||
EndRevokeRole: when a role has been revoked
|
||||
- $profile: profile that lost the role
|
||||
- $role: string name of the role
|
||||
|
@ -758,6 +758,8 @@ class Profile extends Memcached_DataObject
|
||||
|
||||
function grantRole($name)
|
||||
{
|
||||
if (Event::handle('StartGrantRole', array($this, $name))) {
|
||||
|
||||
$role = new Profile_role();
|
||||
|
||||
$role->profile_id = $this->id;
|
||||
@ -767,15 +769,19 @@ class Profile extends Memcached_DataObject
|
||||
$result = $role->insert();
|
||||
|
||||
if (!$result) {
|
||||
common_log_db_error($role, 'INSERT', __FILE__);
|
||||
return false;
|
||||
throw new Exception("Can't save role '$name' for profile '{$this->id}'");
|
||||
}
|
||||
|
||||
return true;
|
||||
Event::handle('EndGrantRole', array($this, $name));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function revokeRole($name)
|
||||
{
|
||||
if (Event::handle('StartRevokeRole', array($this, $name))) {
|
||||
|
||||
$role = Profile_role::pkeyGet(array('profile_id' => $this->id,
|
||||
'role' => $name));
|
||||
|
||||
@ -794,8 +800,11 @@ class Profile extends Memcached_DataObject
|
||||
throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id));
|
||||
}
|
||||
|
||||
Event::handle('EndRevokeRole', array($this, $name));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function isSandboxed()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user