[Rt-commit] rt branch, 4.2/shred-user-not-in-group, created. rt-4.2.5-54-g865ce70
Jim Brandt
jbrandt at bestpractical.com
Thu Jun 19 16:35:49 EDT 2014
The branch, 4.2/shred-user-not-in-group has been created
at 865ce70987f5d13cfac970bd0aba77aafba68bfb (commit)
- Log -----------------------------------------------------------------
commit 865ce70987f5d13cfac970bd0aba77aafba68bfb
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Jun 19 16:19:37 2014 -0400
Add not_member_of option for shredding users
diff --git a/lib/RT/Shredder/Plugin/Users.pm b/lib/RT/Shredder/Plugin/Users.pm
index 74ac950..fb4ef4b 100644
--- a/lib/RT/Shredder/Plugin/Users.pm
+++ b/lib/RT/Shredder/Plugin/Users.pm
@@ -79,6 +79,11 @@ be selected for deletion. Identifier is name of user defined group
or id of a group, as well C<Privileged> or <unprivileged> can used
to select people from system groups.
+=head2 not_member_of - group identifier
+
+Like member_of, but selects users who are not members of the provided
+group.
+
=head2 replace_relations - user identifier
When you delete user there are could be minor links to him in RT DB.
@@ -108,7 +113,7 @@ want to use C<replace_relations> option.
sub SupportArgs
{
return $_[0]->SUPER::SupportArgs,
- qw(status name email member_of replace_relations no_tickets);
+ qw(status name email member_of not_member_of replace_relations no_tickets);
}
sub TestArgs
@@ -128,19 +133,22 @@ sub TestArgs
if( $args{'name'} ) {
$args{'name'} = $self->ConvertMaskToSQL( $args{'name'} );
}
- if( $args{'member_of'} ) {
- my $group = RT::Group->new( RT->SystemUser );
- if ( $args{'member_of'} =~ /^(Everyone|Privileged|Unprivileged)$/i ) {
- $group->LoadSystemInternalGroup( $args{'member_of'} );
- }
- else {
- $group->LoadUserDefinedGroup( $args{'member_of'} );
- }
- unless ( $group->id ) {
- return (0, "Couldn't load group '$args{'member_of'}'" );
- }
- $args{'member_of'} = $group->id;
+ if( $args{'member_of'} or $args{'not_member_of'} ) {
+ foreach my $group_option ( qw(member_of not_member_of) ){
+ next unless $args{$group_option};
+ my $group = RT::Group->new( RT->SystemUser );
+ if ( $args{$group_option} =~ /^(Everyone|Privileged|Unprivileged)$/i ) {
+ $group->LoadSystemInternalGroup( $args{$group_option} );
+ }
+ else {
+ $group->LoadUserDefinedGroup( $args{$group_option} );
+ }
+ unless ( $group->id ) {
+ return (0, "Couldn't load group '$args{$group_option}'" );
+ }
+ $args{$group_option} = $group->id;
+ }
}
if( $args{'replace_relations'} ) {
my $uid = $args{'replace_relations'};
@@ -189,6 +197,13 @@ sub Run
if( $self->{'opt'}{'member_of'} ) {
$objs->MemberOfGroup( $self->{'opt'}{'member_of'} );
}
+ if( $self->{'opt'}{'not_member_of'} ) {
+ return $self->FilterNotMemberOfGroup(
+ Shredder => $args{'Shredder'},
+ Objects => $objs,
+ GroupId => $self->{'opt'}{'not_member_of'},
+ );
+ }
if( $self->{'opt'}{'no_tickets'} ) {
return $self->FilterWithoutTickets(
Shredder => $args{'Shredder'},
@@ -222,6 +237,29 @@ sub SetResolvers
return (1);
}
+sub FilterNotMemberOfGroup {
+ my $self = shift;
+ my %args = (
+ Shredder => undef,
+ Objects => undef,
+ GroupId => undef,
+ @_,
+ );
+
+ my $group = RT::Group->new(RT->SystemUser);
+ $group->Load($args{'GroupId'});
+
+ my $users = $args{Objects};
+ $self->FetchNext( $users, 'init' );
+
+ my @res;
+ while ( my $user = $self->FetchNext( $users ) ) {
+ push @res, $user unless $group->HasMemberRecursively($user->Id);
+ return (1, \@res) if $self->{'opt'}{'limit'} && @res >= $self->{'opt'}{'limit'};
+ }
+ return (1, \@res);
+}
+
sub FilterWithoutTickets {
my $self = shift;
my %args = (
-----------------------------------------------------------------------
More information about the rt-commit
mailing list