[Rt-commit] rt branch, 4.2/user-transactions-privileged-groups, created. rt-4.2.12-127-ga6d5c87

Dustin Graves dustin at bestpractical.com
Thu Jun 9 13:40:03 EDT 2016


The branch, 4.2/user-transactions-privileged-groups has been created
        at  a6d5c8750ed15fde76f4d2dda5c409417e683a96 (commit)

- Log -----------------------------------------------------------------
commit 8df67c5a16194b5b8ab7f064fd8b6de11fcb234a
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Thu May 26 22:31:14 2016 +0000

    log a transaction when setting or unsetting Privileged status on a User

diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 39b8197..6a3cc71 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -363,6 +363,12 @@ sub _SetPrivileged {
         }
         my ($status, $msg) = $priv->_AddMember( InsideTransaction => 1, PrincipalId => $principal);
         if ($status) {
+            $self->_NewTransaction(
+                Type => 'Set',
+                Field     => 'Privileged',
+                NewValue  => 1,
+                OldValue  => 0,
+            );
             return (1, $self->loc("That user is now privileged"));
         } else {
             return (0, $msg);
@@ -383,6 +389,12 @@ sub _SetPrivileged {
         }
         my ($status, $msg) = $unpriv->_AddMember( InsideTransaction => 1, PrincipalId => $principal);
         if ($status) {
+            $self->_NewTransaction(
+                Type => 'Set',
+                Field     => 'Privileged',
+                NewValue  => 0,
+                OldValue  => 1,
+            );
             return (1, $self->loc("That user is now unprivileged"));
         } else {
             return (0, $msg);

commit a6d5c8750ed15fde76f4d2dda5c409417e683a96
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Fri Jun 3 21:54:35 2016 +0000

    log transactions when adding/removing a User/Group to a Group
    
    this logs transactions on both the parent and the child User/Group
    this only affects User-Defined Groups

diff --git a/lib/RT/Group.pm b/lib/RT/Group.pm
index c412ba6..b45b7a5 100644
--- a/lib/RT/Group.pm
+++ b/lib/RT/Group.pm
@@ -1107,6 +1107,19 @@ sub _AddMember {
             unless $ok;
     }
 
+    # Record transactions for UserDefined groups
+    if ($args{RecordTransaction} && $self->Domain eq 'UserDefined') {
+        $new_member_obj->Object->_NewTransaction(
+            Type => 'AddMembership',
+            Field     => $self->PrincipalObj->id,
+        );
+
+        $self->_NewTransaction(
+            Type => 'AddMember',
+            Field     => $new_member,
+        );
+    }
+
     # Record an Add/SetWatcher txn on the object if we're a role group
     if ($args{RecordTransaction} and $self->RoleClass) {
         my $obj = $args{Object} || $self->RoleGroupObject;
@@ -1312,6 +1325,19 @@ sub _DeleteMember {
         }
     }
 
+    # Record transactions for UserDefined groups
+    if ($args{RecordTransaction} && $self->Domain eq 'UserDefined') {
+        $member_obj->MemberObj->Object->_NewTransaction(
+            Type => 'DeleteMembership',
+            Field     => $self->PrincipalObj->id,
+        );
+
+        $self->_NewTransaction(
+            Type => 'DeleteMember',
+            Field     => $member_id,
+        );
+    }
+
     return ( $val, $self->loc("Member deleted") );
 }
 
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index d73bf38..f4a2cd8 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1311,7 +1311,39 @@ sub _FormatUser {
         } else {
             return ("Reminder completed"); #loc()
         }
-    }
+    },
+    AddMember => sub {
+        my $self = shift;
+        my $principal = RT::Principal->new($self->CurrentUser);
+        $principal->Load($self->Field);
+        my $principal_friendly_name = $principal->IsUser  ? 'user'  :
+                                      $principal->IsGroup ? 'group' : '';
+
+        return ("Added [_1] '[_2]'",
+            $principal_friendly_name, $principal->Object->Name); #loc()
+    },
+    DeleteMember => sub {
+        my $self = shift;
+        my $principal = RT::Principal->new($self->CurrentUser);
+        $principal->Load($self->Field);
+        my $principal_friendly_name = $principal->IsUser  ? 'user'  :
+                                      $principal->IsGroup ? 'group' : '';
+
+        return ("Removed [_1] '[_2]'",
+            $principal_friendly_name, $principal->Object->Name); #loc()
+    },
+    AddMembership => sub {
+        my $self = shift;
+        my $principal = RT::Principal->new($self->CurrentUser);
+        $principal->Load($self->Field);
+        return ("Added to group '[_1]'", $principal->Object->Name); #loc()
+    },
+    DeleteMembership => sub {
+        my $self = shift;
+        my $principal = RT::Principal->new($self->CurrentUser);
+        $principal->Load($self->Field);
+        return ("Removed from group '[_1]'", $principal->Object->Name); #loc()
+    },
 );
 
 

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


More information about the rt-commit mailing list