
page.getCategories() ne renvoie pas toujours le catégories de la page, mais parfois juste une liste vide. Du coup, lorsque ça arrive, on regarde dans le corps de la page (ce qui est à priori lent). Si la page à les acl All:read, on retourne immédiatement sans rien faire.
62 lines
2 KiB
Python
62 lines
2 KiB
Python
# -*- coding: iso-8859-1 -*-
|
|
"""
|
|
MoinMoin - CAS authentication
|
|
|
|
Jasig CAS (see http://www.jasig.org/cas) authentication module.
|
|
|
|
@copyright: 2012 MoinMoin:RichardLiao
|
|
@license: GNU GPL, see COPYING for details.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import time, re
|
|
import urlparse
|
|
import urllib, urllib2
|
|
from netaddr import IPNetwork, IPAddress
|
|
|
|
from MoinMoin import log
|
|
logging = log.getLogger(__name__)
|
|
|
|
from MoinMoin.auth import BaseAuth
|
|
from MoinMoin import user, wikiutil
|
|
from MoinMoin.Page import Page
|
|
from anonymous_user import AnonymousAuth
|
|
|
|
class PublicCategories(AnonymousAuth):
|
|
name = 'PublicCategories'
|
|
|
|
def __init__(self, pub_cats=[], auth_username="Connexion"):
|
|
AnonymousAuth.__init__(self, auth_username=auth_username)
|
|
self.pub_cats=pub_cats
|
|
|
|
def can_view(self, request):
|
|
p = urlparse.urlparse(request.url)
|
|
if p.path[1:] == "":
|
|
return False
|
|
if request.page is not None:
|
|
sys.stderr.write("Getting page from cache")
|
|
page = request.page
|
|
else:
|
|
page = Page(request, unicode(urllib.unquote(p.path[1:]),'utf-8'))
|
|
acl = page.getACL(request)
|
|
if acl.acl and [a[0] for a in acl.acl if a[0] == 'All' and a[1].get('read',False)]:
|
|
sys.stderr.write("acl All:read\n")
|
|
return False
|
|
categories = page.getCategories(request)
|
|
if categories:
|
|
for cat in self.pub_cats:
|
|
if cat in categories:
|
|
sys.stderr.write("%r dans la page %r\n" % (cat, p.path[1:]))
|
|
return True
|
|
else:
|
|
sys.stderr.write("categories is empty, searching in page body of %s\n" % p.path[1:])
|
|
body = page.getPageText()
|
|
for cat in self.pub_cats:
|
|
if cat in body:
|
|
sys.stderr.write("%r dans la page %r\n" % (cat, p.path[1:]))
|
|
return True
|
|
|
|
sys.stderr.write("%r n'est pas dans la page %r, %r\n" % (cat, p.path[1:], categories))
|
|
return False
|
|
|