[Rt-commit] rt branch, 4.2/user-transactions-privileged-groups, created. rt-4.2.12-132-gc050da1
Dustin Graves
dustin at bestpractical.com
Fri Jun 10 15:03:48 EDT 2016
The branch, 4.2/user-transactions-privileged-groups has been created
at c050da1e30cefe841a528114429a9656c1c1ac32 (commit)
- Log -----------------------------------------------------------------
commit 41292a38961bb617aca432039ac5ef69c4674497
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..1d43e51 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 bd44290c51ba1a0cc5381e9b71525987ff6878d0
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..b6da4d8 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..9115507 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1311,7 +1311,43 @@ sub _FormatUser {
} else {
return ("Reminder completed"); #loc()
}
- }
+ },
+ AddMember => sub {
+ my $self = shift;
+ my $principal = RT::Principal->new($self->CurrentUser);
+ $principal->Load($self->Field);
+
+ if ($principal->IsUser) {
+ return ("Added user '[_1]'", $principal->Object->Name); #loc()
+ }
+ else {
+ return ("Added group '[_1]'", $principal->Object->Name); #loc()
+ }
+ },
+ DeleteMember => sub {
+ my $self = shift;
+ my $principal = RT::Principal->new($self->CurrentUser);
+ $principal->Load($self->Field);
+
+ if ($principal->IsUser) {
+ return ("Removed user '[_1]'", $principal->Object->Name); #loc()
+ }
+ else {
+ return ("Removed group '[_1]'", $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 f591697117e5bccc26732e6d82325ab27746cf9e
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 b6da4d8..370b492 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 973e702f46a5ca6e612a9354da6588579df453d2
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 1d43e51..43a89ee 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 c050da1e30cefe841a528114429a9656c1c1ac32
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..692d361 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 => 35;
my $test = "RT::Test::Shredder";
### nested membership check
@@ -38,8 +38,21 @@ my $test = "RT::Test::Shredder";
$members->Limit( FIELD => 'GroupId', VALUE => $cgid );
is( $members->Count, 1, "find membership record" );
+ my $transactions = RT::Transactions->new(RT->SystemUser);
+ $transactions->_OpenParen('member');
+ $transactions->Limit( SUBCLAUSE => 'member', FIELD => 'Type', VALUE => 'AddMember');
+ $transactions->Limit( SUBCLAUSE => 'member', FIELD => 'Field', VALUE => $user->PrincipalObj->id, ENTRYAGGREGATOR => 'AND' );
+ $transactions->Limit( SUBCLAUSE => 'member', FIELD => 'ObjectId', VALUE => $cgroup->id, ENTRYAGGREGATOR => 'AND' );
+ $transactions->_CloseParen('member');
+ $transactions->_OpenParen('member');
+ $transactions->Limit( SUBCLAUSE => 'member', FIELD => 'Type', VALUE => 'AddMembership');
+ $transactions->Limit( SUBCLAUSE => 'member', FIELD => 'Field', VALUE => $cgroup->PrincipalObj->id, ENTRYAGGREGATOR => 'AND' );
+ $transactions->Limit( SUBCLAUSE => 'member', FIELD => 'ObjectId', VALUE => $user->id, ENTRYAGGREGATOR => 'AND' );
+ $transactions->_CloseParen('member');
+ is( $transactions->Count, 2, "find membership transaction records" );
+
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