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

Dustin Graves dustin at bestpractical.com
Thu Jun 9 18:14:18 EDT 2016


The branch, 4.2/user-transactions-privileged-groups has been created
        at  33f3d85a417b9779bbde3aa69d93d50d2a4ea86a (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()
+    },
 );
 
 

commit 7a55383d0762aded1e59c70df0f404870265f023
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Thu Jun 9 22:12:24 2016 +0000

    add new Group transactions to RT::Group's __DependsOn

diff --git a/lib/RT/Group.pm b/lib/RT/Group.pm
index b45b7a5..ce00704 100644
--- a/lib/RT/Group.pm
+++ b/lib/RT/Group.pm
@@ -1712,6 +1712,12 @@ sub __DependsOn {
     );
     push( @$list, $objs );
 
+# Cleanup group's membership transactions
+    $objs = RT::Transactions->new( $self->CurrentUser );
+    $objs->Limit( FIELD => 'Type', OPERATOR => 'IN', VALUE => ['AddMember', 'DeleteMember'] );
+    $objs->Limit( FIELD => 'Field', VALUE => $self->PrincipalObj->id, ENTRYAGGREGATOR => 'AND' );
+    push( @$list, $objs );
+
     $deps->_PushDependencies(
         BaseObject => $self,
         Flags => RT::Shredder::Constants::DEPENDS_ON,

commit a6b642be8947e511618733e949b7210f3aed813a
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Thu Jun 9 22:12:46 2016 +0000

    add new User transactions to RT::User's __DependsOn

diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 6a3cc71..8e05cca 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -2742,6 +2742,12 @@ sub __DependsOn {
     $objs->Limit( FIELD => 'MemberId', VALUE => $self->Id );
     push( @$list, $objs );
 
+# Cleanup user's membership transactions
+    $objs = RT::Transactions->new( $self->CurrentUser );
+    $objs->Limit( FIELD => 'Type', OPERATOR => 'IN', VALUE => ['AddMember', 'DeleteMember'] );
+    $objs->Limit( FIELD => 'Field', VALUE => $self->PrincipalObj->id, ENTRYAGGREGATOR => 'AND' );
+    push( @$list, $objs );
+
     $deps->_PushDependencies(
         BaseObject => $self,
         Flags => RT::Shredder::Constants::DEPENDS_ON,

commit 33f3d85a417b9779bbde3aa69d93d50d2a4ea86a
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Thu Jun 9 22:13:01 2016 +0000

    update shredder group membership test to dispose of new transactions

diff --git a/t/shredder/02group_member.t b/t/shredder/02group_member.t
index 87d1e3c..de42455 100644
--- a/t/shredder/02group_member.t
+++ b/t/shredder/02group_member.t
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 
 use Test::Deep;
-use RT::Test::Shredder tests => 34;
+use RT::Test::Shredder tests => 36;
 my $test = "RT::Test::Shredder";
 
 ### nested membership check
@@ -38,8 +38,27 @@ my $test = "RT::Test::Shredder";
         $members->Limit( FIELD => 'GroupId', VALUE => $cgid );
         is( $members->Count, 1, "find membership record" );
 
+        my @transaction_ids;
+
+        my $addmember_transactions = RT::Transactions->new ( RT->SystemUser );
+        $addmember_transactions->Limit( FIELD => 'Type', VALUE => 'AddMember' );
+        $addmember_transactions->Limit( FIELD => 'Field', VALUE => $user->PrincipalObj->id, ENTRYAGGREGATOR => 'AND' );
+        $addmember_transactions->Limit( FIELD => 'ObjectId', VALUE => $cgroup->id, ENTRYAGGREGATOR => 'AND' );
+        is( $addmember_transactions->Count, 1, "find AddMember record" );
+        push @transaction_ids, map { $_->id } @{$addmember_transactions->ItemsArrayRef||[]};
+
+        my $addmembership_transactions = RT::Transactions->new ( RT->SystemUser );
+        $addmembership_transactions->Limit( FIELD => 'Type', VALUE => 'AddMembership' );
+        $addmembership_transactions->Limit( FIELD => 'Field', VALUE => $cgroup->PrincipalObj->id, ENTRYAGGREGATOR => 'AND' );
+        $addmember_transactions->Limit( FIELD => 'ObjectId', VALUE => $user->id, ENTRYAGGREGATOR => 'AND' );
+        is( $addmembership_transactions->Count, 1, "find AddMembership record" );
+        push @transaction_ids, map { $_->id } @{$addmembership_transactions->ItemsArrayRef||[]};
+
+        my $transactions = RT::Transactions->new ( RT->SystemUser );
+        $transactions->Limit( FIELD => 'id', OPERATOR => 'IN', VALUE => \@transaction_ids );
+
         my $shredder = $test->shredder_new();
-        $shredder->PutObjects( Objects => $members );
+        $shredder->PutObjects( Objects => [$members, $transactions] );
         $shredder->WipeoutAll();
         $test->db_is_valid;
         cmp_deeply( $test->dump_current_and_savepoint('buadd'), "current DB equal to savepoint");

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


More information about the rt-commit mailing list