Mercurial > moin > 1.9
changeset 6027:8618232296b5
optimized notification of superusers on user account creation
new user.superusers function that efficiently yields superuser User objects
without listing / reading ALL user profiles as the previous code did.
reduced code duplication.
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Wed, 12 Feb 2014 12:53:41 +0100 |
parents | 28a3951fc9f6 |
children | 1893da1d5213 |
files | MoinMoin/events/emailnotify.py MoinMoin/events/jabbernotify.py MoinMoin/user.py |
diffstat | 3 files changed, 16 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/events/emailnotify.py Wed Feb 12 12:12:17 2014 +0100 +++ b/MoinMoin/events/emailnotify.py Wed Feb 12 12:53:41 2014 +0100 @@ -13,7 +13,7 @@ from MoinMoin.Page import Page from MoinMoin.mail import sendmail from MoinMoin.support.python_compatibility import set -from MoinMoin.user import User, getUserList +from MoinMoin.user import User, superusers from MoinMoin.action.AttachFile import getAttachUrl import MoinMoin.events as ev @@ -116,11 +116,8 @@ email = event.user.email or u"NOT SET" username = event.user.name - user_ids = getUserList(request) - for usr_id in user_ids: - usr = User(request, id=usr_id) - # Currently send this only to super users - if usr.isSuperUser() and event_name in usr.email_subscribed_events: + for usr in superusers(request): + if usr.email and event_name in usr.email_subscribed_events: _ = lambda text: request.getText(text, lang=usr.language or 'en') data = notification.user_created_message(request, _, sitename, username, email) send_notification(request, from_address, [usr.email], data)
--- a/MoinMoin/events/jabbernotify.py Wed Feb 12 12:12:17 2014 +0100 +++ b/MoinMoin/events/jabbernotify.py Wed Feb 12 12:53:41 2014 +0100 @@ -14,7 +14,7 @@ logging = log.getLogger(__name__) from MoinMoin.Page import Page -from MoinMoin.user import User, getUserList +from MoinMoin.user import User, superusers from MoinMoin.support.python_compatibility import set from MoinMoin.action.AttachFile import getAttachUrl @@ -143,11 +143,8 @@ email = event.user.email or u"NOT SET" username = event.user.name - user_ids = getUserList(request) - for id in user_ids: - usr = User(request, id=id) - # Currently send this only to super users - if usr.isSuperUser() and usr.jid and event_name in usr.jabber_subscribed_events: + for usr in superusers(request): + if usr.jid and event_name in usr.jabber_subscribed_events: _ = lambda text: request.getText(text, lang=usr.language or 'en') msg = notification.user_created_message(request, _, sitename, username, email) data = {'action': "user_created", 'subject': msg['subject'], 'text': msg['text'],
--- a/MoinMoin/user.py Wed Feb 12 12:12:17 2014 +0100 +++ b/MoinMoin/user.py Wed Feb 12 12:53:41 2014 +0100 @@ -149,6 +149,16 @@ return _getUserIdByKey(request, 'openids', openid) +def superusers(request): + """ + yields superuser User objects + """ + for name in request.cfg.superuser: + u = User(request, auth_username=name) + if u.isSuperUser(): # this checks for addtl. criteria + yield u + + def getUserIdentification(request, username=None): """ Return user name or IP or '<unknown>' indicator.