changeset 1297:2625857eabf0

Merge with main
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Tue, 15 Aug 2006 22:37:09 +0200
parents 93ecff3f806f (current diff) 655978c9f6c3 (diff)
children d1a4083fc36e
files
diffstat 9 files changed, 104 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Tue Aug 15 21:52:22 2006 +0200
+++ b/.hgignore	Tue Aug 15 22:37:09 2006 +0200
@@ -4,4 +4,5 @@
 sa
 cover
 testwiki
+wiki/underlay
 
--- a/MoinMoin/Page.py	Tue Aug 15 21:52:22 2006 +0200
+++ b/MoinMoin/Page.py	Tue Aug 15 22:37:09 2006 +0200
@@ -1655,7 +1655,7 @@
         try:
             lastRevision = self.getRevList()[0]
         except IndexError:
-            return security.AccessControlList(self.request)
+            return security.AccessControlList(self.request.cfg)
         body = Page(self.request, self.page_name,
                     rev=lastRevision).get_raw_body()
         return security.parseACL(self.request, body)
--- a/MoinMoin/_tests/test_security.py	Tue Aug 15 21:52:22 2006 +0200
+++ b/MoinMoin/_tests/test_security.py	Tue Aug 15 22:37:09 2006 +0200
@@ -204,7 +204,7 @@
             "BadGuy:  "
             "All:read  "
             ]
-        acl = security.AccessControlList(self.request, acl_rights)
+        acl = security.AccessControlList(self.request.cfg, acl_rights)
 
         # Should apply these rights:
         users = (
--- a/MoinMoin/action/fullsearch.py	Tue Aug 15 21:52:22 2006 +0200
+++ b/MoinMoin/action/fullsearch.py	Tue Aug 15 22:37:09 2006 +0200
@@ -92,18 +92,27 @@
     # Start content (important for RTL support)
     request.write(request.formatter.startContent("content"))
 
-    # First search stats
-    request.write(results.stats(request, request.formatter, hitsFrom))
+    # Did we get any hits?
+    if results.hits:
+        # First search stats
+        request.write(results.stats(request, request.formatter, hitsFrom))
 
-    # Then search results
-    info = not titlesearch
-    if context:
-        output = results.pageListWithContext(request, request.formatter,
-                info=info, context=context, hitsFrom=hitsFrom)
+        # Then search results
+        info = not titlesearch
+        if context:
+            output = results.pageListWithContext(request, request.formatter,
+                    info=info, context=context, hitsFrom=hitsFrom)
+        else:
+            output = results.pageList(request, request.formatter, info=info,
+                    hitsFrom=hitsFrom)
+        request.write(output)
     else:
-        output = results.pageList(request, request.formatter, info=info,
-                hitsFrom=hitsFrom)
-    request.write(output)
+        f = request.formatter
+        request.write(''.join([
+            f.heading(1, 3),
+            f.text(_('Your search query didn\'t return any results.')),
+            f.heading(0, 3),
+        ]))
 
     request.write(request.formatter.endContent())
     request.theme.send_footer(pagename)
--- a/MoinMoin/action/info.py	Tue Aug 15 21:52:22 2006 +0200
+++ b/MoinMoin/action/info.py	Tue Aug 15 22:37:09 2006 +0200
@@ -90,7 +90,7 @@
         may_revert = request.user.may.revert(pagename)
 
         def render_action(text, query, **kw):
-            kw.update(rel='nofollow')
+            kw.update(dict(rel='nofollow'))
             if 0: # diff button doesnt work XXX
                 params_html = []
                 for k, v in query.items():
--- a/MoinMoin/config/multiconfig.py	Tue Aug 15 21:52:22 2006 +0200
+++ b/MoinMoin/config/multiconfig.py	Tue Aug 15 22:37:09 2006 +0200
@@ -15,6 +15,7 @@
 from MoinMoin import error, util, wikiutil
 import MoinMoin.auth as authmodule
 from MoinMoin.packages import packLine
+from MoinMoin.security import AccessControlList
 
 _url_re_cache = None
 _farmconfig_mtime = None
@@ -557,6 +558,10 @@
         # Cache variables for the properties below
         self._iwid = self._iwid_full = self._meta_dict = None
 
+        self._acl_rights_before = AccessControlList(self, [self.acl_rights_before])
+        self._acl_rights_default = AccessControlList(self, [self.acl_rights_default])
+        self._acl_rights_after = AccessControlList(self, [self.acl_rights_after])
+
     def load_meta_dict(self):
         """ The meta_dict contains meta data about the wiki instance. """
         if getattr(self, "_meta_dict", None) is None:
--- a/MoinMoin/macro/SystemInfo.py	Tue Aug 15 21:52:22 2006 +0200
+++ b/MoinMoin/macro/SystemInfo.py	Tue Aug 15 22:37:09 2006 +0200
@@ -115,14 +115,18 @@
     from MoinMoin.search.builtin import Search
     xapState = (_('Disabled'), _('Enabled'))
     idxState = (_('index available'), _('index unavailable'))
-    idx = Search._xapianIndex(request)
-    available = idx and idxState[0] or idxState[1]
-    mtime = _('last modified: %s') % (idx and
-            request.user.getFormattedDateTime(
-                wikiutil.version2timestamp(idx.mtime())) or
-                _('N/A'))
-    row(_('Xapian search'), '%s, %s, %s'
-            % (xapState[request.cfg.xapian_search], available, mtime))
+    xapRow = xapState[request.cfg.xapian_search]
+
+    if request.cfg.xapian_search:
+        idx = Search._xapianIndex(request)
+        available = idx and idxState[0] or idxState[1]
+        mtime = _('last modified: %s') % (idx and
+                request.user.getFormattedDateTime(
+                    wikiutil.version2timestamp(idx.mtime())) or
+                    _('N/A'))
+        xapRow += ', %s, %s' % (available, mtime)
+
+    row(_('Xapian search'), xapRow)
     row(_('Xapian stemming'), xapState[request.cfg.xapian_stemming])
 
     row(_('Active threads'), t_count or _('N/A'))
--- a/MoinMoin/mail/mailimport.py	Tue Aug 15 21:52:22 2006 +0200
+++ b/MoinMoin/mail/mailimport.py	Tue Aug 15 22:37:09 2006 +0200
@@ -77,16 +77,16 @@
     html_data = []
     text_data = []
 
-    to_addr = get_addrs(message, 'To')[0]
     from_addr = get_addrs(message, 'From')[0]
+    to_addrs = get_addrs(message, 'To')
     cc_addrs = get_addrs(message, 'Cc')
     bcc_addrs = get_addrs(message, 'Bcc')
-    target_addrs = [to_addr] + cc_addrs + bcc_addrs
+    target_addrs = to_addrs + cc_addrs + bcc_addrs
 
     subject = decode_2044(message['Subject'])
     date = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(mktime_tz(parsedate_tz(message['Date']))))
 
-    log("Processing mail:\n To: %r\n From: %r\n Subject: %r" % (to_addr, from_addr, subject))
+    log("Processing mail:\n To: %r\n From: %r\n Subject: %r" % (to_addrs[0], from_addr, subject))
 
     for part in message.walk():
         log(" Part " + repr((part.get_charsets(), part.get_content_charset(), part.get_content_type(), part.is_multipart(), )))
@@ -117,14 +117,13 @@
 
     return {'text': u"".join(text_data), 'html': u"".join(html_data),
             'attachments': attachments,
-            'target_addrs': target_addrs, 'to_addr': to_addr, 'cc_addrs': cc_addrs, 'bcc_addrs': bcc_addrs,
+            'target_addrs': target_addrs, 'to_addrs': to_addrs, 'cc_addrs': cc_addrs, 'bcc_addrs': bcc_addrs,
             'from_addr': from_addr,
             'subject': subject, 'date': date}
 
-def get_pagename_content(msg, email_subpage_template, wiki_address):
+def get_pagename_content(request, msg, email_subpage_template, wiki_address):
     """ Generates pagename and content according to the specification
         that can be found on MoinMoin:FeatureRequests/WikiEmailintegration """
-
     generate_summary = False
     choose_html = True
 
@@ -147,6 +146,10 @@
         if pagename_tpl[-1] == pagename_tpl[0] == "'":
             pagename_tpl = pagename_tpl[1:-1]
 
+    if not msg['subject'].strip():
+        msg['subject'] = '(...)' # we need non-empty subject
+
+    pagename_tpl = pagename_tpl.strip()
     if pagename_tpl.endswith("/"):
         pagename_tpl += email_subpage_template
 
@@ -163,6 +166,8 @@
         generate_summary = True
         pagename = pagename[1:].lstrip()
 
+    pagename = request.normalizePagename(pagename)
+
     if choose_html and msg['html']:
         content = "{{{#!html\n%s\n}}}" % msg['html'].replace("}}}", "} } }")
     else:
@@ -194,7 +199,7 @@
     if not request.user:
         raise ProcessingError("No suitable user found for mail address %r" % (msg['from_addr'][1], ))
 
-    d = get_pagename_content(msg, email_subpage_template, wiki_address)
+    d = get_pagename_content(request, msg, email_subpage_template, wiki_address)
     pagename = d['pagename']
     generate_summary = d['generate_summary']
 
@@ -235,9 +240,14 @@
     # assemble old page content and new mail body together
     old_content = Page(request, pagename).get_raw_body()
     if old_content:
-        new_content = u"%s\n-----\n%s" % (old_content, d['content'], )
+        new_content = u"%s\n-----\n" % old_content
     else:
-        new_content = d['content']
+        new_content = ''
+
+    if not (generate_summary and "/" in pagename):
+        new_content += u"'''Mail: %s (%s, [[DateTime(%s)]])'''\n\n" % (msg['subject'], email_to_markup(request, msg['from_addr']), msg['date'])
+
+    new_content += d['content']
     new_content += "\n" + u"\n * ".join(attachment_links)
 
     try:
@@ -260,17 +270,16 @@
                 break
 
         table_header = (u"\n\n## mail_overview (don't delete this line)\n" +
-                        u"|| '''[[GetText(From)]] ''' || '''[[GetText(To)]] ''' || '''[[GetText(Subject)]] ''' || '''[[GetText(Date)]] ''' || '''[[GetText(Link)]] ''' || '''[[GetText(Attachments)]] ''' ||\n"
+                        u"|| '''[[GetText(From)]] ''' || '''[[GetText(To)]] ''' || '''[[GetText(Content)]] ''' || '''[[GetText(Date)]] ''' || '''[[GetText(Attachments)]] ''' ||\n"
                        )
 
         from_col = email_to_markup(request, msg['from_addr'])
-        to_col = ' '.join([email_to_markup(request, (realname, mailaddr)) for realname, mailaddr in msg['target_addrs'] if mailaddr != wiki_address])
-        subj_col = msg['subject']
+        to_col = ' '.join([email_to_markup(request, (realname, mailaddr))
+                           for realname, mailaddr in msg['target_addrs'] if mailaddr != wiki_address])
+        subj_col = '["%s" %s]' % (pagename, msg['subject'])
         date_col = msg['date']
-        page_col = pagename
         attach_col = " ".join(attachment_links)
-        new_line = u'|| %s || %s || %s || [[DateTime(%s)]] || ["%s"] || %s ||' % (
-                    from_col, to_col, subj_col, date_col, page_col, attach_col)
+        new_line = u'|| %s || %s || %s || [[DateTime(%s)]] || %s ||' % (from_col, to_col, subj_col, date_col, attach_col)
         if found_table is not None:
             content = "\n".join(old_content[:table_ends] + [new_line] + old_content[table_ends:])
         else:
--- a/MoinMoin/security/__init__.py	Tue Aug 15 21:52:22 2006 +0200
+++ b/MoinMoin/security/__init__.py	Tue Aug 15 22:37:09 2006 +0200
@@ -169,38 +169,23 @@
 
     special_users = ["All", "Known", "Trusted"] # order is important
 
-    def __init__(self, request, lines=[]):
+    def __init__(self, cfg, lines=[]):
         """Initialize an ACL, starting from <nothing>.
         """
-        self.setLines(request.cfg, lines)
-
-    def setLines(self, cfg, lines=[]):
-        self.clean()
-        self.addBefore(cfg)
-        if not lines:
-            self.addDefault(cfg)
+        self._is_group = {}
+        if lines:
+            self.acl = [] # [ ('User', {"read": 0, ...}), ... ]
+            self.acl_lines = []
+            for line in lines:
+                self._addLine(cfg, line)
         else:
-            for line in lines:
-                self.addLine(cfg, line)
-        self.addAfter(cfg)
+            self.acl = None
+            self.acl_lines = None
 
-    def clean(self):
-        self.acl = [] # [ ('User', {"read": 0, ...}), ... ]
-        self.acl_lines = []
-        self._is_group = {}
-
-    def addBefore(self, cfg):
-        self.addLine(cfg, cfg.acl_rights_before, remember=0)
-    def addDefault(self, cfg):
-        self.addLine(cfg, cfg.acl_rights_default, remember=0)
-    def addAfter(self, cfg):
-        self.addLine(cfg, cfg.acl_rights_after, remember=0)
-
-    def addLine(self, cfg, aclstring, remember=1):
+    def _addLine(self, cfg, aclstring, remember=1):
         """ Add another ACL line
 
-        This can be used in multiple subsequent calls to process longer
-        lists.
+        This can be used in multiple subsequent calls to process longer lists.
 
         @param cfg: current config
         @param aclstring: acl string from page or cfg
@@ -216,26 +201,25 @@
         acliter = ACLStringIterator(cfg.acl_rights_valid, aclstring)
         for modifier, entries, rights in acliter:
             if entries == ['Default']:
-                self.addDefault(cfg)
-                continue
-
-            for entry in entries:
-                if group_re.search(entry):
-                    self._is_group[entry] = 1
-                rightsdict = {}
-                if modifier:
-                    # Only user rights are added to the right dict.
-                    # + add rights with value of 1
-                    # - add right with value of 0
-                    for right in rights:
-                        rightsdict[right] = (modifier == '+')
-                else:
-                    # All rights from acl_rights_valid are added to the
-                    # dict, user rights with value of 1, and other with
-                    # value of 0
-                    for right in cfg.acl_rights_valid:
-                        rightsdict[right] = (right in rights)
-                self.acl.append((entry, rightsdict))
+                self._addLine(cfg, cfg.acl_rights_default, remember=0)
+            else:
+                for entry in entries:
+                    if group_re.search(entry):
+                        self._is_group[entry] = 1
+                    rightsdict = {}
+                    if modifier:
+                        # Only user rights are added to the right dict.
+                        # + add rights with value of 1
+                        # - add right with value of 0
+                        for right in rights:
+                            rightsdict[right] = (modifier == '+')
+                    else:
+                        # All rights from acl_rights_valid are added to the
+                        # dict, user rights with value of 1, and other with
+                        # value of 0
+                        for right in cfg.acl_rights_valid:
+                            rightsdict[right] = (right in rights)
+                    self.acl.append((entry, rightsdict))
 
     def may(self, request, name, dowhat):
         """May <name> <dowhat>?
@@ -243,8 +227,10 @@
         """
         is_group_member = request.dicts.has_member
 
+        acl_page = self.acl or request.cfg._acl_rights_default.acl
+        acl = request.cfg._acl_rights_before.acl + acl_page + request.cfg._acl_rights_after.acl
         allowed = None
-        for entry, rightsdict in self.acl:
+        for entry, rightsdict in acl:
             if entry in self.special_users:
                 handler = getattr(self, "_special_"+entry, None)
                 allowed = handler(request, name, dowhat, rightsdict)
@@ -266,7 +252,11 @@
 
     def getString(self, b='#acl ', e='\n'):
         """print the acl strings we were fed with"""
-        return ''.join(["%s%s%s" % (b, l, e) for l in self.acl_lines])
+        if self.acl_lines:
+            acl_lines = ''.join(["%s%s%s" % (b, l, e) for l in self.acl_lines])
+        else:
+            acl_lines = ''
+        return acl_lines
 
     def _special_All(self, request, name, dowhat, rightsdict):
         return rightsdict.get(dowhat)
@@ -291,6 +281,7 @@
 
     def __eq__(self, other):
         return self.acl_lines == other.acl_lines
+
     def __ne__(self, other):
         return self.acl_lines != other.acl_lines
 
@@ -403,5 +394,5 @@
             else:
                 args = ""
             acl_lines.append(args)
-    return AccessControlList(request, acl_lines)
+    return AccessControlList(request.cfg, acl_lines)