changeset 2466:474448e88c24

Merge main.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Fri, 20 Jul 2007 01:56:41 +0200
parents 3c5b329afe4b (current diff) dd138b728c1f (diff)
children 31b3d03bd1ea
files MoinMoin/userprefs/prefs.py
diffstat 14 files changed, 217 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_events.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/_tests/test_events.py	Fri Jul 20 01:56:41 2007 +0200
@@ -51,40 +51,36 @@
     user = User(request)
     event = events.Event(request)
 
-    print "User is subscribed to this event and wants to get notified by jabber."
+    print "User is subscribed to this event on jabber."
     print "This means, that he should stay on the list."
-    user.notify_by_jabber = True
     user.jid = "user@example.com"
-    user.subscribed_events = [events.Event.__name__]
+    user.jabber_subscribed_events = [events.Event.__name__]
     subscribers = {"en": [user]}
     notification.filter_subscriber_list(event, subscribers, True)
     assert subscribers["en"]
 
-    print "User is subscribed to this event, but doesn't want to get notified by jabber."
+    print "User is not subscribed to this event on jabber."
     print "The list should be empty."
-    user.notify_by_jabber = False
     user.jid = "user@example.com"
-    user.subscribed_events = [events.Event.__name__]
+    user.jabber_subscribed_events = []
     subscribers = {"en": [user]}
     notification.filter_subscriber_list(event, subscribers, True)
     assert not subscribers["en"]
 
-    print "User is not subscribed to this event, but wants to get notfied by jabber."
-    print "The list should be empty."
-    user.notify_by_jabber = True
-    user.jid = "user@example.com"
-    user.subscribed_events = []
+    print "User is subscribed to this event on email."
+    print "This means, that he should stay on the list."
+    user.email = "user@example.com"
+    user.email_subscribed_events = [events.Event.__name__]
     subscribers = {"en": [user]}
-    notification.filter_subscriber_list(event, subscribers, True)
-    assert not subscribers["en"]
+    notification.filter_subscriber_list(event, subscribers, False)
+    assert subscribers["en"]
 
-    print "User is neither subscribed to this event, nor wants jabber notifications."
+    print "User is not subscribed to this event on email."
     print "The list should be empty."
-    user.notify_by_jabber = False
-    user.subscribed_events = []
-    user.jid = "user@example.com"
+    user.email = "user@example.com"
+    user.email_subscribed_events = []
     subscribers = {"en": [user]}
-    notification.filter_subscriber_list(event, subscribers, True)
+    notification.filter_subscriber_list(event, subscribers, False)
     assert not subscribers["en"]
 
 coverage_modules = ["MoinMoin.events"]
--- a/MoinMoin/action/userprefs.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/action/userprefs.py	Fri Jul 20 01:56:41 2007 +0200
@@ -51,7 +51,8 @@
         obj = cls(request)
         if not obj.allowed():
             continue
-        url = request.page.url(request, {'action': 'userprefs', 'sub': sub})
+        url = request.page.url(request, {'action': 'userprefs', 'sub': sub},
+                               relative=False)
         lnk = html.LI().append(html.A(href=url).append(html.Text(obj.title)))
         items.append(lnk)
     return unicode(ret)
--- a/MoinMoin/auth/openidrp.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/auth/openidrp.py	Fri Jul 20 01:56:41 2007 +0200
@@ -13,8 +13,9 @@
 from openid.fetchers import HTTPFetchingError
 from MoinMoin import wikiutil
 from MoinMoin.widget import html
-from MoinMoin.auth import (CancelLogin, ContinueLogin, MultistageFormLogin,
-    MultistageRedirectLogin, get_multistage_continuation_url)
+from MoinMoin.auth import CancelLogin, ContinueLogin
+from MoinMoin.auth import MultistageFormLogin, MultistageRedirectLogin
+from MoinMoin.auth import get_multistage_continuation_url
 
 class OpenIDAuth(BaseAuth):
     login_inputs = ['openid_identifier']
--- a/MoinMoin/config/multiconfig.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/config/multiconfig.py	Fri Jul 20 01:56:41 2007 +0200
@@ -534,7 +534,6 @@
         ('show_fancy_diff', lambda _: _('Show fancy diffs')),
         ('wikiname_add_spaces', lambda _: _('Add spaces to displayed wiki names')),
         ('remember_me', lambda _: _('Remember login information')),
-        ('want_trivial', lambda _: _('Subscribe to trivial changes')),
 
         ('disabled', lambda _: _('Disable this account forever')),
         # if an account is disabled, it may be used for looking up
@@ -698,15 +697,6 @@
             from xmlrpclib import Server
             self.notification_server = Server(self.notification_bot_uri, )
 
-            # Add checkbox fields that allow user to select means of notification
-            self.user_checkbox_fields.extend([
-                  ('notify_by_email', lambda _: _('Notify me about changes via email')),
-                  ('notify_by_jabber', lambda _: _('Notify me about changes via jabber')),
-                  ])
-
-            new_defaults = {'notify_by_email': 1, 'notify_by_jabber': 0}
-            self.user_checkbox_defaults.update(new_defaults)
-
         # Cache variables for the properties below
         self._iwid = self._iwid_full = self._meta_dict = None
 
--- a/MoinMoin/events/emailnotify.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/events/emailnotify.py	Fri Jul 20 01:56:41 2007 +0200
@@ -79,8 +79,10 @@
 
         # send email to all subscribers
         for lang in subscribers:
-            emails = [u.email for u in subscribers[lang] if u.notify_by_email]
-            names = [u.name for u in subscribers[lang] if u.notify_by_email]
+            users = [u for u in subscribers[lang]
+                     if PageChangedEvent.__name__ in u.email_subscribed_events]
+            emails = [u.email for u in users]
+            names = [u.name for u in users]
             data = prep_page_changed_mail(request, page, comment, lang, revisions, trivial)
 
             if send_notification(request, mail_from, emails, data):
@@ -107,11 +109,9 @@
 
     for id in user_ids:
         usr = User(event.request, id=id)
-        if not usr.notify_by_email:
-            continue
 
         # Currently send this only to super users
-        if usr.isSuperUser() and event_name in usr.subscribed_events and usr.notify_by_email:
+        if usr.isSuperUser() and event_name in usr.email_subscribed_events:
             emails.append(usr.email)
 
     send_notification(event.request, from_address, emails, data)
@@ -135,7 +135,7 @@
         emails = []
 
         for usr in subscribers[lang]:
-            if usr.notify_by_email and event_name in usr.subscribed_events:
+            if usr.email and event_name in usr.email_subscribed_events:
                 emails.append(usr.email)
             else:
                 continue
--- a/MoinMoin/events/jabbernotify.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/events/jabbernotify.py	Fri Jul 20 01:56:41 2007 +0200
@@ -80,7 +80,7 @@
         data = notification.attachment_added(request, event.pagename, event.name, event.size)
 
         for usr in subscribers[lang]:
-            if usr.notify_by_jabber and usr.jid and event_name in usr.subscribed_events:
+            if usr.jid and event_name in usr.jabber_subscribed_events:
                 jids.append(usr.jid)
             else:
                 continue
@@ -139,11 +139,9 @@
 
     for id in user_ids:
         usr = User(event.request, id=id)
-        if not usr.notify_by_jabber:
-            continue
 
         # Currently send this only to super users
-        if usr.isSuperUser() and usr.jid and event_name in usr.subscribed_events:
+        if usr.isSuperUser() and usr.jid and event_name in usr.jabber_subscribed_events:
             jids.append(usr.jid)
 
     send_notification(event.request, jids, msg % (event.user.name, email), data['subject'])
--- a/MoinMoin/events/notification.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/events/notification.py	Fri Jul 20 01:56:41 2007 +0200
@@ -176,11 +176,12 @@
     return {'body': body, 'subject': subject}
 
 
+# XXX: clean up this method to take a notification type instead of bool for_jabber
 def filter_subscriber_list(event, subscribers, for_jabber):
     """Filter a list of page subscribers to honor event subscriptions
 
     @param subscribers: list of subscribers (dict of lists, language is the key)
-    @param for_jabber: require jid and notify_by_jabber
+    @param for_jabber: require jid
     @type subscribers: dict
 
     """
@@ -193,11 +194,11 @@
 
         if for_jabber:
             for usr in subscribers[lang]:
-                if usr.jid and usr.notify_by_jabber and event_name in usr.subscribed_events:
+                if usr.jid and event_name in usr.jabber_subscribed_events:
                     userlist.append(usr)
         else:
             for usr in subscribers[lang]:
-                if usr.notify_by_email and event_name in usr.subscribed_events:
+                if usr.email and event_name in usr.email_subscribed_events:
                     userlist.append(usr)
 
         subscribers[lang] = userlist
--- a/MoinMoin/user.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/user.py	Fri Jul 20 01:56:41 2007 +0200
@@ -299,8 +299,6 @@
         self.auth_method = kw.get('auth_method', 'internal')
         self.auth_attribs = kw.get('auth_attribs', ())
         self.bookmarks = {} # interwikiname: bookmark
-        self.notify_by_email = True
-        self.notify_by_jabber = False
 
         # create some vars automatically
         self.__dict__.update(self._cfg.user_form_defaults)
@@ -331,7 +329,8 @@
         self.datetime_fmt = ""
         self.quicklinks = self._cfg.quicklinks_default
         self.subscribed_pages = self._cfg.subscribed_pages_default
-        self.subscribed_events = self._cfg.subscribed_events_default
+        self.email_subscribed_events = self._cfg.subscribed_events_default
+        self.jabber_subscribed_events = []
         self.theme_name = self._cfg.theme_default
         self.editor_default = self._cfg.editor_default
         self.editor_ui = self._cfg.editor_ui
--- a/MoinMoin/userprefs/__init__.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/userprefs/__init__.py	Fri Jul 20 01:56:41 2007 +0200
@@ -72,7 +72,7 @@
             preferences forms and then call make_row(). See
             existing plugins, e.g. changepass.py.
         '''
-        action = self.request.page.url(self.request)
+        action = self.request.page.url(self.request, relative=False)
         _form = html.FORM(action=action)
         _form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
         _form.append(html.INPUT(type="hidden", name="handler", value=self.name))
--- a/MoinMoin/userprefs/changepass.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/userprefs/changepass.py	Fri Jul 20 01:56:41 2007 +0200
@@ -22,7 +22,7 @@
         self._ = request.getText
         _ = request.getText
         self.cfg = request.cfg
-        self.title = _("Change password")
+        self.title = _("Change password", formatted=False)
         self.name = 'changepass'
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/userprefs/notification.py	Fri Jul 20 01:56:41 2007 +0200
@@ -0,0 +1,176 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - Notification preferences
+
+    @copyright: 2001-2004 Juergen Hermann <jh@web.de>,
+                2003-2007 MoinMoin:ThomasWaldmann
+                2007      MoinMoin:JohannesBerg
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import time
+from MoinMoin import user, util, wikiutil, events
+from MoinMoin.widget import html
+from MoinMoin.userprefs import UserPrefBase
+
+
+class Settings(UserPrefBase):
+    def __init__(self, request):
+        """ Initialize user settings form. """
+        UserPrefBase.__init__(self, request)
+        self.request = request
+        self._ = request.getText
+        self.cfg = request.cfg
+        self.title = self._("Notification")
+        self.name = 'notification'
+
+    def _decode_pagelist(self, key):
+        """ Decode list of pages from form input
+
+        Each line is a page name, empty lines ignored.
+
+        @param key: the form key to get
+        @rtype: list of unicode strings
+        @return: list of normalized names
+        """
+        text = self.request.form.get(key, [''])[0]
+        text = text.replace('\r', '')
+        items = []
+        for item in text.split('\n'):
+            item = item.strip()
+            if not item:
+                continue
+            items.append(item)
+        return items
+
+    def _save_notification_settings(self):
+        _ = self._
+        form = self.request.form
+
+        if self.request.request_method != 'POST':
+            return
+        theuser = self.request.user
+        if not theuser:
+            return
+
+        # subscription for page change notification
+        theuser.subscribed_pages = self._decode_pagelist('subscribed_pages')
+
+        # subscription to various events
+        available = events.get_subscribable_events()
+        theuser.email_subscribed_events = []
+        theuser.jabber_subscribed_events = []
+        types = {
+            'email': theuser.email_subscribed_events,
+            'jabber': theuser.jabber_subscribed_events
+        }
+        for tp in types:
+            for evt in available:
+                fieldname = 'subscribe:%s:%s' % (tp, evt)
+                if fieldname in form:
+                    types[tp].append(evt)
+        # save data
+        theuser.save()
+
+        return _("Notification settings saved!")
+
+
+    def handle_form(self):
+        _ = self._
+        form = self.request.form
+
+        if form.has_key('cancel'):
+            return
+
+        if form.has_key('save'): # Save user profile
+            return self._save_notification_settings()
+
+    # form generation part
+
+    def _event_select(self):
+        """ Create event subscription list. """
+        _ = self._
+
+        types = []
+        if self.cfg.mail_enabled and self.request.user.email:
+            types.append(('email', _("'''Email'''")))
+        if self.cfg.jabber_enabled and self.request.user.jid:
+            types.append(('jabber', _("'''Jabber'''")))
+
+        table = html.TABLE()
+        header = html.TR()
+        table.append(header)
+        for name, descr in types:
+            header.append(html.TH().append(html.Raw(descr)))
+        header.append(html.TH(align='left').append(html.Raw(_("'''Event type'''"))))
+
+        event_list = events.get_subscribable_events()
+        super = self.request.user.isSuperUser()
+
+        # Create a list of (value, name) tuples for display as radiobuttons
+        # Only include super-user visible events if current user has these rights.
+        # It's cosmetic - the check for super-user rights should be performed
+        # in event handling code as well!
+        allowed = []
+        for key in event_list.keys():
+            if not event_list[key]['superuser'] or super:
+                allowed.append((key, event_list[key]['desc']))
+
+        for evname, evdescr in allowed:
+            tr = html.TR()
+            table.append(tr)
+            for notiftype, notifdescr in types:
+                checked = evname in getattr(self.request.user,
+                                            '%s_subscribed_events' % notiftype)
+                tr.append(html.TD().append(html.INPUT(
+                        type='checkbox',
+                        checked=checked,
+                        name='subscribe:%s:%s' % (notiftype, evname))))
+            tr.append(html.TD().append(html.Raw(evdescr)))
+
+        return table
+
+    def create_form(self):
+        """ Create the complete HTML form code. """
+        _ = self._
+        self._form = self.make_form()
+
+        self._form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
+        self._form.append(html.INPUT(type="hidden", name="handler", value="prefs"))
+
+        if (not (self.cfg.mail_enabled and self.request.user.email)
+            and not (self.cfg.jabber_enabled and self.request.user.jid)):
+            self.make_row('', [html.Text(
+                _("Before you can be notified, you need to provide a way"
+                  " to contact you in the general preferences."))])
+            self.make_row('', [
+                html.INPUT(type="submit", name="cancel", value=_("Cancel"))])
+            return unicode(self._form)
+
+        self.make_row(_('Subscribed events'), [self._event_select()])
+
+        # subscribed pages
+        if self.cfg.mail_enabled:
+            # Get list of subscribe pages, DO NOT sort! it should
+            # stay in the order the user entered it in his input
+            # box.
+            notifylist = self.request.user.getSubscriptionList()
+
+            self.make_row(
+                html.Raw(_('Subscribed wiki pages[[BR]](one regex per line)')),
+                [html.TEXTAREA(name="subscribed_pages", rows="6", cols="50").append(
+                    '\n'.join(notifylist)), ],
+                valign="top"
+            )
+
+        # Add buttons
+        self.make_row('', [
+            html.INPUT(type="submit", name="save", value=_("Save")),
+            ' ',
+            html.INPUT(type="submit", name="cancel", value=_("Cancel"))])
+
+        return unicode(self._form)
+
+    def allowed(self):
+        return UserPrefBase.allowed(self) and (
+            self.cfg.mail_enabled or self.cfg.jabber_enabled)
--- a/MoinMoin/userprefs/oid.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/userprefs/oid.py	Fri Jul 20 01:56:41 2007 +0200
@@ -28,7 +28,8 @@
         self.request = request
         self._ = request.getText
         self.cfg = request.cfg
-        self.title = self._("OpenID settings")
+        _ = self._
+        self.title = _("OpenID settings", formatted=False)
         openid_auth = False
         if not _openid_disabled:
             for authm in self.request.cfg.auth:
--- a/MoinMoin/userprefs/prefs.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/userprefs/prefs.py	Fri Jul 20 01:56:41 2007 +0200
@@ -20,7 +20,6 @@
 # split the plugin into multiple preferences pages:
 #    - account details (name, email, timezone, ...)
 #    - wiki settings (editor, fancy diffs, theme, ...)
-#    - notification settings (trivial, subscribed pages, ...)
 #    - quick links (or leave in wiki settings?)
 ####
 
@@ -34,7 +33,8 @@
         self.request = request
         self._ = request.getText
         self.cfg = request.cfg
-        self.title = self._("Preferences")
+        _ = self._
+        self.title = _("Preferences", formatted=False)
         self.name = 'prefs'
 
     def _decode_pagelist(self, key):
@@ -194,13 +194,6 @@
         # quicklinks for navibar
         theuser.quicklinks = self._decode_pagelist('quicklinks')
 
-        # subscription for page change notification
-        theuser.subscribed_pages = self._decode_pagelist('subscribed_pages')
-
-        # subscription to various events
-        available = events.get_subscribable_events()
-        theuser.subscribed_events = [ev for ev in form.get('events', [])]
-
         # save data
         theuser.save()
         if theuser.disabled:
@@ -297,24 +290,6 @@
 
         return util.web.makeSelection('theme_name', options, cur_theme)
 
-    def _event_select(self):
-        """ Create event subscription list. """
-
-        event_list = events.get_subscribable_events()
-        selected = self.request.user.subscribed_events
-        super = self.request.user.isSuperUser()
-
-        # Create a list of (value, name) tuples for display in <select>
-        # Only include super-user visible events if current user has these rights.
-        # It's cosmetic - the check for super-user rights should be performed
-        # in event handling code as well!
-        allowed = []
-        for key in event_list.keys():
-            if not event_list[key]['superuser'] or super:
-                allowed.append((key, event_list[key]['desc']))
-
-        return util.web.makeMultiSelection('events', allowed, selectedvals=selected)
-
     def _editor_default_select(self):
         """ Create editor selection. """
         editor_default = self.request.user.valid and self.request.user.editor_default or self.cfg.editor_default
@@ -400,33 +375,6 @@
                     .append('\n'.join(self.request.user.getQuickLinks())),
             ], valign="top")
 
-            # FIXME: this depends on Jabber ATM, but may not do so in the future
-            if self.cfg.jabber_enabled:
-                self.make_row(_('Subscribed events'), [self._event_select()])
-
-            # subscribed pages
-            if self.cfg.mail_enabled:
-                # Get list of subscribe pages, DO NOT sort! it should
-                # stay in the order the user entered it in his input
-                # box.
-                notifylist = self.request.user.getSubscriptionList()
-
-                warning = []
-                if not self.request.user.email:
-                    warning = [
-                        html.BR(),
-                        html.SMALL(Class="warning").append(
-                            _("This list does not work, unless you have"
-                              " entered a valid email address!")
-                        )]
-
-                self.make_row(
-                    html.Raw(_('Subscribed wiki pages (one regex per line)')),
-                    [html.TEXTAREA(name="subscribed_pages", rows="6", cols="50").append(
-                        '\n'.join(notifylist)),
-                    ] + warning,
-                    valign="top"
-                )
             self._form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
             self._form.append(html.INPUT(type="hidden", name="handler", value="prefs"))
 
--- a/MoinMoin/userprefs/suid.py	Fri Jul 20 01:46:31 2007 +0200
+++ b/MoinMoin/userprefs/suid.py	Fri Jul 20 01:56:41 2007 +0200
@@ -19,7 +19,8 @@
         self.request = request
         self._ = request.getText
         self.cfg = request.cfg
-        self.title = self._("Switch user")
+        _ = self._
+        self.title = _("Switch user", formatted=False)
         self.name = 'suid'
 
     def allowed(self):