Life in the trenches

Life in the trenches is about the mixture of forces in ones life. In my case it's family, work, and RPGs.

User Account Pruning - Update

Just and update on this.  As it turns out you can easily create the context you need for an administrative account in a CSModule and CSTask.

All of the examples I saw told you that you could generate a CSContext by using something like this in the ITask.Execute() method:

SiteSettingsManager.IterateSiteSettings(new SiteSettingsListIterator(RunMyJob));

and in the RunMyJob method make a call to:

CSContext.Create(SettingsID);

That in fact is what I used in the first run of my ProfileAging class.  Now with the User Pruning we actually needed a user whos profile has IsAdministrator or IsMembershipAdministrator set to true.  The reason for this is that the Users.DeleteUser method requires that level or authorization to complete the delete.  When I was looking around in the API I noticed that there is a CSContext.Current.User attribute but I assumed that this was a read-only field.  I also assumed that this property would only get set via some type of login or impersonation.

I'm happy to find out, thanks to Phosphorous on the CS fourms, that you can actually assign it this way:

CSContext.Current.User = Users.GetUser(UserID);

Wow, that was easy and now my delete call works like a champ.  I was able to complete the main logic so that an account is disabled after X days and deleted after Y days.  The values for the UserID, X Days, and Y Days are all in the configuration file.  I also set the logic to where you don't have to have the number of days for delete in which case deletions don't happen buy the disapprovals do.  Now all I need is the remaining logic but I might adjust the flow a little bit so that an event is thrown for each of the tasks.  This will allow isolation of the functions so that anyone wanting to swap out the functionality will be able to do so without changing the main processor.