[Rt-commit] rt branch, 4.2/unregister-role, created. rt-4.1.6-21-g348dbc1

Thomas Sibley trs at bestpractical.com
Wed Jan 16 18:53:14 EST 2013


The branch, 4.2/unregister-role has been created
        at  348dbc1dd3c139bb4b3b3116113abd0361a9ab7a (commit)

- Log -----------------------------------------------------------------
commit 348dbc1dd3c139bb4b3b3116113abd0361a9ab7a
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Jan 16 15:17:19 2013 -0800

    Provide a method to unregister roles at runtime
    
    Doing so is filled with caveats, mostly around re-adding them and code
    expectations, but now it's possible.

diff --git a/lib/RT/Role/Record/Roles.pm b/lib/RT/Role/Record/Roles.pm
index 454994f..f07fb08 100644
--- a/lib/RT/Role/Record/Roles.pm
+++ b/lib/RT/Role/Record/Roles.pm
@@ -164,6 +164,36 @@ sub RegisterRole {
     return 1;
 }
 
+=head2 UnregisterRole
+
+Removes an RT role which applies to this class for role-based access control.
+Any roles on equivalent classes (via EquivClasses passed to L</RegisterRole>)
+are also unregistered.
+
+Takes a role name as the sole argument.
+
+B<Use this carefully:> Objects created after a role is unregistered will not
+have an associated L<RT::Group> for the removed role.  If you later decide to
+stop unregistering the role, operations on those objects created in the
+meantime will fail when trying to interact with the missing role groups.
+
+B<Unregistering a role may break code which assumes the role exists.>
+
+=cut
+
+sub UnregisterRole {
+    my $self  = shift;
+    my $class = ref($self) || $self;
+    my $name  = shift
+        or return;
+
+    my $role = delete $self->_ROLES->{$name}
+        or return;
+
+    $_->UnregisterRole($name)
+        for "RT::System", reverse @{$role->{EquivClasses}};
+}
+
 =head2 Role
 
 Takes a role name; returns a hashref describing the role.  This hashref

-----------------------------------------------------------------------


More information about the Rt-commit mailing list