The two problems I’m going to deal here are:
- Batch setting the email based on the username
- Batch setting the Account expiry date (based on a search)
Batch setting the email based on the username
This problem happened because in one of the 3.2 TM sites that we hosted, 61 user accounts were created with no email value (in the previous version the email was not required). Luckily they used the email as the username, so this is ‘just’ a case of assigning an user’s email value to its username.
Let’s start by opening up a CSharpRepl script environment:
And this is how to get a reference to the current user’s object:
There are also extension methods that allow the easy programmatic access to a particular user:
And its email:
As a first example, let’s change this user’s email (which is dinis@si)
to dcruz@securityinnovation.com
Note that although this change shows in the User’s list
A git status will show that there was no file changes (i.e. the change was all done in memory)
but if we save the user
the git status will now show a changed file:
(note that when running TM on localhost, the auto git commits are disabled (namely to prevent conflicts with the admin account))
This means that the script to set all users email to its username is simply:
(the “admin” and “dinis” accounts were the only ones that the username didn't contain an email)
After running the script there were 61 changes, committed as one:
and pushed into the main Site_clientName repository.
After the push, I went into the live server and did a User Data Sync in order to do trigger the pull:
And now the user’s changes have been propagated to the live server:
Let’s now handle the 2nd issue:
Batch setting the Account expiry date (based on a search)
After the import from 3.2 to 3.3, we have 427 users in the current TM instance
In the CSharpRepl we start again by getting the TMUsers object (part of the UserData class)
Here is how to get the current users that have an SI account:
or if you prefer to use LINQ
Here is how to get a user’s account ExpirationDate:
which at the moment is (5th April 2013):
Here is how to make the expiry date to be in 16 days from today’s date:
And to disable completely the Expiration date, we just set it to default(DateTime);
And here is how to remove the expiration date check from all SI users:
Using TM4TM to document these scripts
Based on the scripts created on this blog post, I created the User Management using REPL Scripts page, written in WikiText
and whose HTML (and code formatting) looks like this: