[rt-devel] Issue with new users in RT CLI

Iain Price iain.price at post.serco.com
Mon Oct 13 08:39:16 EDT 2003


Hi,

For once i'm (hopefully) posting something useful and not just moans 
about slow databases ;)

I've started implementing the RT CLI tool in my Java API where i was 
writing direct to the DB before, it seems to work oK although the 
examples are wrong (there was a patch on a previous mail to fix them), 
but I had issues with creating new users.  The code seems to create a 
user called "New user" then modify it to fit ur parameters, the issue 
(as the code points out) is if this user already exists.  I suspect the 
comment might refer to the case that the user creates a 'New user' user 
rather than the code breaking but anyway... if you botch the RT CLI 
parameters in some way, or something breaks it leaves New user around, 
and then cant create a new one any more.

Its inevitable that such a breakage will occur, users entering duplicate 
email addresses to be added to RT or some such thing, so I decided to 
assume 'New user' was an internal-only thing and patched RT to load this 
user if it cant create a new one.  Theres probably better ways to code 
this (i.e check the user exists rather than create and fail - although 
this ordering will be minutely faster when the system is working 
normally - i.e. no New user user). I've no experience with the perl RT 
api and the bits i used were near by in the code ;)

It would also be nice if the ticket id came back from a new ticket so I 
didn't have to use "identifyable subjects" to retrieve the ID (a 20 odd 
digit random number :P)

Here is my patch, i apologise for any bad coding, or even a broken 
generation of the diff (i used 'diff -p 
share/html/REST/1.0/Forms/user/default.orig 
share/html/REST/1.0/Forms/user/default' but have no clue what i'm doing) 
- this will probably be the first time i've submitted a patch for anyone 
elses code so go easy on it ;) let me know what i should have done 
better etc etc...

Thanks,
Iain

*** share/html/REST/1.0/Forms/user/default.orig 2003-10-13 
11:06:23.000000000 +0100
--- share/html/REST/1.0/Forms/user/default      2003-10-13 
13:26:04.000000000 +0100
*************** if ($id ne 'new') {
*** 40,46 ****
--- 40,55 ----
  }
  else {
      # XXX: Can this fail? What if the user already exists?
+     # IJP 13/10/2003: Yes it can, if you botch RT cli params it can 
get left as 'New user' preventing all future new users...
+     # solution - pick up the existing one if we can - ASSUMPTION: User 
does not have user called 'New user' (already an assumption however)
      $user->Create(Name => 'New user');
+     if (!$user->Id) {
+         $user->Load("New user");
+       if (!$user->Id) {
+               # IJP : Cant make New user, cant load New user, dont 
know if this can happen, but program defensively
+               return [ "# The New User object already existed, but we 
failed to load it.", [], {}, 1 ];
+       }
+     }
  }
  
  my ($c, $o, $k, $e) = ("", [], {}, 0);







More information about the Rt-devel mailing list