[CalendarServer-changes] [14307] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jan 15 10:11:02 PST 2015
Revision: 14307
http://trac.calendarserver.org//changeset/14307
Author: cdaboo at apple.com
Date: 2015-01-15 10:11:02 -0800 (Thu, 15 Jan 2015)
Log Message:
-----------
Fix and simplify cross-pod requests.
Modified Paths:
--------------
CalendarServer/trunk/requirements-dev.txt
CalendarServer/trunk/twistedcaldav/storebridge.py
CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/scheduler.py
CalendarServer/trunk/txdav/caldav/icalendarstore.py
CalendarServer/trunk/txdav/common/datastore/podding/attachments.py
CalendarServer/trunk/txdav/common/datastore/podding/conduit.py
CalendarServer/trunk/txdav/common/datastore/podding/directory.py
CalendarServer/trunk/txdav/common/datastore/podding/request.py
CalendarServer/trunk/txdav/common/datastore/podding/resource.py
CalendarServer/trunk/txdav/common/datastore/podding/sharing_base.py
CalendarServer/trunk/txdav/common/datastore/podding/sharing_invites.py
CalendarServer/trunk/txdav/common/datastore/podding/sharing_store.py
CalendarServer/trunk/txdav/common/datastore/podding/test/test_conduit.py
CalendarServer/trunk/txdav/common/datastore/podding/test/test_resource.py
CalendarServer/trunk/txdav/common/datastore/podding/test/util.py
CalendarServer/trunk/txdav/who/cache.py
CalendarServer/trunk/txdav/who/delegates.py
CalendarServer/trunk/txdav/who/directory.py
CalendarServer/trunk/txdav/who/groups.py
Modified: CalendarServer/trunk/requirements-dev.txt
===================================================================
--- CalendarServer/trunk/requirements-dev.txt 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/requirements-dev.txt 2015-01-15 18:11:02 UTC (rev 14307)
@@ -8,4 +8,4 @@
q
tl.eggdeps
--editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVClientLibrary/trunk@13420#egg=CalDAVClientLibrary
---editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@14300#egg=CalDAVTester
+--editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@14306#egg=CalDAVTester
Modified: CalendarServer/trunk/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/storebridge.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/twistedcaldav/storebridge.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -2850,7 +2850,7 @@
# Look for client fixes
ua = request.headers.getHeader("User-Agent")
- client_fix_transp = matchClientFixes(config, ua)
+ client_fix_transp = "ForceAttendeeTRANSP" in matchClientFixes(config, ua)
# Setup options
options = {
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/scheduler.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/scheduler.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/scheduler.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -376,7 +376,7 @@
# Check against this server.
matched = False
- serversDB = self.txn._store.directoryService().serversDB
+ serversDB = self.txn._store.directoryService().serversDB()
if serversDB.getThisServer().checkThisIP(clientip):
matched = True
Modified: CalendarServer/trunk/txdav/caldav/icalendarstore.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/icalendarstore.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/caldav/icalendarstore.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -953,7 +953,7 @@
-class SetComponentOptions(Names):
+class SetComponentOptions(object):
"""
Constants for keys used in the L{ICalendarObject.setComponent} method's
C{options} dict. The definitions below define the constant key name and
@@ -966,14 +966,18 @@
Value: L{bool}
"""
- smartMerge = NamedConstant()
- smartMerge.description = u"Smart Merge: CalDAV If-Schedule-Tag-Match behavior"
- smartMerge.defaultValue = False
+ # Smart Merge: CalDAV If-Schedule-Tag-Match behavior
+ smartMerge = "smartMerge"
- clientFixTRANSP = NamedConstant()
- clientFixTRANSP.description = u"Fix for clients not setting TRANSP"
- clientFixTRANSP.defaultValue = False
+ # Fix for clients not setting TRANSP
+ clientFixTRANSP = "clientFixTRANSP"
+ _defaults = {
+ smartMerge: False,
+ clientFixTRANSP: False
+ }
+
@staticmethod
def value(options, key):
- return options.get(key, key.defaultValue) if options is not None else key.defaultValue
+ defaultValue = SetComponentOptions._defaults.get(key)
+ return options.get(key, defaultValue) if options is not None else defaultValue
Modified: CalendarServer/trunk/txdav/common/datastore/podding/attachments.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/attachments.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/attachments.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -15,7 +15,6 @@
##
from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.python.reflect import namedClass
class AttachmentsPoddingConduitMixin(object):
@@ -48,13 +47,9 @@
request["filename"] = filename
response = yield self.sendRequest(shareeView._txn, recipient, request, stream, content_type)
+ returnValue(response)
- if response["result"] == "ok":
- returnValue(response["value"])
- elif response["result"] == "exception":
- raise namedClass(response["class"])(response["result"])
-
@inlineCallbacks
def recv_add_attachment(self, txn, request):
"""
@@ -64,26 +59,15 @@
@type request: C{dict}
"""
- actionName = "add-attachment"
- _ignore_shareeView, objectResource = yield self._getResourcesForRequest(txn, request, actionName)
- try:
- attachment, location = yield objectResource.addAttachment(
- request["rids"],
- request["streamType"],
- request["filename"],
- request["stream"],
- )
- except Exception as e:
- returnValue({
- "result": "exception",
- "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
- "request": str(e),
- })
+ _ignore_shareeView, objectResource = yield self._getResourcesForRequest(txn, request)
+ attachment, location = yield objectResource.addAttachment(
+ request["rids"],
+ request["streamType"],
+ request["filename"],
+ request["stream"],
+ )
- returnValue({
- "result": "ok",
- "value": (attachment.managedID(), location,),
- })
+ returnValue((attachment.managedID(), location,))
@inlineCallbacks
@@ -110,13 +94,9 @@
request["filename"] = filename
response = yield self.sendRequest(shareeView._txn, recipient, request, stream, content_type)
+ returnValue(response)
- if response["result"] == "ok":
- returnValue(response["value"])
- elif response["result"] == "exception":
- raise namedClass(response["class"])(response["result"])
-
@inlineCallbacks
def recv_update_attachment(self, txn, request):
"""
@@ -126,26 +106,15 @@
@type request: C{dict}
"""
- actionName = "update-attachment"
- _ignore_shareeView, objectResource = yield self._getResourcesForRequest(txn, request, actionName)
- try:
- attachment, location = yield objectResource.updateAttachment(
- request["managedID"],
- request["streamType"],
- request["filename"],
- request["stream"],
- )
- except Exception as e:
- returnValue({
- "result": "exception",
- "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
- "request": str(e),
- })
+ _ignore_shareeView, objectResource = yield self._getResourcesForRequest(txn, request)
+ attachment, location = yield objectResource.updateAttachment(
+ request["managedID"],
+ request["streamType"],
+ request["filename"],
+ request["stream"],
+ )
- returnValue({
- "result": "ok",
- "value": (attachment.managedID(), location,),
- })
+ returnValue((attachment.managedID(), location,))
@inlineCallbacks
@@ -167,14 +136,9 @@
request["rids"] = rids
request["managedID"] = managed_id
- response = yield self.sendRequest(shareeView._txn, recipient, request)
+ yield self.sendRequest(shareeView._txn, recipient, request)
- if response["result"] == "ok":
- returnValue(response["value"])
- elif response["result"] == "exception":
- raise namedClass(response["class"])(response["result"])
-
@inlineCallbacks
def recv_remove_attachment(self, txn, request):
"""
@@ -184,21 +148,8 @@
@type request: C{dict}
"""
- actionName = "remove-attachment"
- _ignore_shareeView, objectResource = yield self._getResourcesForRequest(txn, request, actionName)
- try:
- yield objectResource.removeAttachment(
- request["rids"],
- request["managedID"],
- )
- except Exception as e:
- returnValue({
- "result": "exception",
- "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
- "request": str(e),
- })
-
- returnValue({
- "result": "ok",
- "value": None,
- })
+ _ignore_shareeView, objectResource = yield self._getResourcesForRequest(txn, request)
+ yield objectResource.removeAttachment(
+ request["rids"],
+ request["managedID"],
+ )
Modified: CalendarServer/trunk/txdav/common/datastore/podding/conduit.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/conduit.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/conduit.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -16,8 +16,6 @@
from twext.python.log import Logger
-from twisted.internet.defer import inlineCallbacks, returnValue
-
from txdav.common.idirectoryservice import DirectoryRecordNotFoundError
from txdav.common.datastore.podding.attachments import AttachmentsPoddingConduitMixin
from txdav.common.datastore.podding.base import FailedCrossPodRequestError
@@ -26,7 +24,11 @@
from txdav.common.datastore.podding.sharing_invites import SharingInvitesPoddingConduitMixin
from txdav.common.datastore.podding.sharing_store import SharingStorePoddingConduitMixin
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.python.reflect import namedClass
+from twisted.python.failure import Failure
+
log = Logger()
@@ -114,7 +116,12 @@
response = (yield request.doRequest(txn))
except Exception as e:
raise FailedCrossPodRequestError("Failed cross-pod request: {}".format(e))
- returnValue(response)
+ if response["result"] == "exception":
+ raise namedClass(response["class"])(response["result"])
+ elif response["result"] != "ok":
+ raise FailedCrossPodRequestError("Cross-pod request failed: {}".format(response))
+ else:
+ returnValue(response.get("value"))
@inlineCallbacks
@@ -146,11 +153,15 @@
# Do the actual request processing
try:
- result = (yield getattr(self, method)(txn, data))
+ value = (yield getattr(self, method)(txn, data))
+ result = {"result": "ok"}
+ if value is not None:
+ result["value"] = value
except Exception as e:
+ ex = Failure()
yield txn.abort()
log.error("Failed action: {action}, {ex}", action=action, ex=e)
- raise FailedCrossPodRequestError("Failed action: {}, {}".format(action, e))
+ ex.raiseException()
yield txn.commit()
Modified: CalendarServer/trunk/txdav/common/datastore/podding/directory.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/directory.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/directory.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -15,7 +15,6 @@
##
from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.python.reflect import namedClass
from txdav.common.datastore.podding.base import FailedCrossPodRequestError
from txdav.who.delegates import Delegates
@@ -41,13 +40,9 @@
"action": "all-group-delegates",
}
response = yield self.sendRequestToServer(txn, server, request)
+ returnValue(set(response))
- if response["result"] == "ok":
- returnValue(set(response["value"]))
- elif response["result"] == "exception":
- raise namedClass(response["class"])(response["result"])
-
@inlineCallbacks
def recv_all_group_delegates(self, txn, request):
"""
@@ -57,24 +52,11 @@
@type request: C{dict}
"""
- if request["action"] != "all-group-delegates":
- raise FailedCrossPodRequestError("Wrong action '{}' for recv_all_group_delegates".format(request["action"]))
+ delegatedUIDs = yield txn.allGroupDelegates()
- try:
- delegatedUIDs = yield txn.allGroupDelegates()
- except Exception as e:
- returnValue({
- "result": "exception",
- "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
- "request": str(e),
- })
+ returnValue(list(delegatedUIDs))
- returnValue({
- "result": "ok",
- "value": list(delegatedUIDs),
- })
-
@inlineCallbacks
def send_set_delegates(self, txn, delegator, delegates, readWrite):
"""
@@ -98,14 +80,9 @@
"delegates": [delegate.uid for delegate in delegates],
"read-write": readWrite,
}
- response = yield self.sendRequestToServer(txn, delegator.server(), request)
+ yield self.sendRequestToServer(txn, delegator.server(), request)
- if response["result"] == "ok":
- returnValue(None)
- elif response["result"] == "exception":
- raise namedClass(response["class"])(response["result"])
-
@inlineCallbacks
def recv_set_delegates(self, txn, request):
"""
@@ -115,34 +92,20 @@
@type request: C{dict}
"""
- if request["action"] != "set-delegates":
- raise FailedCrossPodRequestError("Wrong action '{}' for recv_set_delegates".format(request["action"]))
+ delegator = yield txn.directoryService().recordWithUID(request["uid"])
+ if delegator is None or not delegator.thisServer():
+ raise FailedCrossPodRequestError("Cross-pod delegate not on this server: {}".format(delegator.uid))
- try:
- delegator = yield txn.directoryService().recordWithUID(request["uid"])
- if delegator is None or not delegator.thisServer():
- raise FailedCrossPodRequestError("Cross-pod delegate not on this server: {}".format(delegator.uid))
+ delegates = []
+ for uid in request["delegates"]:
+ delegate = yield txn.directoryService().recordWithUID(uid)
+ if delegate is None:
+ raise FailedCrossPodRequestError("Cross-pod delegate missing on this server: {}".format(uid))
+ delegates.append(delegate)
- delegates = []
- for uid in request["delegates"]:
- delegate = yield txn.directoryService().recordWithUID(uid)
- if delegate is None:
- raise FailedCrossPodRequestError("Cross-pod delegate missing on this server: {}".format(uid))
- delegates.append(delegate)
+ yield Delegates.setDelegates(txn, delegator, delegates, request["read-write"])
- yield Delegates.setDelegates(txn, delegator, delegates, request["read-write"])
- except Exception as e:
- returnValue({
- "result": "exception",
- "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
- "request": str(e),
- })
- returnValue({
- "result": "ok",
- })
-
-
@inlineCallbacks
def send_get_delegates(self, txn, delegator, readWrite, expanded=False):
"""
@@ -165,13 +128,9 @@
"expanded": expanded,
}
response = yield self.sendRequestToServer(txn, delegator.server(), request)
+ returnValue(set(response))
- if response["result"] == "ok":
- returnValue(set(response["value"]))
- elif response["result"] == "exception":
- raise namedClass(response["class"])(response["result"])
-
@inlineCallbacks
def recv_get_delegates(self, txn, request):
"""
@@ -181,28 +140,15 @@
@type request: C{dict}
"""
- if request["action"] != "get-delegates":
- raise FailedCrossPodRequestError("Wrong action '{}' for recv_get_delegates".format(request["action"]))
+ delegator = yield txn.directoryService().recordWithUID(request["uid"])
+ if delegator is None or not delegator.thisServer():
+ raise FailedCrossPodRequestError("Cross-pod delegate not on this server: {}".format(delegator.uid))
- try:
- delegator = yield txn.directoryService().recordWithUID(request["uid"])
- if delegator is None or not delegator.thisServer():
- raise FailedCrossPodRequestError("Cross-pod delegate not on this server: {}".format(delegator.uid))
+ delegates = yield Delegates._delegatesOfUIDs(txn, delegator, request["read-write"], request["expanded"])
- delegates = yield Delegates._delegatesOfUIDs(txn, delegator, request["read-write"], request["expanded"])
- except Exception as e:
- returnValue({
- "result": "exception",
- "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
- "request": str(e),
- })
+ returnValue(list(delegates))
- returnValue({
- "result": "ok",
- "value": list(delegates),
- })
-
@inlineCallbacks
def send_get_delegators(self, txn, server, delegate, readWrite):
"""
@@ -226,13 +172,9 @@
"read-write": readWrite,
}
response = yield self.sendRequestToServer(txn, server, request)
+ returnValue(set(response))
- if response["result"] == "ok":
- returnValue(set(response["value"]))
- elif response["result"] == "exception":
- raise namedClass(response["class"])(response["result"])
-
@inlineCallbacks
def recv_get_delegators(self, txn, request):
"""
@@ -242,23 +184,10 @@
@type request: C{dict}
"""
- if request["action"] != "get-delegators":
- raise FailedCrossPodRequestError("Wrong action '{}' for recv_get_delegators".format(request["action"]))
+ delegate = yield txn.directoryService().recordWithUID(request["uid"])
+ if delegate is None or delegate.thisServer():
+ raise FailedCrossPodRequestError("Cross-pod delegate missing or on this server: {}".format(delegate.uid))
- try:
- delegate = yield txn.directoryService().recordWithUID(request["uid"])
- if delegate is None or delegate.thisServer():
- raise FailedCrossPodRequestError("Cross-pod delegate missing or on this server: {}".format(delegate.uid))
+ delegators = yield Delegates._delegatedToUIDs(txn, delegate, request["read-write"], onlyThisServer=True)
- delegateors = yield Delegates._delegatedToUIDs(txn, delegate, request["read-write"], onlyThisServer=True)
- except Exception as e:
- returnValue({
- "result": "exception",
- "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
- "request": str(e),
- })
-
- returnValue({
- "result": "ok",
- "value": list(delegateors),
- })
+ returnValue(list(delegators))
Modified: CalendarServer/trunk/txdav/common/datastore/podding/request.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/request.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/request.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -72,7 +72,7 @@
self.loggedResponse = yield self.logResponse(response)
emitAccounting("xPod", "", self.loggedRequest + "\n" + self.loggedResponse, "POST")
- if response.code in (responsecode.OK,):
+ if response.code in (responsecode.OK, responsecode.BAD_REQUEST,):
data = (yield allDataFromStream(response.stream))
data = json.loads(data)
else:
Modified: CalendarServer/trunk/txdav/common/datastore/podding/resource.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/resource.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/resource.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -29,7 +29,6 @@
deliverSchedulePrivilegeSet
from txdav.xml import element as davxml
-from txdav.common.datastore.podding.conduit import FailedCrossPodRequestError
import base64
import json
@@ -119,7 +118,7 @@
"""
# Check shared secret
- if not self.store.directoryService().serversDB.getThisServer().checkSharedSecret(request.headers):
+ if not self.store.directoryService().serversDB().getThisServer().checkSharedSecret(request.headers):
self.log.error("Invalid shared secret header in cross-pod request")
raise HTTPError(StatusResponse(responsecode.FORBIDDEN, "Not authorized to make this request"))
@@ -158,12 +157,17 @@
# Get the conduit to process the data
try:
result = yield self.store.conduit.processRequest(j)
- except FailedCrossPodRequestError as e:
- raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
+ code = responsecode.OK
except Exception as e:
- raise HTTPError(StatusResponse(responsecode.INTERNAL_SERVER_ERROR, str(e)))
+ # Send the exception over to the other side
+ result = {
+ "result": "exception",
+ "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
+ "request": str(e),
+ }
+ code = responsecode.BAD_REQUEST
- response = JSONResponse(responsecode.OK, result)
+ response = JSONResponse(code, result)
returnValue(response)
Modified: CalendarServer/trunk/txdav/common/datastore/podding/sharing_base.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/sharing_base.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/sharing_base.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -58,7 +58,7 @@
@inlineCallbacks
- def _getResourcesForRequest(self, txn, request, expected_action):
+ def _getResourcesForRequest(self, txn, request):
"""
Find the resources associated with the request. This is used when a JSON request has been received
and the underlying store objects the request refers to need to be found.
@@ -67,9 +67,6 @@
@type request: C{dict}
"""
- if request["action"] != expected_action:
- raise FailedCrossPodRequestError("Wrong action '{}' for recv_{}".format(request["action"], expected_action))
-
# Get a share
ownerHome = yield txn.homeWithUID(request["type"], request["owner"])
if ownerHome is None or ownerHome.external():
Modified: CalendarServer/trunk/txdav/common/datastore/podding/sharing_invites.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/sharing_invites.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/sharing_invites.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -14,9 +14,8 @@
# limitations under the License.
##
-from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.defer import inlineCallbacks
-from txdav.common.icommondatastore import ExternalShareFailed
from txdav.common.datastore.podding.base import FailedCrossPodRequestError
from txdav.common.datastore.podding.sharing_base import SharingCommonPoddingConduit
@@ -71,8 +70,7 @@
if supported_components is not None:
request["supported-components"] = supported_components
- result = yield self.sendRequest(txn, recipient, request)
- returnValue(result)
+ yield self.sendRequest(txn, recipient, request)
@inlineCallbacks
@@ -84,34 +82,24 @@
@type request: C{dict}
"""
- if request["action"] != "shareinvite":
- raise FailedCrossPodRequestError("Wrong action '{}' for recv_shareinvite".format(request["action"]))
-
# Sharee home on this pod must exist (create if needed)
shareeHome = yield txn.homeWithUID(request["type"], request["sharee"], create=True)
if shareeHome is None or shareeHome.external():
raise FailedCrossPodRequestError("Invalid sharee UID specified")
# Create a share
- try:
- yield shareeHome.processExternalInvite(
- request["owner"],
- request["owner_id"],
- request["owner_name"],
- request["share_id"],
- request["mode"],
- request["summary"],
- request["properties"],
- supported_components=request.get("supported-components")
- )
- except ExternalShareFailed as e:
- raise FailedCrossPodRequestError(str(e))
+ yield shareeHome.processExternalInvite(
+ request["owner"],
+ request["owner_id"],
+ request["owner_name"],
+ request["share_id"],
+ request["mode"],
+ request["summary"],
+ request["properties"],
+ supported_components=request.get("supported-components")
+ )
- returnValue({
- "result": "ok",
- })
-
@inlineCallbacks
def send_shareuninvite(self, txn, homeType, ownerUID, ownerID, shareeUID, shareUID):
"""
@@ -140,8 +128,7 @@
"share_id": shareUID,
}
- result = yield self.sendRequest(txn, recipient, request)
- returnValue(result)
+ yield self.sendRequest(txn, recipient, request)
@inlineCallbacks
@@ -153,29 +140,19 @@
@type request: C{dict}
"""
- if request["action"] != "shareuninvite":
- raise FailedCrossPodRequestError("Wrong action '{}' for recv_shareuninvite".format(request["action"]))
-
# Sharee home on this pod must already exist
shareeHome = yield txn.homeWithUID(request["type"], request["sharee"])
if shareeHome is None or shareeHome.external():
FailedCrossPodRequestError("Invalid sharee UID specified")
# Remove a share
- try:
- yield shareeHome.processExternalUninvite(
- request["owner"],
- request["owner_id"],
- request["share_id"],
- )
- except ExternalShareFailed as e:
- FailedCrossPodRequestError(str(e))
+ yield shareeHome.processExternalUninvite(
+ request["owner"],
+ request["owner_id"],
+ request["share_id"],
+ )
- returnValue({
- "result": "ok",
- })
-
@inlineCallbacks
def send_sharereply(self, txn, homeType, ownerUID, shareeUID, shareUID, bindStatus, summary=None):
"""
@@ -208,8 +185,7 @@
if summary is not None:
request["summary"] = summary
- result = yield self.sendRequest(txn, recipient, request)
- returnValue(result)
+ yield self.sendRequest(txn, recipient, request)
@inlineCallbacks
@@ -221,26 +197,16 @@
@type request: C{dict}
"""
- if request["action"] != "sharereply":
- raise FailedCrossPodRequestError("Wrong action '{}' for recv_sharereply".format(request["action"]))
-
# Sharer home on this pod must already exist
ownerHome = yield txn.homeWithUID(request["type"], request["owner"])
if ownerHome is None or ownerHome.external():
FailedCrossPodRequestError("Invalid owner UID specified")
# Process a reply
- try:
- yield ownerHome.processExternalReply(
- request["owner"],
- request["sharee"],
- request["share_id"],
- request["status"],
- summary=request.get("summary")
- )
- except ExternalShareFailed as e:
- FailedCrossPodRequestError(str(e))
-
- returnValue({
- "result": "ok",
- })
+ yield ownerHome.processExternalReply(
+ request["owner"],
+ request["sharee"],
+ request["share_id"],
+ request["status"],
+ summary=request.get("summary")
+ )
Modified: CalendarServer/trunk/txdav/common/datastore/podding/sharing_store.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/sharing_store.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/sharing_store.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -15,7 +15,6 @@
##
from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.python.reflect import namedClass
from txdav.common.datastore.podding.sharing_base import SharingCommonPoddingConduit
from txdav.caldav.datastore.scheduling.freebusy import generateFreeBusyInfo
@@ -59,10 +58,7 @@
if kwargs is not None:
request["keywords"] = kwargs
response = yield self.sendRequest(shareeView._txn, recipient, request)
- if response["result"] == "ok":
- returnValue(response["value"] if transform is None else transform(response["value"], shareeView, objectResource))
- elif response["result"] == "exception":
- raise namedClass(response["class"])(response["result"])
+ returnValue(response if transform is None else transform(response, shareeView, objectResource))
@inlineCallbacks
@@ -81,29 +77,19 @@
@type transform: C{callable}
"""
- shareeView, objectResource = yield self._getResourcesForRequest(txn, request, actionName)
- try:
- if onHomeChild:
- # Operate on the L{CommonHomeChild}
- value = yield getattr(shareeView, method)(*request.get("arguments", ()), **request.get("keywords", {}))
+ shareeView, objectResource = yield self._getResourcesForRequest(txn, request)
+ if onHomeChild:
+ # Operate on the L{CommonHomeChild}
+ value = yield getattr(shareeView, method)(*request.get("arguments", ()), **request.get("keywords", {}))
+ else:
+ # Operate on the L{CommonObjectResource}
+ if objectResource is not None:
+ value = yield getattr(objectResource, method)(*request.get("arguments", ()), **request.get("keywords", {}))
else:
- # Operate on the L{CommonObjectResource}
- if objectResource is not None:
- value = yield getattr(objectResource, method)(*request.get("arguments", ()), **request.get("keywords", {}))
- else:
- # classmethod call
- value = yield getattr(shareeView._objectResourceClass, method)(shareeView, *request.get("arguments", ()), **request.get("keywords", {}))
- except Exception as e:
- returnValue({
- "result": "exception",
- "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
- "request": str(e),
- })
+ # classmethod call
+ value = yield getattr(shareeView._objectResourceClass, method)(shareeView, *request.get("arguments", ()), **request.get("keywords", {}))
- returnValue({
- "result": "ok",
- "value": transform(value, shareeView, objectResource) if transform is not None else value,
- })
+ returnValue(transform(value, shareeView, objectResource) if transform is not None else value)
@inlineCallbacks
@@ -134,13 +120,9 @@
action["event_details"] = event_details
response = yield self.sendRequest(calresource._txn, recipient, action)
+ returnValue((response["fbresults"], response["matchtotal"],))
- if response["result"] == "ok":
- returnValue((response["fbresults"], response["matchtotal"],))
- elif response["result"] == "exception":
- raise namedClass(response["class"])(response["result"])
-
@inlineCallbacks
def recv_freebusy(self, txn, request):
"""
@@ -150,37 +132,30 @@
@type request: C{dict}
"""
- shareeView, _ignore_objectResource = yield self._getResourcesForRequest(txn, request, "freebusy")
- try:
- # Operate on the L{CommonHomeChild}
- fbinfo = [[], [], []]
- matchtotal = yield generateFreeBusyInfo(
- shareeView,
- fbinfo,
- TimeRange(start=request["timerange"][0], end=request["timerange"][1]),
- request["matchtotal"],
- request["excludeuid"],
- request["organizer"],
- request["organizerPrincipal"],
- request["same_calendar_user"],
- request["servertoserver"],
- request["event_details"],
- logItems=None
- )
- except Exception as e:
- returnValue({
- "result": "exception",
- "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
- "request": str(e),
- })
+ # Operate on the L{CommonHomeChild}
+ shareeView, _ignore_objectResource = yield self._getResourcesForRequest(txn, request)
+ fbinfo = [[], [], []]
+ matchtotal = yield generateFreeBusyInfo(
+ shareeView,
+ fbinfo,
+ TimeRange(start=request["timerange"][0], end=request["timerange"][1]),
+ request["matchtotal"],
+ request["excludeuid"],
+ request["organizer"],
+ request["organizerPrincipal"],
+ request["same_calendar_user"],
+ request["servertoserver"],
+ request["event_details"],
+ logItems=None
+ )
+
# Convert L{DateTime} objects to text for JSON response
for i in range(3):
for j in range(len(fbinfo[i])):
fbinfo[i][j] = fbinfo[i][j].getText()
returnValue({
- "result": "ok",
"fbresults": fbinfo,
"matchtotal": matchtotal,
})
Modified: CalendarServer/trunk/txdav/common/datastore/podding/test/test_conduit.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/test/test_conduit.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/test/test_conduit.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -52,7 +52,6 @@
def recv_fake(self, j):
return succeed({
- "result": "ok",
"back2u": j["echo"],
"more": "bits",
})
@@ -149,7 +148,6 @@
def recv_fake(self, txn, j):
return succeed({
- "result": "ok",
"back2u": j["echo"],
"more": "bits",
})
@@ -173,23 +171,13 @@
txn = self.transactionUnderTest()
store1 = self.storeUnderTest()
response = yield store1.conduit.send_fake(txn, "user01", "puser01")
- self.assertTrue("result" in response)
- self.assertEqual(response["result"], "ok")
- self.assertTrue("back2u" in response)
- self.assertEqual(response["back2u"], "bravo")
- self.assertTrue("more" in response)
- self.assertEqual(response["more"], "bits")
+ self.assertEqual(response, {"back2u": "bravo", "more": "bits"})
yield txn.commit()
store2 = self.otherStoreUnderTest()
txn = store2.newTransaction()
response = yield store2.conduit.send_fake(txn, "puser01", "user01")
- self.assertTrue("result" in response)
- self.assertEqual(response["result"], "ok")
- self.assertTrue("back2u" in response)
- self.assertEqual(response["back2u"], "bravo")
- self.assertTrue("more" in response)
- self.assertEqual(response["more"], "bits")
+ self.assertEqual(response, {"back2u": "bravo", "more": "bits"})
yield txn.commit()
Modified: CalendarServer/trunk/txdav/common/datastore/podding/test/test_resource.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/test/test_resource.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/test/test_resource.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -37,7 +37,6 @@
def recv_fake(self, txn, j):
return succeed({
- "result": "ok",
"back2u": j["echo"],
"more": "bits",
})
@@ -266,7 +265,5 @@
j = json.loads(data)
self.assertTrue("result" in j)
self.assertEqual(j["result"], "ok")
- self.assertTrue("back2u" in j)
- self.assertEqual(j["back2u"], "bravo")
- self.assertTrue("more" in j)
- self.assertEqual(j["more"], "bits")
+ self.assertTrue("value" in j)
+ self.assertEqual(j["value"], {"back2u": "bravo", "more": "bits"})
Modified: CalendarServer/trunk/txdav/common/datastore/podding/test/util.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/test/util.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/common/datastore/podding/test/util.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -89,7 +89,15 @@
if self.stream is not None:
j["stream"] = self.stream
j["streamType"] = self.streamType
- result = yield store.conduit.processRequest(j)
+ try:
+ result = yield store.conduit.processRequest(j)
+ except Exception as e:
+ # Send the exception over to the other side
+ result = {
+ "result": "exception",
+ "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
+ "request": str(e),
+ }
result = json.dumps(result)
returnValue(result)
Modified: CalendarServer/trunk/txdav/who/cache.py
===================================================================
--- CalendarServer/trunk/txdav/who/cache.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/who/cache.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -473,6 +473,10 @@
)
+ def serversDB(self):
+ return self._directory.serversDB()
+
+
@inlineCallbacks
def flush(self):
self.resetCache()
Modified: CalendarServer/trunk/txdav/who/delegates.py
===================================================================
--- CalendarServer/trunk/txdav/who/delegates.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/who/delegates.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -614,7 +614,7 @@
log.debug("_podDelegators for: {} and read-write = {}".format(delegate.uid, readWrite,))
results = yield DeferredList([
txn.store().conduit.send_get_delegators(txn, server, delegate, readWrite) for
- server in txn.directoryService().serversDB.allServersExceptThis()
+ server in txn.directoryService().serversDB().allServersExceptThis()
], consumeErrors=True)
delegators = set()
for result in results:
Modified: CalendarServer/trunk/txdav/who/directory.py
===================================================================
--- CalendarServer/trunk/txdav/who/directory.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/who/directory.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -53,10 +53,14 @@
guid = "1332A615-4D3A-41FE-B636-FBE25BFB982E"
- serversDB = None
+ _serversDB = None
+ def serversDB(self):
+ return self._serversDB
+
+
def setServersDB(self, serversDB):
- self.serversDB = serversDB
+ self._serversDB = serversDB
# Must maintain the hack for a bit longer:
@@ -502,10 +506,10 @@
URL of the server hosting this record. Return None if hosted on this server.
"""
if (
- self.service.serversDB is not None and
+ self.service.serversDB() is not None and
getattr(self, "serviceNodeUID", None)
):
- return self.service.serversDB.getServerURIById(self.serviceNodeUID)
+ return self.service.serversDB().getServerURIById(self.serviceNodeUID)
else:
return None
@@ -515,10 +519,10 @@
Server hosting this record. Return None if hosted on this server.
"""
if (
- self.service.serversDB is not None and
+ self.service.serversDB() is not None and
getattr(self, "serviceNodeUID", None)
):
- return self.service.serversDB.getServerById(self.serviceNodeUID)
+ return self.service.serversDB().getServerById(self.serviceNodeUID)
else:
return None
Modified: CalendarServer/trunk/txdav/who/groups.py
===================================================================
--- CalendarServer/trunk/txdav/who/groups.py 2015-01-15 17:56:24 UTC (rev 14306)
+++ CalendarServer/trunk/txdav/who/groups.py 2015-01-15 18:11:02 UTC (rev 14307)
@@ -533,10 +533,10 @@
)
# Also get group delegates from other pods
- if txn.directoryService().serversDB is not None and len(txn.directoryService().serversDB.allServersExceptThis()) != 0:
+ if txn.directoryService().serversDB() is not None and len(txn.directoryService().serversDB().allServersExceptThis()) != 0:
results = yield DeferredList([
txn.store().conduit.send_all_group_delegates(txn, server) for
- server in txn.directoryService().serversDB.allServersExceptThis()
+ server in txn.directoryService().serversDB().allServersExceptThis()
], consumeErrors=True)
for result in results:
if result and result[0]:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150115/e45f72ac/attachment-0001.html>
More information about the calendarserver-changes
mailing list