def maybeCommit(req): class JustForCleanup(object): def newTransaction(self, *whatever): return self def commit(self): return transactionFromRequest(req, JustForCleanup()).commit()
def homeResourceForRecord(self, record, request): transaction = transactionFromRequest(request, self.parent._newStore) name = record.uid if record is None: log.debug("No directory record with UID {name}", name=name) returnValue(None) if not getattr(record, self.enabledAttribute, False): log.debug("Directory record {rec!r} is not enabled for {type}", rec=record, type=self.homeResourceTypeName) returnValue(None) assert len( name ) > 4, "Directory record has an invalid GUID (too short): %r" % ( name, ) if record.thisServer(): child = yield self.homeResourceCreator(record, transaction) else: child = DirectoryReverseProxyResource(self, record) returnValue(child)
def http_POST(self, request): """ The server-to-server POST method. """ # Need a transaction to work with txn = transactionFromRequest(request, self._newStore) # This is a server-to-server scheduling operation. scheduler = IScheduleScheduler(txn, None, podding=self._podding) originator = self.loadOriginatorFromRequestHeaders(request) recipients = self.loadRecipientsFromRequestHeaders(request) body = (yield allDataFromStream(request.stream)) # Do the POST processing treating this as a non-local schedule try: result = (yield scheduler.doSchedulingViaPOST(request.remoteAddr, request.headers, body, originator, recipients)) except Exception: ex = Failure() yield txn.abort() ex.raiseException() else: yield txn.commit() response = result.response() if not self._podding: response.headers.addRawHeader(ISCHEDULE_CAPABILITIES, str(config.Scheduling.iSchedule.SerialNumber)) returnValue(response)
def homeResourceForRecord(self, record, request): transaction = transactionFromRequest(request, self.parent._newStore) name = record.uid if record is None: log.debug("No directory record with GUID %r" % (name,)) returnValue(None) if not getattr(record, self.enabledAttribute): log.debug("Directory record %r is not enabled for %s" % ( record, self.homeResourceTypeName)) returnValue(None) assert len(name) > 4, "Directory record has an invalid GUID: %r" % ( name,) if record.locallyHosted(): child = yield self.homeResourceCreator(record, transaction) elif record.thisServer(): child = DirectoryReverseProxyResource(self, record) else: child = None # Use a redirect? returnValue(child)
def __init__(self, test, method, uri, headers=None, content=None, authPrincipal=None): super(SimpleStoreRequest, self).__init__(test.site, method, uri, headers, content) self._test = test self._newStoreTransaction = test.transactionUnderTest(txn=transactionFromRequest(self, test.storeUnderTest())) self.credentialFactories = {} # Fake credentials if auth needed if authPrincipal is not None: self.authzUser = self.authnUser = authPrincipal
def http_POST(self, request): """ The server-to-server POST method. """ # Need a transaction to work with txn = transactionFromRequest(request, self._newStore) # Log extended item if not hasattr(request, "extendedLogItems"): request.extendedLogItems = {} # This is a server-to-server scheduling operation. scheduler = IScheduleScheduler(txn, None, logItems=request.extendedLogItems, podding=self._podding) # Check content first contentType = request.headers.getHeader("content-type") format = self.determineType(contentType) if format is None: msg = "MIME type {} not allowed in iSchedule request".format( contentType, ) self.log.error(msg) raise HTTPError( scheduler.errorResponse( responsecode.FORBIDDEN, (ischedule_namespace, "invalid-calendar-data-type"), msg, )) originator = self.loadOriginatorFromRequestHeaders(request) recipients = self.loadRecipientsFromRequestHeaders(request) body = (yield allDataFromStream(request.stream)) calendar = Component.fromString(body, format=format) # Do the POST processing treating this as a non-local schedule try: result = (yield scheduler.doSchedulingViaPOST(request.remoteAddr, request.headers, body, calendar, originator, recipients)) except Exception: ex = Failure() yield txn.abort() ex.raiseException() else: yield txn.commit() response = result.response(format=format) if not self._podding: response.headers.addRawHeader( ISCHEDULE_CAPABILITIES, str(config.Scheduling.iSchedule.SerialNumber)) returnValue(response)
def __init__(self, test, method, uri, headers=None, content=None, authid=None): super(SimpleStoreRequest, self).__init__(test.site, method, uri, headers, content) self._test = test self._newStoreTransaction = test.transactionUnderTest(txn=transactionFromRequest(self, test.storeUnderTest())) self.credentialFactories = {} # Fake credentials if auth needed if authid is not None: record = self._test.directory.recordWithShortName(DirectoryService.recordType_users, authid) if record: self.authzUser = self.authnUser = element.Principal(element.HRef("/principals/__uids__/%s/" % (record.uid,)))
def tearDown(self): """ If the request started by this test has a transaction, commit it. Otherwise, don't bother. """ class JustForCleanup(object): def newTransaction(self, *whatever): return self def commit(self): return return transactionFromRequest(self._cleanupRequest, JustForCleanup()).commit()
def http_POST(self, request): """ The server-to-server POST method. """ # This is a server-to-server scheduling operation. scheduler = IScheduleScheduler(request, self) # Need a transaction to work with txn = transactionFromRequest(request, self._newStore) request._newStoreTransaction = txn # Do the POST processing treating this as a non-local schedule try: result = (yield scheduler.doSchedulingViaPOST(txn, use_request_headers=True)) except Exception, e: yield txn.abort() raise e
def http_POST(self, request): """ The server-to-server POST method. """ # Need a transaction to work with txn = transactionFromRequest(request, self._newStore) # This is a server-to-server scheduling operation. scheduler = IScheduleScheduler(txn, None, podding=self._podding) # Check content first contentType = request.headers.getHeader("content-type") format = self.determineType(contentType) if format is None: msg = "MIME type {} not allowed in iSchedule request".format(contentType,) self.log.error(msg) raise HTTPError(scheduler.errorResponse( responsecode.FORBIDDEN, (ischedule_namespace, "invalid-calendar-data-type"), msg, )) originator = self.loadOriginatorFromRequestHeaders(request) recipients = self.loadRecipientsFromRequestHeaders(request) body = (yield allDataFromStream(request.stream)) calendar = Component.fromString(body, format=format) # Do the POST processing treating this as a non-local schedule try: result = (yield scheduler.doSchedulingViaPOST(request.remoteAddr, request.headers, body, calendar, originator, recipients)) except Exception: ex = Failure() yield txn.abort() ex.raiseException() else: yield txn.commit() response = result.response(format=format) if not self._podding: response.headers.addRawHeader(ISCHEDULE_CAPABILITIES, str(config.Scheduling.iSchedule.SerialNumber)) returnValue(response)
def homeResourceForRecord(self, record, request): transaction = transactionFromRequest(request, self.parent._newStore) name = record.uid if record is None: self.log_msg("No directory record with GUID %r" % (name,)) return None if not record.enabledForCalendaring: self.log_msg("Directory record %r is not enabled for calendaring" % (record,)) return None assert len(name) > 4, "Directory record has an invalid GUID: %r" % (name,) if record.locallyHosted(): child = DirectoryCalendarHomeResource(self, record, transaction) else: child = DirectoryReverseProxyResource(self, record) return child
def generateSchedulingResponses(self): def failForRecipient(recipient): err = HTTPError(ErrorResponse( responsecode.FORBIDDEN, (caldav_namespace, "recipient-failed"), "iMIP request failed", )) self.responses.add( recipient.cuaddr, Failure(exc_value=err), reqstatus=iTIPRequestStatus.SERVICE_UNAVAILABLE, suppressErrorLog=True ) # Generate an HTTP client request try: # We do not do freebusy requests via iMIP if self.freebusy: raise ValueError("iMIP VFREEBUSY requests not supported.") method = self.scheduler.calendar.propertyValue("METHOD") if method not in ( "PUBLISH", "REQUEST", "REPLY", "ADD", "CANCEL", "DECLINE_COUNTER", ): log.info("Could not do server-to-imip method: %s" % (method,)) for recipient in self.recipients: err = HTTPError(ErrorResponse( responsecode.FORBIDDEN, (caldav_namespace, "recipient-failed"), "iMIP method not allowed: %s" % (method,), )) self.responses.add( recipient.cuaddr, Failure(exc_value=err), reqstatus=iTIPRequestStatus.NO_USER_SUPPORT ) returnValue(None) caldata = str(self.scheduler.calendar) for recipient in self.recipients: try: toAddr = str(recipient.cuaddr) if not toAddr.lower().startswith("mailto:"): raise ValueError("ATTENDEE address '%s' must be mailto: for iMIP operation." % (toAddr,)) fromAddr = str(self.scheduler.originator.cuaddr) txn = transactionFromRequest(self.scheduler.request, self.scheduler.request._newStoreTransaction.store) log.debug("Submitting iMIP message... To: '%s', From :'%s'\n%s" % (toAddr, fromAddr, caldata,)) yield txn.enqueue(IMIPInvitationWork, fromAddr=fromAddr, toAddr=toAddr, icalendarText=caldata) except Exception, e: # Generated failed response for this recipient log.debug("iMIP request %s failed for recipient %s: %s" % (self, recipient, e)) failForRecipient(recipient) else: self.responses.add( recipient.cuaddr, responsecode.OK, reqstatus=iTIPRequestStatus.MESSAGE_SENT ) except Exception, e: # Generated failed responses for each recipient log.debug("iMIP request %s failed: %s" % (self, e)) for recipient in self.recipients: failForRecipient(recipient)