[patch] Add extension point for Session modification
|Reported by:||Morris||Owned by:|
|Severity:||normal||Keywords:||patch session extension|
I realize that the IUserdirectory functionality currently scheduled for 0.12 will (and should) in all likelihood supercede this …but I need it now.
This patch adds a new extension point in
trac/web/main.py called ISessionObserver. Calls to _get_session (performed as part of every request dispatch) will call pass_user_fields(username, email, name) on every component that implements ISessionObserver; the required return is a tuple of the form (newemail, newname). If the returned values are non-None and different from the original values, the main Session dict is updated before being returned.
What is this good for? If you've ever wanted to autopopulate-at-login your user's display names and/or email addresses, then here you go. Apply this patch, then write a plugin that implements ISessionObserver and does your user data lookup in the pass_user_fields method. If this means hitting a DB, I'd strongly recommend adding some simple caching to your plugin to reduce the flurry of DB hits that this feature would cause :)
NOTE: you'll probably only want to implement ISessionObserver in one plugin — having multiple ISessionObserver components will behave in undefined ways since there's no way (to my knowledge) to guarantee the order in which they'll be called.