[Rt-commit] r19891 - in rt/3.8/trunk: . lib/RT/Action sbin

ruz at bestpractical.com ruz at bestpractical.com
Thu Jun 4 09:36:30 EDT 2009


Author: ruz
Date: Thu Jun  4 09:36:30 2009
New Revision: 19891

Added:
   rt/3.8/trunk/etc/upgrade/3.8.4/
   rt/3.8/trunk/etc/upgrade/3.8.4/content
Modified:
   rt/3.8/trunk/   (props changed)
   rt/3.8/trunk/lib/RT/Action/NotifyGroup.pm
   rt/3.8/trunk/sbin/rt-email-group-admin.in

Log:
* branches/notify_group -> trunk
 r19493 at Macintosh (orig r19484):  ruz | 2009-05-07 03:55:06 +0300
 - Create branch notify_group
 r19599 at Macintosh (orig r19587):  ruz | 2009-05-08 04:34:17 +0300
 * obsolete old storable format in NotifyGroup action
 r19600 at Macintosh (orig r19588):  ruz | 2009-05-08 04:35:44 +0300
 * add support for group name, user name, user's email address
   and just an email address in NotifyGroup action.
   This will make easier to use it in crontool
 r19601 at Macintosh (orig r19589):  ruz | 2009-05-08 04:36:24 +0300
 * add upgrade script for RT 3.8.4
 r19602 at Macintosh (orig r19590):  ruz | 2009-05-08 04:37:36 +0300
 * use new format and obsolete old format, we have upgrade script
   for conversion


Added: rt/3.8/trunk/etc/upgrade/3.8.4/content
==============================================================================
--- (empty file)
+++ rt/3.8/trunk/etc/upgrade/3.8.4/content	Thu Jun  4 09:36:30 2009
@@ -0,0 +1,58 @@
+
+ at Final = (
+    sub {
+        $RT::Logger->debug("Going to correct arguments of NotifyGroup actions if you have any");
+
+        my $actions = RT::ScripActions->new( $RT::SystemUser );
+        $actions->Limit(
+            FIELD => 'ExecModule',
+            VALUE => 'NotifyGroup',
+        );
+        $actions->Limit(
+            FIELD => 'ExecModule',
+            VALUE => 'NotifyGroupAsComment',
+        );
+
+        my $converter = sub {
+            my $arg = shift;
+            my @res;
+            foreach my $r ( @{ $arg } ) {
+                my $obj;
+                next unless $r->{'Type'};
+                if( lc $r->{'Type'} eq 'user' ) {
+                    $obj = RT::User->new( $RT::SystemUser );
+                } elsif ( lc $r->{'Type'} eq 'group' ) {
+                    $obj = RT::Group->new( $RT::SystemUser );
+                } else {
+                    next;
+                }
+                $obj->Load( $r->{'Instance'} );
+                my $id = $obj->id;
+                next unless( $id );
+
+                push @res, $id;
+            }
+
+            return join ',', @res;
+        };
+
+        require Storable;
+        while ( my $action = $actions->Next ) {
+            my $argument = $action->Argument;
+            my $new = '';
+            local $@;
+            if ( my $struct = eval { Storable::thaw( $arg ) } ) {
+                $new = $converter->( $struct );
+            } else {
+                $new = join /, /, grep length, split /[^0-9]+/, $argument;
+            }
+            next if $new eq $argument;
+
+            my ($status, $msg) = $action->__Set( Field => 'Argument', Value => $new );
+            $RT::Logger->warning( "Couldn't change argument value of the action: $msg" )
+                unless $status;
+        }
+    },
+);
+
+

Modified: rt/3.8/trunk/lib/RT/Action/NotifyGroup.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Action/NotifyGroup.pm	(original)
+++ rt/3.8/trunk/lib/RT/Action/NotifyGroup.pm	Thu Jun  4 09:36:30 2009
@@ -80,12 +80,6 @@
     my $self = shift;
 
     my $arg = $self->Argument;
-
-    my $old_arg = eval { Storable::thaw( $arg ) };
-    unless( $@ ) {
-        $arg = $self->__ConvertOldArg( $old_arg );
-    }
-
     foreach( $self->__SplitArg( $arg ) ) {
         $self->_HandleArgument( $_ );
     }
@@ -103,9 +97,43 @@
 sub _HandleArgument {
     my $self = shift;
     my $instance = shift;
-    
-    my $obj = RT::Principal->new( $RT::SystemUser );
-    $obj->Load( $instance );
+
+    if ( $instance !~ /\D/ ) {
+        my $obj = RT::Principal->new( $self->CurrentUser );
+        $obj->Load( $instance );
+        return $self->_HandlePrincipal( $obj );
+    }
+
+    my $group = RT::Group->new( $self->CurrentUser );
+    $group->LoadUserDefinedGroup( $instance );
+    # to check disabled and so on
+    return $self->_HandlePrincipal( $group->PrincipalObj )
+        if $group->id;
+
+    require Email::Address;
+
+    my $user = RT::User->new( $self->CurrentUser );
+    if ( $instance =~ /^$Email::Address::addr_spec$/ ) {
+        $user->LoadByEmail( $instance );
+        return $self->__PushUserAddress( $instance )
+            unless $user->id;
+    } else {
+        $user->Load( $instance );
+    }
+    return $self->_HandlePrincipal( $user->PrincipalObj )
+        if $user->id;
+
+    $RT::Logger->error(
+        "'$instance' is not principal id, group name, user name,"
+        ." user email address or any email address"
+    );
+
+    return;
+}
+
+sub _HandlePrincipal {
+    my $self = shift;
+    my $obj = shift;
     unless( $obj->id ) {
         $RT::Logger->error( "Couldn't load principal #$instance" );
         return;
@@ -149,31 +177,7 @@
 }
 
 sub __SplitArg {
-    return split /[^0-9]+/, $_[1];
-}
-
-sub __ConvertOldArg {
-    my $self = shift;
-    my $arg = shift;
-    my @res;
-    foreach my $r ( @{ $arg } ) {
-        my $obj;
-        next unless $r->{'Type'};
-        if( lc $r->{'Type'} eq 'user' ) {
-            $obj = RT::User->new( $RT::SystemUser );
-        } elsif ( lc $r->{'Type'} eq 'user' ) {
-            $obj = RT::Group->new( $RT::SystemUser );
-        } else {
-            next;
-        }
-        $obj->Load( $r->{'Instance'} );
-        my $id = $obj->id;
-        next unless( $id );
-
-        push @res, $id;
-    }
-
-    return join ';', @res;
+    return grep length, map {s/^\s+//; s/\s+$//; $_} split /,/, $_[1];
 }
 
 sub __PushUserAddress {

Modified: rt/3.8/trunk/sbin/rt-email-group-admin.in
==============================================================================
--- rt/3.8/trunk/sbin/rt-email-group-admin.in	(original)
+++ rt/3.8/trunk/sbin/rt-email-group-admin.in	Thu Jun  4 09:36:30 2009
@@ -361,7 +361,7 @@
 
     push @cur, $id;
 
-    return $action->__Set( Field => 'Argument', Value => join(';', @cur) );
+    return $action->__Set( Field => 'Argument', Value => join(',', @cur) );
 }
 
 =head2 delete NAME
@@ -477,44 +477,8 @@
 
 sub argument_to_list {
     my $action = shift;
-    my $arg = $action->Argument;
-
-    # old variant via Storable
-    {
-        local $@;
-        require Storable;
-        my $old = eval { Storable::thaw( $arg ) };
-        unless ( $@ ) {
-            $arg = __convert_old($old);
-        }
-    }
-
-    return _split_arg( $arg );
-}
-
-sub _split_arg { return split /[^0-9]+/, $_[0] }
-
-sub __convert_old {
-    my $arg = shift;
-    my @res;
-    foreach my $r ( @{ $arg } ) {
-        my $obj;
-        next unless $r->{'Type'};
-        if ( lc $r->{'Type'} eq 'user' ) {
-            $obj = RT::User->new( $RT::SystemUser );
-        } elsif ( lc $r->{'Type'} eq 'user' ) {
-            $obj = RT::Group->new( $RT::SystemUser );
-        } else {
-            next;
-        }
-        $obj->Load( $r->{'Instance'} );
-        my $id = $obj->id;
-        next unless $id;
-
-        push @res, $id;
-    }
-
-    return join ';', @res;
+    require RT::Action::NotifyGroup;
+    return RT::Action::NotifyGroup->__SplitArg( $action->Argument );
 }
 
 sub _get_our_actions {


More information about the Rt-commit mailing list