changeset 3038:07ab9d4b8bb8

bug fix for 1.6.0SupplementationAndAccessRights (thanks to Boleslaw Kulbabinski) (ported from 1.6)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 03 Feb 2008 21:55:18 +0100
parents c0d62e7f4fbc
children 744c46c1f869
files MoinMoin/action/supplementation.py MoinMoin/theme/__init__.py
diffstat 2 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/supplementation.py	Sun Feb 03 21:21:52 2008 +0100
+++ b/MoinMoin/action/supplementation.py	Sun Feb 03 21:55:18 2008 +0100
@@ -16,18 +16,24 @@
     sub_page_name = request.cfg.supplementation_page_name
     sub_page_template = request.cfg.supplementation_page_template
     newpagename = "%s/%s" % (pagename, sub_page_name)
+    errormsg = _("You are not allowed to create the supplementation page.", formatted=False)
 
     if pagename.endswith(sub_page_name): # sub_sub_page redirects to sub_page
         query = {}
         url = Page(request, pagename).url(request, query, relative=False)
         request.http_redirect(url)
-    elif request.user.may.read(newpagename) and request.user.may.write(newpagename):
+    elif request.user.may.read(newpagename):
         query = {}
         url = Page(request, newpagename).url(request, query, relative=False)
         test = Page(request, newpagename)
         if test.exists(): # page is defined -> redirect
             request.http_redirect(url)
-        else:  # page will be created from template
+        elif request.user.may.write(newpagename):  # page will be created from template
             query = {'action': 'edit', 'backto': newpagename, 'template': quoteWikinameURL(sub_page_template)}
             url = Page(request, newpagename).url(request, query, relative=False)
             request.http_redirect(url)
+        else:
+            request.theme.add_msg(errormsg, "error")
+    else:
+        request.theme.add_msg(errormsg, "error")
+        
\ No newline at end of file
--- a/MoinMoin/theme/__init__.py	Sun Feb 03 21:21:52 2008 +0100
+++ b/MoinMoin/theme/__init__.py	Sun Feb 03 21:55:18 2008 +0100
@@ -1107,11 +1107,21 @@
         return editbar_actions
 
     def supplementation_page_nameLink(self, page):
-        """  discussion for page """
+        """Return a link to the discussion page
+
+           If the discussion page doesn't exist and the user
+           has no right to create it, show a disabled link.
+	"""
         _ = self.request.getText
-        return page.link_to(self.request,
-                            text=_(self.request.cfg.supplementation_page_name, formatted=False),
-                            querystr={'action': 'supplementation'}, css_class='nbsupplementation', rel='nofollow')
+        suppl_name = self.request.cfg.supplementation_page_name
+        suppl_name_full = "%s/%s" % (page.page_name, suppl_name)
+
+        test = Page(self.request, suppl_name_full)
+        if not test.exists() and not self.request.user.may.write(suppl_name_full):
+            return ('<span class="disabled">%s</span>' % _(suppl_name, formatted=False))
+        else:
+            return page.link_to(self.request, text=_(suppl_name, formatted=False),
+                                querystr={'action': 'supplementation'}, css_class='nbsupplementation', rel='nofollow')
 
     def guiworks(self, page):
         """ Return whether the gui editor / converter can work for that page.