[Rt-commit] rt branch, 4.0/rt-email-group-load-user-by-email, created. rt-4.0.14rc1-8-gd163684

Thomas Sibley trs at bestpractical.com
Wed Jul 17 14:46:18 EDT 2013


The branch, 4.0/rt-email-group-load-user-by-email has been created
        at  d1636843938fa7e50e8dea2f35a3a268564ca7d8 (commit)

- Log -----------------------------------------------------------------
commit 2f21ca104b9f57940fe0e6a38b60dc6fd0f82f1b
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Jul 17 11:32:31 2013 -0700

    rt-email-group-admin: Load users by email address after trying name
    
    All of the examples in the usage use --user email at address, although the
    individual subcommand usage does state that they are "unames".  While
    many users in RT have a username equal to their email address, this is
    non-obvious in the provided examples.  Simply make --user take a name or
    an email address of an existing user.

diff --git a/sbin/rt-email-group-admin.in b/sbin/rt-email-group-admin.in
index f6a055a..c3f6d95 100644
--- a/sbin/rt-email-group-admin.in
+++ b/sbin/rt-email-group-admin.in
@@ -245,7 +245,7 @@ sub _list {
     return;
 }
 
-=head2 create NAME [--comment] [--group GNAME] [--user UNAME]
+=head2 create NAME [--comment] [--group GNAME] [--user NAME-OR-EMAIL]
 
 Creates new action with NAME and adds users and/or groups to its
 recipient list. Would be notify as comment if --comment specified.  The
@@ -323,10 +323,12 @@ sub __check_user
     require RT::User;
     my $obj = RT::User->new( RT->SystemUser );
     $obj->Load( $instance );
+    $obj->LoadByEmail( $instance )
+        if not $obj->id and $instance =~ /@/;
     return $obj->id ? $obj : undef;
 }
 
-=head2 add NAME [--group GNAME] [--user UNAME]
+=head2 add NAME [--group GNAME] [--user NAME-OR-EMAIL]
 
 Adds groups and/or users to recipients of the action NAME.  The user, if
 specified, must already exist in RT.

commit d1636843938fa7e50e8dea2f35a3a268564ca7d8
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Jul 17 11:43:52 2013 -0700

    rt-email-group-admin: Autocreate users if necessary
    
    The command is much friendlier if you can specify any email address to
    --user and have it autocreate a record for you.
    
    I avoided using RT::User->LoadOrCreateByEmail to preserve preferred load
    order (although it _shouldn't_ really matter) and use a correct Comment
    rather than the misleading one in the existing method.

diff --git a/sbin/rt-email-group-admin.in b/sbin/rt-email-group-admin.in
index c3f6d95..cf1cd2f 100644
--- a/sbin/rt-email-group-admin.in
+++ b/sbin/rt-email-group-admin.in
@@ -249,7 +249,7 @@ sub _list {
 
 Creates new action with NAME and adds users and/or groups to its
 recipient list. Would be notify as comment if --comment specified.  The
-user, if specified, must already exist in RT.
+user, if specified, will be autocreated if necessary.
 
 =cut
 
@@ -313,7 +313,7 @@ sub __check_group
 sub _check_users
 {
     return map {$_->[1]}
-        grep { $_->[1] ? 1: do { print STDERR "User '$_->[0]' skipped, doesn't exist\n"; 0; } }
+        grep { $_->[1] ? 1: do { print STDERR "User '$_->[0]' skipped, doesn't exist and couldn't autocreate\n"; 0; } }
         map { [$_, __check_user($_)] } @_;
 }
 
@@ -325,13 +325,25 @@ sub __check_user
     $obj->Load( $instance );
     $obj->LoadByEmail( $instance )
         if not $obj->id and $instance =~ /@/;
+
+    unless ($obj->id) {
+        my ($ok, $msg) = $obj->Create(
+            Name         => $instance,
+            EmailAddress => $instance,
+            Privileged   => 0,
+            Comments     => 'Autocreated when added to notify action via rt-email-group-admin',
+        );
+        print STDERR "Autocreate of user '$instance' failed: $msg\n"
+            unless $ok;
+    }
+
     return $obj->id ? $obj : undef;
 }
 
 =head2 add NAME [--group GNAME] [--user NAME-OR-EMAIL]
 
 Adds groups and/or users to recipients of the action NAME.  The user, if
-specified, must already exist in RT.
+specified, will be autocreated if necessary.
 
 =cut
 

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


More information about the Rt-commit mailing list