Fix ACLs
authorBernardo Innocenti <bernie@codewiz.org>
Sun, 23 Sep 2007 06:02:34 +0000 (08:02 +0200)
committerBernardo Innocenti <bernie@codewiz.org>
Sun, 23 Sep 2007 06:02:34 +0000 (08:02 +0200)
geekigeeki.css
geekigeeki.py

index d56bb96b54eeb618a4e250bb1c2f431bc7a8b76b..8c4b9eb46247bb04694e92636b54cb8f5792778b 100755 (executable)
@@ -14,24 +14,12 @@ body {
        margin-right: 0px;
 }
 
-a {
-       color: #1010FF;
-}
-a:visited {
-       color: #501080;
-}
-
-a.nonexistent {
-       color: #D04040;
-}
-
-a.navlink {
-       font-size: smaller;
-}
-
-a.external {
-       font-style: italic;
-}
+a { color: #1010FF; }
+a:visited { color: #501080; }
+a.nonexistent { color: #D04040; }
+a.navlink { font-size: smaller; }
+a.external { font-style: italic; }
+a.heading { text-decoration: none; color: #aaaaaa; font-size: smaller; }
 
 h1 {
        font-size: x-large;
@@ -150,6 +138,10 @@ div.preview {
        border: 2px dashed #FF0000;
 }
 
+div.index {
+       border: 1px solid #EEEEEE;
+}
+
 div.nav {
        border-color: #cc9933;
        background-color: #ffcc66;
index 46c61c55ad5343f95bbf6541eb959a6cab0f0638..9fd1adf5a139c1ba32152a9eb6270b2847f8227b 100755 (executable)
@@ -154,8 +154,7 @@ def link_tag(params, text=None, ss_class=None, authentication=False):
     classattr = ''
     if ss_class:
         classattr += 'class="%s" ' % ss_class
-        # Prevent crawlers from following links to generated pages
-        # and links added by potential spammers
+        # Prevent crawlers from following links potentially added by spammers or to generated pages
         if ss_class == 'external' or ss_class == 'navlink':
             classattr += 'rel="nofollow" '
     if authentication:
@@ -355,12 +354,12 @@ class PageFormatter:
 
     def _tit_repl(self, word):
         if self.h_level:
-            result = "</h%d></a>" % self.h_level
+            result = '</h%d>' % self.h_level
             self.h_level = 0
         else:
             self.h_level = len(word) - 1
             self.h_count += 1
-            result = '<a href="#%d"><h%d id="%d">' % (self.h_count, self.h_level, self.h_count)
+            result = '<h%d id="%d"><a class="heading" href="#%d">*</a> ' % (self.h_level, self.h_count, self.h_count)
         return result
 
     def _rule_repl(self, word):
@@ -487,7 +486,7 @@ class PageFormatter:
             raise "Can't handle match " + `match`
 
     def print_html(self):
-        print "<div class='wiki'><p>"
+        print '<div class="wiki"><p>'
 
         # For each line, we scan through looking for magic
         # strings, outputting verbatim any intervening text
@@ -552,7 +551,7 @@ class PageFormatter:
         if self.in_pre: print '</pre>'
         if self.in_table: print '</tbody></table><p>'
         print self._undent()
-        print "</p></div>"
+        print '</p></div>'
 
 # ----------------------------------------------------------
 class Page:
@@ -621,27 +620,38 @@ class Page:
                 raise er
         return self.attrs
 
-    def can_edit(self):
+    def can(self, action, default=True):
         attrs = self.get_attrs()
         try:
             # SomeUser:read,write All:read
             acl = attrs["acl"]
             for rule in acl.split():
-                (user,perms) = acl.split(':')
+                (user,perms) = rule.split(':')
                 if user == remote_user() or user == "All":
-                    if 'write' in perms.split(','):
+                    if action in perms.split(','):
                         return True
+                    else:
+                        return False
             return False
-        except:
+        except Exception, er:
             pass
-        return True
+        return default
+
+    def can_write(self):
+        return self.can("write", True)
+
+    def can_read(self):
+        return self.can("read", True)
 
     def send_page(self):
         page_name = None
-        if self.can_edit():
+        if self.can_write():
             page_name = self.page_name
         send_title(page_name, self.split_title(), msg=self.msg, msg_type=self.msg_type)
-        PageFormatter(self.get_raw_body()).print_html()
+        if self.can_read():
+            PageFormatter(self.get_raw_body()).print_html()
+        else:
+            print "<p>This page is not visible to you</p>"
         send_footer(page_name, self._last_modified())
 
     def _last_modified(self):
@@ -725,8 +735,7 @@ try:
     # Configuration values
     site_name = 'Codewiz'
 
-    # set to None for read-only sites
-    # leave empty ('') to allow anonymous edits
+    # set to None for read-only sites, leave empty ('') to allow anonymous edits
     # otherwise, set to a URL that requires authentication
     privileged_url = 'https://www.codewiz.org/~bernie/wiki'