[CalendarServer-changes] [3163] CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Thu Oct 16 16:34:50 PDT 2008
Revision: 3163
http://trac.macosforge.org/projects/calendarserver/changeset/3163
Author: sagen at apple.com
Date: 2008-10-16 16:34:49 -0700 (Thu, 16 Oct 2008)
Log Message:
-----------
Checkpoint of work in progress
Modified Paths:
--------------
CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/directory/calendar.py
CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/directory/wiki.py
CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/root.py
Modified: CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/directory/calendar.py
===================================================================
--- CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/directory/calendar.py 2008-10-16 03:16:45 UTC (rev 3162)
+++ CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/directory/calendar.py 2008-10-16 23:34:49 UTC (rev 3163)
@@ -422,8 +422,7 @@
returnValue(request.wikiACL)
# query the wiki server
- # import pdb; pdb.set_trace()
- request.wikiACL = yield (getWikiACL(request, request.wikiUser,
+ request.wikiACL = yield (getWikiACL(request,
self.record.shortName))
returnValue(request.wikiACL)
Modified: CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/directory/wiki.py
===================================================================
--- CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/directory/wiki.py 2008-10-16 03:16:45 UTC (rev 3162)
+++ CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/directory/wiki.py 2008-10-16 23:34:49 UTC (rev 3163)
@@ -25,14 +25,18 @@
from twisted.python.filepath import FilePath
from twisted.web2.dav import davxml
-from twisted.web.xmlrpc import Proxy
+from twisted.web.xmlrpc import Proxy, Fault
from twisted.web2.http import HTTPError, StatusResponse
+from twisted.internet.defer import inlineCallbacks, returnValue
+
+from twisted.web2.dav.resource import TwistedACLInheritable
from twistedcaldav.config import config
from twistedcaldav.py.plistlib import readPlist
from twistedcaldav.directory.directory import (DirectoryService,
DirectoryRecord,
UnknownRecordTypeError)
+from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
class WikiDirectoryService(DirectoryService):
"""
@@ -40,7 +44,7 @@
"""
baseGUID = "d79ef1e0-9a42-11dd-ad8b-0800200c9a66"
- realmName = None
+ realmName = "Wiki"
recordType_wikis = "wikis"
@@ -112,52 +116,73 @@
return super(WikiDirectoryRecord, self).verifyCredentials(credentials)
-def getWikiACL(request, userID, wikiID):
+ at inlineCallbacks
+def getWikiACL(request, wikiID):
- def wikiACLSuccess(access):
- import pdb; pdb.set_trace()
+ wikiConfig = config.Authentication["Wiki"]
+ userID = "unauthenticated"
+
+ try:
+ url = str(request.authzUser.children[0])
+ principal = (yield request.locateResource(url))
+ if isinstance(principal, DirectoryCalendarPrincipalResource):
+ userID = principal.record.guid
+ except:
+ # TODO: better error handling
+ pass
+
+ proxy = Proxy(wikiConfig["URL"])
+ try:
+
+ access = (yield proxy.callRemote(wikiConfig["WikiMethod"],
+ userID, wikiID))
+
+
if access == "read":
- return davxml.ACL(
- (
+ returnValue(
+ davxml.ACL(
davxml.ACE(
request.authnUser,
davxml.Grant(
davxml.Privilege(davxml.Read()),
),
- ),
+ TwistedACLInheritable(),
+ )
)
)
elif access in ("write", "admin"):
- return davxml.ACL(
- (
+ returnValue(
+ davxml.ACL(
davxml.ACE(
request.authnUser,
davxml.Grant(
davxml.Privilege(davxml.Read()),
),
+ TwistedACLInheritable(),
),
davxml.ACE(
request.authnUser,
davxml.Grant(
davxml.Privilege(davxml.Write()),
),
- ),
+ TwistedACLInheritable(),
+ )
)
)
else:
- return davxml.ACL( )
+ returnValue( davxml.ACL( ) )
- def wikiACLFailure(error):
- if error.value.faultCode == 12:
- raise HTTPError(StatusResponse(404, error.value.faultString))
+ except Fault, fault:
- return davxml.ACL( )
+ # return wikiACLSuccess("write")
- wikiConfig = config.Authentication["Wiki"]
+ if fault.faultCode == 2:
+ raise HTTPError(StatusResponse(403, fault.faultString))
- proxy = Proxy(wikiConfig["URL"])
- d = proxy.callRemote(wikiConfig["WikiMethod"], userID, wikiID).addCallbacks(
- wikiACLSuccess, wikiACLFailure)
- return d
+ elif fault.faultCode == 12:
+ raise HTTPError(StatusResponse(404, fault.faultString))
+
+ returnValue( davxml.ACL( ) )
+
Modified: CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/root.py
===================================================================
--- CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/root.py 2008-10-16 03:16:45 UTC (rev 3162)
+++ CalendarServer/branches/users/sagen/wikitype-3152/twistedcaldav/root.py 2008-10-16 23:34:49 UTC (rev 3163)
@@ -174,6 +174,7 @@
# Examine cookies for wiki auth token
def validSessionID(username):
+ print "GOT BACK: %s" % username
directory = request.site.resource.getDirectory()
record = directory.recordWithShortName("users", username)
if record is None:
@@ -183,9 +184,10 @@
))
request.authnUser = request.authzUser = davxml.Principal(
davxml.HRef.fromString("/principals/__uids__/%s/" % (record.guid,)))
- request.wikiUser = username
+ request.username = username
def invalidSessionID(error):
+ print "INVALID SESSION ID", error
raise HTTPError(StatusResponse(
responsecode.FORBIDDEN,
"Your sessionID was rejected by the authenticating wiki server."
@@ -203,6 +205,7 @@
if token is not None:
proxy = Proxy(wikiConfig["URL"])
+ print "session id: %s" % token
d = proxy.callRemote(wikiConfig["UserMethod"],
token).addCallbacks(validSessionID, invalidSessionID)
d.addCallback(lambda _: super(RootResource, self
@@ -210,8 +213,8 @@
return d
# TODO: REMOVE!!!!!
- validSessionID("sagen")
- return super(RootResource, self).locateChild(request, segments)
+ # validSessionID("sagen")
+ # return super(RootResource, self).locateChild(request, segments)
if self.useSacls and not hasattr(request, "checkedSACL") and not hasattr(request, "checkingSACL"):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081016/838cb4ef/attachment.html
More information about the calendarserver-changes
mailing list