Index: acct_mgr/notification.py
===================================================================
--- acct_mgr/notification.py (revision 0)
+++ acct_mgr/notification.py (revision 0)
@@ -0,0 +1,108 @@
+
+from trac.core import *
+from trac.admin import IAdminPanelProvider
+from trac.config import Option, ListOption
+from trac.web.chrome import ITemplateProvider
+from trac.notification import NotifyEmail
+
+from api import IAccountChangeListener
+
+class AccountChangesListner(Component):
+ implements(IAccountChangeListener)
+
+ _notify_actions = ListOption(
+ 'account-manager', 'notify_actions', ['new', 'change', 'delete'],
+ doc="""Comma separated list of actions to notify of.
+ Available actions 'new', 'change', 'delete'.""")
+
+ # IAccountChangeListener methods
+
+ def user_created(self, username, password):
+ if 'new' in self._notify_actions:
+ notifier = AccountChangesNotification(self.env)
+ notifier.notify(username, 'New user registration')
+
+ def user_password_changed(self, username, password):
+ if 'change' in self._notify_actions:
+ notifier = AccountChangesNotification(self.env)
+ notifier.notify(username, 'Password reset for user')
+
+ def user_deleted(self, username):
+ if 'delete' in self._notify_actions:
+ notifier = AccountChangesNotification(self.env)
+ notifier.notify(username, 'Deleted User')
+
+class AccountChangesNotification(NotifyEmail):
+ template_name = 'user_changes_email.txt'
+
+ _recipients = Option(
+ 'account-manager', 'account_changes_notify_addresses', '',
+ """List of email addresses that get notified of user changes, ie,
+ new user, password change and delete user.""")
+
+ def get_recipients(self, resid):
+ recipients = self._recipients.split()
+ return (recipients,[])
+
+ def notify(self, username, action):
+ self.data.update({
+ 'account': {
+ 'username': username,
+ 'action': action
+ },
+ 'login': {
+ 'link': self.env.abs_href.login(),
+ }
+ })
+
+ projname = self.config.get('project', 'name')
+ subject = '[%s] %s: %s' % (projname, action, username)
+
+ NotifyEmail.notify(self, username, subject)
+
+
+
+class AccountChangesNotificationAdminPanel(Component):
+ implements(IAdminPanelProvider, ITemplateProvider)
+
+ # IAdminPageProvider
+ def get_admin_panels(self, req):
+ if req.perm.has_permission('TRAC_ADMIN'):
+ yield ('accounts', 'Accounts', 'notification', 'Notification')
+
+ def render_admin_panel(self, req, cat, page, path_info):
+ if page == 'notification':
+ return self._do_config(req)
+
+ def _do_config(self, req):
+ if req.method == 'POST':
+ self.config.set(
+ 'account-manager', 'account_changes_notify_addresses',
+ ' '.join(req.args.get('notify_addresses').strip('\n').split()))
+
+ self.config.set('account-manager', 'notify_actions',
+ ','.join(req.args.getlist('notify_actions'))
+ )
+ self.config.save()
+ notify_addresses = self.config.get(
+ 'account-manager', 'account_changes_notify_addresses').split()
+ notify_actions = self.config.getlist('account-manager',
+ 'notify_actions')
+ data = dict(notify_actions=notify_actions,
+ notify_addresses=notify_addresses)
+ return 'admin_accountsnotification.html', data
+
+ # ITemplateProvider
+
+ def get_htdocs_dirs(self):
+ """Return the absolute path of a directory containing additional
+ static resources (such as images, style sheets, etc).
+ """
+ return []
+
+ def get_templates_dirs(self):
+ """Return the absolute path of the directory containing the provided
+ ClearSilver templates.
+ """
+ from pkg_resources import resource_filename
+ return [resource_filename(__name__, 'templates')]
Property changes on: acct_mgr/notification.py
___________________________________________________________________
Name: svn:keywords
+ Id URL LastChangedDate Rev LastChangedBy
Name: svn:eol-style
+ native
Index: acct_mgr/templates/admin_accountsnotification.html
===================================================================
--- acct_mgr/templates/admin_accountsnotification.html (revision 0)
+++ acct_mgr/templates/admin_accountsnotification.html (revision 0)
@@ -0,0 +1,46 @@
+
+
+