def _fromRecord(cuaddr, record, txn): """ Map a calendar user record into an L{CalendarUser} taking into account whether they are hosted in the directory or known to be locally hosted - or match address patterns for other services. @param cuaddr: the calendar user address to map @type cuaddr: L{str} @param record: the calendar user record to map or L{None} @type record: L{IDirectoryRecord} @param txn: a transaction to use for store operations @type txn: L{ICommonStoreTransaction} """ if record is not None: if not record.calendarsEnabled(): returnValue(InvalidCalendarUser(cuaddr, record)) elif record.thisServer(): returnValue(LocalCalendarUser(cuaddr, record)) else: returnValue(OtherServerCalendarUser(cuaddr, record)) else: uid = uidFromCalendarUserAddress(cuaddr) if uid is not None: hosted, serviceNodeUID = yield txn.store().uidInStore(txn, uid) if hosted: record = TemporaryDirectoryRecord(txn.directoryService(), uid, serviceNodeUID) returnValue(LocalCalendarUser(cuaddr, record)) from txdav.caldav.datastore.scheduling import addressmapping result = (yield addressmapping.mapper.getCalendarUser(cuaddr)) returnValue(result)
def _fromRecord(cuaddr, record, txn): """ Map a calendar user record into an L{CalendarUser} taking into account whether they are hosted in the directory or known to be locally hosted - or match address patterns for other services. @param cuaddr: the calendar user address to map @type cuaddr: L{str} @param record: the calendar user record to map or L{None} @type record: L{IDirectoryRecord} @param txn: a transaction to use for store operations @type txn: L{ICommonStoreTransaction} """ if record is not None: if not record.calendarsEnabled(): returnValue(InvalidCalendarUser(cuaddr, record)) elif record.thisServer(): returnValue(LocalCalendarUser(cuaddr, record)) else: returnValue(OtherServerCalendarUser(cuaddr, record)) else: uid = uidFromCalendarUserAddress(cuaddr) if uid is not None: hosted, serviceNodeUID = yield txn.store().uidInStore(txn, uid) if hosted: record = TemporaryDirectoryRecord(txn.directoryService(), uid, serviceNodeUID) returnValue(LocalCalendarUser(cuaddr, record)) from txdav.caldav.datastore.scheduling import addressmapping result = (yield addressmapping.mapper.getCalendarUser(cuaddr)) returnValue(result)
def test_uidFromCalendarUserAddress(self): """ Test that L{uidFromCalendarUserAddress} returns the expected results. """ data = ( ("urn:x-uid:foobar", "foobar"), ("urn:uuid:foobar", "foobar"), ("urn:uuid:49DE7436-F01C-4AD8-B685-A94303F40301", "49DE7436-F01C-4AD8-B685-A94303F40301"), ("/principals/__uids__/foobar", "foobar"), ("/principals/users/foobar", None), ("/principals/groups/foobar", None), ("mailto:[email protected]", None), ) for cuaddr, uid in data: self.assertEqual(uidFromCalendarUserAddress(cuaddr), uid)