diff options
Diffstat (limited to 'rt/lib/RT/Shredder/Plugin')
-rw-r--r-- | rt/lib/RT/Shredder/Plugin/Attachments.pm | 4 | ||||
-rw-r--r-- | rt/lib/RT/Shredder/Plugin/Base.pm | 11 | ||||
-rw-r--r-- | rt/lib/RT/Shredder/Plugin/Base/Dump.pm | 2 | ||||
-rw-r--r-- | rt/lib/RT/Shredder/Plugin/Base/Search.pm | 2 | ||||
-rw-r--r-- | rt/lib/RT/Shredder/Plugin/Objects.pm | 2 | ||||
-rw-r--r-- | rt/lib/RT/Shredder/Plugin/SQLDump.pm | 2 | ||||
-rw-r--r-- | rt/lib/RT/Shredder/Plugin/Summary.pm | 13 | ||||
-rw-r--r-- | rt/lib/RT/Shredder/Plugin/Tickets.pm | 2 | ||||
-rw-r--r-- | rt/lib/RT/Shredder/Plugin/Users.pm | 105 |
9 files changed, 91 insertions, 52 deletions
diff --git a/rt/lib/RT/Shredder/Plugin/Attachments.pm b/rt/lib/RT/Shredder/Plugin/Attachments.pm index 05f264ec3..5a573ad27 100644 --- a/rt/lib/RT/Shredder/Plugin/Attachments.pm +++ b/rt/lib/RT/Shredder/Plugin/Attachments.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # <sales@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) @@ -132,7 +132,7 @@ sub Run } return (0, "Internal error: '". $sth->err ."'. Please send bug report.") if $sth->err; - map { $_ = "RT::Attachment-$_" } @objs; + @objs = map {"RT::Attachment-$_"} @objs; return (1, @objs); } diff --git a/rt/lib/RT/Shredder/Plugin/Base.pm b/rt/lib/RT/Shredder/Plugin/Base.pm index 7ada97e48..30fa3f320 100644 --- a/rt/lib/RT/Shredder/Plugin/Base.pm +++ b/rt/lib/RT/Shredder/Plugin/Base.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # <sales@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) @@ -61,14 +61,14 @@ sub new { my $proto = shift; my $self = bless( {}, ref $proto || $proto ); - $self->_Init( @_ ); - return $self; + return $self->_Init( @_ ); } sub _Init { my $self = shift; $self->{'opt'} = { @_ }; + return $self; } =head1 USAGE @@ -125,8 +125,9 @@ sub HasSupportForArgs foreach my $a( @args ) { push @unsupported, $a unless grep $_ eq $a, $self->SupportArgs; } - return( 1 ) unless @unsupported; - return( 0, "Plugin doesn't support argument(s): @unsupported" ) if @unsupported; + return( 0, "Plugin doesn't support argument(s): @unsupported" ) + if @unsupported; + return( 1 ); } =head3 TestArgs diff --git a/rt/lib/RT/Shredder/Plugin/Base/Dump.pm b/rt/lib/RT/Shredder/Plugin/Base/Dump.pm index 945bd93e8..c687c0114 100644 --- a/rt/lib/RT/Shredder/Plugin/Base/Dump.pm +++ b/rt/lib/RT/Shredder/Plugin/Base/Dump.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # <sales@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) diff --git a/rt/lib/RT/Shredder/Plugin/Base/Search.pm b/rt/lib/RT/Shredder/Plugin/Base/Search.pm index bb21bd6af..e2ba495d9 100644 --- a/rt/lib/RT/Shredder/Plugin/Base/Search.pm +++ b/rt/lib/RT/Shredder/Plugin/Base/Search.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # <sales@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) diff --git a/rt/lib/RT/Shredder/Plugin/Objects.pm b/rt/lib/RT/Shredder/Plugin/Objects.pm index ebfe2a00f..4da9f8f7f 100644 --- a/rt/lib/RT/Shredder/Plugin/Objects.pm +++ b/rt/lib/RT/Shredder/Plugin/Objects.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # <sales@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) diff --git a/rt/lib/RT/Shredder/Plugin/SQLDump.pm b/rt/lib/RT/Shredder/Plugin/SQLDump.pm index d12cf0b5c..7b59feea9 100644 --- a/rt/lib/RT/Shredder/Plugin/SQLDump.pm +++ b/rt/lib/RT/Shredder/Plugin/SQLDump.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # <sales@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) diff --git a/rt/lib/RT/Shredder/Plugin/Summary.pm b/rt/lib/RT/Shredder/Plugin/Summary.pm index 9ccd66e0a..7442c6d15 100644 --- a/rt/lib/RT/Shredder/Plugin/Summary.pm +++ b/rt/lib/RT/Shredder/Plugin/Summary.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # <sales@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) @@ -76,7 +76,6 @@ sub Run my $method = 'WriteDown'. $class; $method = 'WriteDownDefault' unless $self->can($method); return $self->$method( %args ); - return 1; } my %skip_refs_to = (); @@ -114,8 +113,8 @@ sub WriteDownPrincipal { return 1 } sub WriteDownGroup { my $self = shift; my %args = ( Object => undef, @_ ); - if ( $args{'Object'}->Domain =~ /-Role$/ ) { - return $skip_refs_to{ $args{'Object'}->_AsString } = 1; + if ( $args{'Object'}->RoleClass ) { + return $skip_refs_to{ $args{'Object'}->UID } = 1; } return $self->WriteDownDefault( %args ); } @@ -142,7 +141,7 @@ sub WriteDownScrip { my $props = $self->_MakeHash( $args{'Object'} ); $props->{'Action'} = $args{'Object'}->ActionObj->Name; $props->{'Condition'} = $args{'Object'}->ConditionObj->Name; - $props->{'Template'} = $args{'Object'}->TemplateObj->Name; + $props->{'Template'} = $args{'Object'}->Template; $props->{'Queue'} = $args{'Object'}->QueueObj->Name || 'global'; return $self->_WriteDownHash( $args{'Object'}, $props ); @@ -154,7 +153,7 @@ sub _MakeHash { foreach (grep exists $hash->{$_}, qw(Creator LastUpdatedBy)) { my $method = $_ .'Obj'; my $u = $obj->$method(); - $hash->{ $_ } = $u->EmailAddress || $u->Name || $u->_AsString; + $hash->{ $_ } = $u->EmailAddress || $u->Name || $u->UID; } return $hash; } @@ -171,7 +170,7 @@ sub _WriteDownHash { my ($self, $obj, $hash) = @_; return (0, 'no handle') unless my $fh = $self->{'opt'}{'file_handle'}; - print $fh "=== ". $obj->_AsString ." ===\n" + print $fh "=== ". $obj->UID ." ===\n" or return (0, "Couldn't write to filehandle"); foreach my $key( sort keys %$hash ) { diff --git a/rt/lib/RT/Shredder/Plugin/Tickets.pm b/rt/lib/RT/Shredder/Plugin/Tickets.pm index 180c45c9e..c6b9b8ede 100644 --- a/rt/lib/RT/Shredder/Plugin/Tickets.pm +++ b/rt/lib/RT/Shredder/Plugin/Tickets.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # <sales@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) diff --git a/rt/lib/RT/Shredder/Plugin/Users.pm b/rt/lib/RT/Shredder/Plugin/Users.pm index f763246c2..7e1c31f77 100644 --- a/rt/lib/RT/Shredder/Plugin/Users.pm +++ b/rt/lib/RT/Shredder/Plugin/Users.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC # <sales@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) @@ -79,15 +79,20 @@ 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. -This option allow you to replace this links with link to other user. -This links are Creator and LastUpdatedBy, but NOT any watcher roles, -this means that if user is watcher(Requestor, Owner, -Cc or AdminCc) of the ticket or queue then link would be deleted. +When you delete a user there could be minor links to them in the RT database. +This option allow you to replace these links with links to the new user. +The replaceable links are Creator and LastUpdatedBy, but NOT any watcher roles. +This means that if the user is a watcher(Requestor, Owner, +Cc or AdminCc) of the ticket or queue then the link would be deleted. -This argument could be user id or name. +This argument could be a user id or name. =head2 no_tickets - boolean @@ -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'}; @@ -183,20 +191,38 @@ sub Run $objs->Limit( FIELD => 'Name', OPERATOR => 'MATCHES', VALUE => $self->{'opt'}{'name'}, + CASESENSITIVE => 0, ); } if( $self->{'opt'}{'member_of'} ) { $objs->MemberOfGroup( $self->{'opt'}{'member_of'} ); } + my @filter; + if( $self->{'opt'}{'not_member_of'} ) { + push @filter, $self->FilterNotMemberOfGroup( + Shredder => $args{'Shredder'}, + GroupId => $self->{'opt'}{'not_member_of'}, + ); + } if( $self->{'opt'}{'no_tickets'} ) { - return $self->FilterWithoutTickets( + push @filter, $self->FilterWithoutTickets( Shredder => $args{'Shredder'}, - Objects => $objs, ); - } else { - if( $self->{'opt'}{'limit'} ) { - $objs->RowsPerPage( $self->{'opt'}{'limit'} ); + } + + if (@filter) { + $self->FetchNext( $objs, 'init' ); + my @res; + USER: while ( my $user = $self->FetchNext( $objs ) ) { + for my $filter (@filter) { + next USER unless $filter->($user); + } + push @res, $user; + last if $self->{'opt'}{'limit'} && @res >= $self->{'opt'}{'limit'}; } + $objs = \@res; + } elsif ( $self->{'opt'}{'limit'} ) { + $objs->RowsPerPage( $self->{'opt'}{'limit'} ); } return (1, $objs); } @@ -221,6 +247,23 @@ sub SetResolvers return (1); } +sub FilterNotMemberOfGroup { + my $self = shift; + my %args = ( + Shredder => undef, + GroupId => undef, + @_, + ); + + my $group = RT::Group->new(RT->SystemUser); + $group->Load($args{'GroupId'}); + + return sub { + my $user = shift; + not $group->HasMemberRecursively($user->id); + }; +} + sub FilterWithoutTickets { my $self = shift; my %args = ( @@ -228,15 +271,11 @@ sub FilterWithoutTickets { Objects => undef, @_, ); - my $users = $args{Objects}; - $self->FetchNext( $users, 'init' ); - my @res; - while ( my $user = $self->FetchNext( $users ) ) { - push @res, $user if $self->_WithoutTickets( $user ); - return (1, \@res) if $self->{'opt'}{'limit'} && @res >= $self->{'opt'}{'limit'}; - } - return (1, \@res); + return sub { + my $user = shift; + $self->_WithoutTickets( $user ) + }; } sub _WithoutTickets { |