def inviteProperty(self, request): """ Calculate the customxml.Invite property (for readProperty) from the invites database. """ if config.Sharing.Enabled: @inlineCallbacks def invitePropertyElement(invitation, includeUID=True): userid = "urn:x-uid:" + invitation.shareeUID principal = yield self.principalForUID(invitation.shareeUID) cn = principal.displayName() if principal else invitation.shareeUID returnValue(customxml.InviteUser( customxml.UID.fromString(invitation.uid) if includeUID else None, element.HRef.fromString(userid), customxml.CommonName.fromString(cn), customxml.InviteAccess(invitationBindModeToXMLMap[invitation.mode]()), invitationBindStatusToXMLMap[invitation.status](), )) # See if this property is on the shared calendar if self.isSharedByOwner(): invitations = yield self.validateInvites(request) returnValue(customxml.Invite( *[(yield invitePropertyElement(invitation)) for invitation in invitations] )) # See if it is on the sharee calendar if self.isShareeResource(): original = yield self._newStoreObject.ownerView() if original is not None: invitations = yield original.allInvitations() invitations = yield self.validateInvites(request, invitations) ownerPrincipal = yield self.principalForUID(self._newStoreObject.ownerHome().uid()) if ownerPrincipal is None: owner = "invalid" ownerCN = "Invalid" else: # FIXME: use urn:x-uid in all cases if self.isCalendarCollection(): owner = ownerPrincipal.principalURL() else: owner = "urn:x-uid:" + ownerPrincipal.principalUID() ownerCN = ownerPrincipal.displayName() returnValue(customxml.Invite( customxml.Organizer( element.HRef.fromString(owner), customxml.CommonName.fromString(ownerCN), ), *[(yield invitePropertyElement(invitation, includeUID=False)) for invitation in invitations] )) returnValue(None)
def test_POSTremoveInvalidInvitee(self): yield self.resource.upgradeToShare() yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?> <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"> <CS:set> <D:href>mailto:[email protected]</D:href> <CS:summary>My Shared Calendar</CS:summary> <CS:read-write/> </CS:set> </CS:share> """) propInvite = (yield self.resource.readProperty(customxml.Invite, None)) self.assertEquals( self._clearUIDElementValue(propInvite), customxml.Invite( customxml.InviteUser( customxml.UID.fromString(""), davxml.HRef.fromString("urn:x-uid:user02"), customxml.CommonName.fromString("User 02"), customxml.InviteAccess(customxml.ReadWriteAccess()), customxml.InviteStatusNoResponse(), ))) record = yield self.userRecordWithShortName("user02") yield self.changeRecord(record, self.directory.fieldName.hasCalendars, False) propInvite = (yield self.resource.readProperty(customxml.Invite, None)) self.assertEquals( self._clearUIDElementValue(propInvite), customxml.Invite( customxml.InviteUser( customxml.UID.fromString(""), davxml.HRef.fromString("urn:x-uid:user02"), customxml.CommonName.fromString("User 02"), customxml.InviteAccess(customxml.ReadWriteAccess()), customxml.InviteStatusInvalid(), ))) yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?> <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"> <CS:remove> <D:href>urn:x-uid:user02</D:href> </CS:remove> </CS:share> """) propInvite = (yield self.resource.readProperty(customxml.Invite, None)) self.assertEquals(propInvite, None)
def test_POSTDowngradeWithMissingInvitee(self): yield self.resource.upgradeToShare() yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?> <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"> <CS:set> <D:href>mailto:[email protected]</D:href> <CS:summary>My Shared Calendar</CS:summary> <CS:read-write/> </CS:set> </CS:share> """) propInvite = (yield self.resource.readProperty(customxml.Invite, None)) self.assertEquals( self._clearUIDElementValue(propInvite), customxml.Invite( customxml.InviteUser( customxml.UID.fromString(""), davxml.HRef.fromString("urn:x-uid:user02"), customxml.CommonName.fromString("User 02"), customxml.InviteAccess(customxml.ReadWriteAccess()), customxml.InviteStatusNoResponse(), ), )) yield self.directory.removeRecords( ((yield self.userUIDFromShortName("user02")), )) self.assertTrue((yield self.userUIDFromShortName("user02")) is None) yield self.resource.downgradeFromShare(norequest())
def test_POSTaddInviteeNotAlreadyShared(self): yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?> <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"> <CS:set> <D:href>mailto:[email protected]</D:href> <CS:summary>My Shared Calendar</CS:summary> <CS:read-write/> </CS:set> </CS:share> """) propInvite = (yield self.resource.readProperty(customxml.Invite, None)) self.assertEquals( self._clearUIDElementValue(propInvite), customxml.Invite( customxml.InviteUser( customxml.UID.fromString(""), davxml.HRef.fromString("urn:x-uid:user02"), customxml.CommonName.fromString("User 02"), customxml.InviteAccess(customxml.ReadWriteAccess()), customxml.InviteStatusNoResponse(), ))) isShared = self.resource.isShared() self.assertTrue(isShared) isShareeResource = (yield self.resource.isShareeResource()) self.assertFalse(isShareeResource)
def test_POSTShareeRemoveWithMissingSharer(self): yield self.resource.upgradeToShare() yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?> <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"> <CS:set> <D:href>mailto:[email protected]</D:href> <CS:summary>My Shared Calendar</CS:summary> <CS:read-write/> </CS:set> </CS:share> """) propInvite = (yield self.resource.readProperty(customxml.Invite, None)) uid = self._getUIDElementValue(propInvite) self.assertEquals( self._clearUIDElementValue(propInvite), customxml.Invite( customxml.InviteUser( customxml.UID.fromString(""), davxml.HRef.fromString("urn:x-uid:user02"), customxml.CommonName.fromString("User 02"), customxml.InviteAccess(customxml.ReadWriteAccess()), customxml.InviteStatusNoResponse(), ), )) result = (yield self._doPOSTSharerAccept( """<?xml version='1.0' encoding='UTF-8'?> <invite-reply xmlns='http://calendarserver.org/ns/'> <href xmlns='DAV:'>mailto:[email protected]</href> <invite-accepted/> <hosturl> <href xmlns='DAV:'>/calendars/__uids__/user01/calendar/</href> </hosturl> <in-reply-to>%s</in-reply-to> <summary>The Shared Calendar</summary> <common-name>User 02</common-name> <first-name>user</first-name> <last-name>02</last-name> </invite-reply> """ % (uid, ))) href = self._getHRefElementValue(result) + "/" yield self.directory.removeRecords( ((yield self.userUIDFromShortName("user01")), )) self.assertTrue((yield self.userUIDFromShortName("user01")) is None) resource = (yield self._getResourceSharer(href)) yield resource.removeShareeResource( SimpleStoreRequest(self, "DELETE", href)) resource = (yield self._getResourceSharer(href)) self.assertFalse(resource.exists())
def test_shareeInviteWithDisabledSharer(self): yield self.resource.upgradeToShare() yield self._doPOST("""<?xml version="1.0" encoding="utf-8" ?> <CS:share xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/"> <CS:set> <D:href>mailto:[email protected]</D:href> <CS:summary>My Shared Calendar</CS:summary> <CS:read-write/> </CS:set> </CS:share> """) propInvite = (yield self.resource.readProperty(customxml.Invite, None)) uid = self._getUIDElementValue(propInvite) self.assertEquals( self._clearUIDElementValue(propInvite), customxml.Invite( customxml.InviteUser( customxml.UID.fromString(""), davxml.HRef.fromString("urn:x-uid:user02"), customxml.CommonName.fromString("User 02"), customxml.InviteAccess(customxml.ReadWriteAccess()), customxml.InviteStatusNoResponse(), ), )) result = (yield self._doPOSTSharerAccept( """<?xml version='1.0' encoding='UTF-8'?> <invite-reply xmlns='http://calendarserver.org/ns/'> <href xmlns='DAV:'>mailto:[email protected]</href> <invite-accepted/> <hosturl> <href xmlns='DAV:'>/calendars/__uids__/user01/calendar/</href> </hosturl> <in-reply-to>%s</in-reply-to> <summary>The Shared Calendar</summary> <common-name>User 02</common-name> <first-name>user</first-name> <last-name>02</last-name> </invite-reply> """ % (uid, ))) href = self._getHRefElementValue(result) + "/" record = yield self.userRecordWithShortName("user01") yield self.changeRecord(record, self.directory.fieldName.hasCalendars, False) resource = (yield self._getResourceSharer(href)) propInvite = yield resource.inviteProperty(None) self.assertEquals( self._clearUIDElementValue(propInvite), customxml.Invite( customxml.Organizer( davxml.HRef.fromString("/principals/__uids__/user01/"), customxml.CommonName.fromString("User 01"), ), customxml.InviteUser( davxml.HRef.fromString("urn:x-uid:user02"), customxml.CommonName.fromString("User 02"), customxml.InviteAccess(customxml.ReadWriteAccess()), customxml.InviteStatusAccepted(), ), ))