Advertisement
Guest User

Atlassian bulk add user

a guest
Jan 30th, 2013
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var IDarray, tabArray, tempArray = new Array(); //Initialize arrays
  2. //Configure these:
  3. var target = "https://insertYourSubDomain.atlassian.net/secure/admin/user/AddUser!default.jspa";
  4. IDarray = "First Last,firstlast@example.com;Second Guy,second@example.com".split(';');
  5. var closeComplete = false; // Close tabs after submitting and logging
  6. var submit = true; // Press the submit button (no spot check)
  7. //don't change these
  8. var n = "\n";
  9. var i, test, macro;
  10. var failed = 0;
  11. var done = 0;
  12. var userName, fullName, emailAddress;
  13. var debugMe = false;
  14.  
  15. function advance() {
  16.     if (debugMe) {
  17.         if (!window.confirm('Advancing. i=' + i + ',  tab=' + (gBrowser.tabContainer.selectedIndex + 1) + '/' + gBrowser.browsers.length)) {
  18.             iimExit();
  19.         }
  20.     }
  21.     gBrowser.tabContainer.advanceSelectedTab(1, true); //advance tab
  22. }
  23.  
  24. function log(errorCode, data) //Write URL to file, then close tab if log successful
  25. {
  26.     data = data.replace(/ /g, "<sp>"); //Replace all occurrences of <space> because imacros doesn't like it
  27.     test = '';
  28.     if (errorCode != 1) // If doesn't equal 1 (no error) then log as failed, else log as succeeded.
  29.     {
  30.         macro = "CODE:ADD !EXTRACT {{!URLCURRENT}}" + n;
  31.         macro += "ADD !EXTRACT " + errorCode + n;
  32.         macro += "ADD !EXTRACT " + data + n;
  33.         macro += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=Failed.csv";
  34.         if (debugMe) {
  35.             if (!window.confirm(macro)) {
  36.                 iimExit();
  37.             }
  38.         }
  39.         test = iimPlay(macro);
  40.         failed++;
  41.     } else {
  42.         macro = "CODE:ADD !EXTRACT {{!URLCURRENT}}" + n;
  43.         macro += "ADD !EXTRACT " + errorCode + n;
  44.         macro += "ADD !EXTRACT " + data + n;
  45.         macro += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=Success.csv";
  46.         if (debugMe) {
  47.             if (!window.confirm(macro)) {
  48.                 iimExit();
  49.             }
  50.         }
  51.         test = iimPlay(macro);
  52.         done++;
  53.     }
  54.    
  55.     if (test == 1) //if log succeeded
  56.     {
  57.         if (debugMe) {
  58.             if (!window.confirm('Closing='+closeComplete+', i=' + i + '; errorCode=' + errorCode + '; tab=' + (gBrowser.tabContainer.selectedIndex + 1) + '/' + gBrowser.browsers.length)) {
  59.                 iimExit();
  60.             }
  61.         }
  62.         if (closeComplete) {
  63.             gBrowser.removeCurrentTab();
  64.         } // Close tab.
  65.     } else {
  66.         iimDisplay('Log Failed: ' + iimGetLastError());
  67.     }
  68. }
  69.  
  70.  
  71. for (i = 0; i < IDarray.length; i++) // Go through every ID in array
  72. {
  73.     tempArray = IDarray[i].split(','); // Split new user into temporary array.
  74.     userName = tempArray[1].split('@')[0].toString().toLowerCase(); // Do crazy string splitting madness
  75.     fullName = tempArray[0];
  76.     emailAddress = tempArray[1];
  77.     if (debugMe) {
  78.         window.alert(userName + ',' + fullName + ',' + emailAddress);
  79.     }
  80.     gBrowser.addTab(target + '?username=' + userName + '&fullname=' + fullName + '&email=' + emailAddress); //Open link with specified information
  81.     if (i > 0) {
  82.         advance();
  83.     }
  84.     if (i == 0) {
  85.         gBrowser.removeCurrentTab(); //Close the first tab.
  86.     }
  87.     if (submit) {
  88.         iimPlay('CODE:TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:user-create ATTR=ID:user-create-submit')
  89.     }
  90.     if (window.content.document.getElementById('user-create-username-error')) {
  91.         log(0, (userName + ',' + fullName + ',' + emailAddress));
  92.     } else {
  93.         log(1, (userName + ',' + fullName + ',' + emailAddress));
  94.     }
  95. }
  96. window.alert('Done.' + n + n + 'Total: ' + IDarray.length + n + 'Failed: ' + failed + n + 'Success: ' + done);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement