# HG changeset patch # User Thomas Waldmann # Date 1392206021 -3600 # Node ID 8618232296b54896bfba4d1091cba445624e670e # Parent 28a3951fc9f60cd917fedc9f5bada8097e7bc09c 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. diff -r 28a3951fc9f6 -r 8618232296b5 MoinMoin/events/emailnotify.py --- 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) diff -r 28a3951fc9f6 -r 8618232296b5 MoinMoin/events/jabbernotify.py --- 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'], diff -r 28a3951fc9f6 -r 8618232296b5 MoinMoin/user.py --- 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 '' indicator.