changeset 4841:14c74ab59b45

Groups 2009: merged with the 1.9
author Dmitrijs Milajevs <dimazest@gmail.com>
date Thu, 09 Jul 2009 13:22:18 +0200
parents ce2667a4d982 (current diff) 5db0151a2df3 (diff)
children 654fdbbf4eb5
files MoinMoin/Page.py MoinMoin/security/__init__.py MoinMoin/wsgiapp.py
diffstat 11 files changed, 65 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/Page.py	Thu Jul 09 13:22:18 2009 +0200
@@ -1064,7 +1064,7 @@
         if 'deprecated' in pi:
             # deprecated page, append last backup version to current contents
             # (which should be a short reason why the page is deprecated)
-            request.theme.add_msg(_('The backed up content of this page is deprecated and will not be included in search results!'), "warning")
+            request.theme.add_msg(_('The backed up content of this page is deprecated and will ranked lower in search results!'), "warning")
 
             revisions = self.getRevList()
             if len(revisions) >= 2: # XXX shouldn't that be ever the case!? Looks like not.
--- a/MoinMoin/_tests/test_packages.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/_tests/test_packages.py	Thu Jul 09 13:22:18 2009 +0200
@@ -17,7 +17,7 @@
 from MoinMoin.action import AttachFile
 from MoinMoin.action.PackagePages import PackagePages
 from MoinMoin.packages import Package, ScriptEngine, MOIN_PACKAGE_FILE, ZipPackage, packLine, unpackLine
-from MoinMoin._tests import become_superuser, create_page, nuke_page
+from MoinMoin._tests import become_trusted, become_superuser, create_page, nuke_page
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
 
@@ -137,6 +137,7 @@
         return zip_file
 
     def testAttachments_after_page_creation(self):
+        become_trusted(self.request)
         pagename = u'PackageTestPageCreatedFirst'
         page = create_page(self.request, pagename, u"This page has not yet an attachments dir")
         script = u"""MoinMoinPackage|1
@@ -154,6 +155,7 @@
         os.unlink(zip_file)
 
     def testAttachments_without_page_creation(self):
+        become_trusted(self.request)
         pagename = u"PackageAttachmentAttachWithoutPageCreation"
         script = u"""MoinMoinPackage|1
 AddAttachment|1_attachment|my_test.txt|%(pagename)s
--- a/MoinMoin/action/_tests/test_attachfile.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/action/_tests/test_attachfile.py	Thu Jul 09 13:22:18 2009 +0200
@@ -56,7 +56,10 @@
         """
         Tests if AttachFile.getFilename creates the attachment dir on self.requesting
         """
+        become_trusted(self.request)
+
         filename = ""
+
         file_exists = os.path.exists(AttachFile.getFilename(self.request, self.pagename, filename))
 
         nuke_page(self.request, self.pagename)
--- a/MoinMoin/macro/WantedPages.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/macro/WantedPages.py	Thu Jul 09 13:22:18 2009 +0200
@@ -36,6 +36,7 @@
 
     # build a dict of wanted pages
     wanted = {}
+    deprecated_links = []
     for name, page in pages.items():
         # Skip system pages, because missing translations are not wanted pages,
         # unless you are a translator and clicked "Include system pages"
@@ -44,13 +45,22 @@
 
         # Add links to pages which do not exist in pages dict
         links = page.getPageLinks(request)
+        is_deprecated = page.parse_processing_instructions(
+                ).get('deprecated', False)
+
         for link in links:
             if not link in pages and request.user.may.read(link):
+                if is_deprecated:
+                    deprecated_links.append(link)
                 if link in wanted:
                     wanted[link][name] = 1
                 else:
                     wanted[link] = {name: 1}
 
+    for link in deprecated_links:
+        if len(wanted[link]) == 1:
+            del wanted[link]
+
     # Check for the extreme case when there are no wanted pages
     if not wanted:
         return u"%s<p>%s</p>" % (controlbar, _("No wanted pages in this wiki."))
--- a/MoinMoin/macro/_tests/test_GetVal.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/macro/_tests/test_GetVal.py	Thu Jul 09 13:22:18 2009 +0200
@@ -23,23 +23,24 @@
     def teardown_class(self):
         nuke_page(self.request, self.pagename)
 
-    def _test_macro(self, name, args):
-        m = make_macro(self.request, self.page)
+    def _test_macro(self, name, args, page):
+        m = make_macro(self.request, page)
         return m.execute(name, args)
 
     def testGetValNoACLs(self):
         """ macro GetVal test: 'reads VAR' """
-        self.page = create_page(self.request, self.pagename, u' VAR:: This is an example')
-        result = self._test_macro(u'GetVal', "%s,%s" % (self.pagename, u'VAR'))
+        page = create_page(self.request, self.pagename, u' VAR:: This is an example')
+        result = self._test_macro(u'GetVal', "%s,%s" % (self.pagename, u'VAR'), page)
         assert result == "This is an example"
 
     def testGetValAfterADictPageIsDeleted(self):
         """ macro GetVal test: 'reads Dict var after another Dict is removed' """
         request = self.request
+        become_trusted(request)
         page = create_page(request, u'SomeDict', u" EXAMPLE:: This is an example text")
         page.deletePage()
         page = create_page(request, self.pagename, u' VAR:: This is a brand new example')
-        result = self._test_macro(u'GetVal', "%s,%s" % (self.pagename, u'VAR'))
+        result = self._test_macro(u'GetVal', "%s,%s" % (self.pagename, u'VAR'), page)
         nuke_page(request, u'SomeDict')
         assert result == "This is a brand new example"
 
--- a/MoinMoin/parser/_tests/test_text_moin_wiki.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/parser/_tests/test_text_moin_wiki.py	Thu Jul 09 13:22:18 2009 +0200
@@ -161,7 +161,7 @@
         (u'<<DateTime(2003-03-03T03:03:03)>>',   '2003-03-03 03:03:03'),
         (u'<<DateTime(2000-01-01T00:00:00Z)>>',  '2000-01-01 00:00:00'), # works for Europe/Vilnius
         (u'<<Date(2002-02-02T01:02:03Z)>>',      '2002-02-02'),
-        (u'<<DateTime(1970-01-06T00:00:00)>>',   '1970-01-06 00:00:00'), # fails e.g. for Europe/Vilnius
+        #(u'<<DateTime(1970-01-06T00:00:00)>>',   '1970-01-06 00:00:00'), # fails e.g. for Europe/Vilnius
         )
 
     def testDateTimeMacro(self):
@@ -171,7 +171,8 @@
     If this fails, it is likely a problem in your python / libc,
     not in moin.  See also: <http://sourceforge.net/tracker/index.php?func=detail&aid=902172&group_id=5470&atid=105470>
 
-    It can also be related to TZ changes a country historically made.
+    It can also be related to TZ changes a country historically made and then
+    shows a bug in moin. For this reason, the last tuple above is commented out.
     """
 
         for test, expected in self._tests:
--- a/MoinMoin/search/_tests/test_search.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/search/_tests/test_search.py	Thu Jul 09 13:22:18 2009 +0200
@@ -11,6 +11,7 @@
 
 from MoinMoin.search import QueryError
 from MoinMoin.search.queryparser import QueryParser
+from MoinMoin.search import Xapian
 from MoinMoin import search
 
 
@@ -93,7 +94,7 @@
     def testTitleSearchNegativeTerm(self):
         """ search: title search for a AND expression with a negative term """
         helpon_count = len(search.searchPages(self.request, u"title:HelpOn").hits)
-        result = search.searchPages(self.request, u"title:HelpOn -title:Acl")
+        result = search.searchPages(self.request, u"title:HelpOn -title:AccessControlLists")
         assert len(result.hits) == helpon_count - 1 # finds all HelpOn* except one
 
     def testFullSearchNegatedFindAll(self):
@@ -108,5 +109,24 @@
         assert 0 < len(result.hits) < helpon_count
 
 
+class TestXapianIndex:
+    """ search: test Xapian indexing """
+
+    def testIndex(self):
+        """ search: kicks off indexing for a single pages in Xapian """
+
+        # AD - This only tests the the call to indexing doesn't raise.
+
+        idx = Xapian.Index(self.request)
+        idx.indexPages(['HomePageWiki'], mode='add')
+
+    def testIndexInNewThread(self):
+        """ search: kicks off indexing for a page in a new thread in Xapian"""
+
+        # AD - This only tests the the call to indexing doesn't raise.
+
+        idx = Xapian.Index(self.request)
+        idx.indexPagesInNewThread(['HomePageWiki'], mode='add')
+
 coverage_modules = ['MoinMoin.search']
 
--- a/MoinMoin/search/results.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/search/results.py	Thu Jul 09 13:22:18 2009 +0200
@@ -118,6 +118,8 @@
             weight += match.weight()
             # More sophisticated things to be added, like increase
             # weight of near matches.
+        if self.page.parse_processing_instructions().get('deprecated', False):
+            weight = int(weight / 4) # rank it down
         return weight
 
     def add_matches(self, matches):
--- a/MoinMoin/security/__init__.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/security/__init__.py	Thu Jul 09 13:22:18 2009 +0200
@@ -69,6 +69,10 @@
                 allowed = acl.may(request, username, right)
                 if allowed is not None:
                     return allowed
+                # If the item has an acl (even one that doesn't match) we *do not*
+                # check the parents. We only check the parents if there's no acl on
+                # the item at all.
+                break
         if not some_acl:
             allowed = cache.acl_rights_default.may(request, username, right)
             if allowed is not None:
--- a/MoinMoin/security/_tests/test_security.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/security/_tests/test_security.py	Thu Jul 09 13:22:18 2009 +0200
@@ -245,10 +245,14 @@
     """
     mainpage_name = u'AclTestMainPage'
     subpage_name = u'AclTestMainPage/SubPage'
+    item_rwforall = u'EveryoneMayReadWriteMe'
+    subitem_4boss = u'EveryoneMayReadWriteMe/OnlyTheBossMayWMe'
     pages = [
         # pagename, content
         (mainpage_name, u"#acl JoeDoe:\n#acl JaneDoe:read,write\nFoo!"),
         (subpage_name, u"FooFoo!"),
+        (item_rwforall, u"#acl All:read,write\nMay be read from and written to by anyone"),
+        (subitem_4boss, u"#acl JoeDoe:read,write\nOnly JoeDoe (the boss) may write"),
     ]
 
     from MoinMoin._tests import wikiconfig
@@ -294,6 +298,8 @@
             (True,  self.subpage_name, u'JoeDoe', []), # by inherited acl from main page
             (False, self.subpage_name, u'JaneDoe', ['read', 'write']), # by default acl
             (True,  self.subpage_name, u'JaneDoe', ['read', 'write']), # by inherited acl from main page
+            (True,  self.subitem_4boss, u'AnyUser', ['read']), # by after acl
+            (True,  self.subitem_4boss, u'JoeDoe', ['read', 'write']), # by item acl
         ]
 
         for hierarchic, pagename, username, may in tests:
--- a/MoinMoin/wsgiapp.py	Thu Jul 09 11:06:53 2009 +0200
+++ b/MoinMoin/wsgiapp.py	Thu Jul 09 13:22:18 2009 +0200
@@ -38,6 +38,11 @@
 
     context.lang = setup_i18n_postauth(context)
 
+    def finish():
+        pass
+
+    context.finish = finish
+
     context.reset()
 
     context.clock.stop('init')
@@ -71,6 +76,7 @@
         except MoinMoinFinish:
             return request
     finally:
+        context.finish()
         context.clock.stop('run')
 
 def remove_prefix(path, prefix=None):