def _doSetNodeConfiguration(self, result, options): node, affiliation = result if affiliation != 'owner': raise error.Forbidden() return node.setConfiguration(options)
def unsubscribe(self, nodeIdentifier, subscriber, requestor): if subscriber.userhostJID() != requestor.userhostJID(): return defer.fail(error.Forbidden()) d = self.storage.getNode(nodeIdentifier) d.addCallback(lambda node: node.removeSubscription(subscriber)) return d
def subscribe(self, nodeIdentifier, subscriber, requestor): subscriberEntity = subscriber.userhostJID() if subscriberEntity != requestor.userhostJID(): return defer.fail(error.Forbidden()) d = self.storage.getNode(nodeIdentifier) d.addCallback(_getAffiliation, subscriberEntity) d.addCallback(self._doSubscribe, subscriber) return d
def _doPreDelete(self, result, redirectURI): node, affiliation = result if affiliation != 'owner': raise error.Forbidden() data = {'nodeIdentifier': node.nodeIdentifier, 'redirectURI': redirectURI} d = defer.DeferredList([cb(data) for cb in self._callbackList], consumeErrors=1) d.addCallback(self._doDelete, node.nodeIdentifier)
def _doPurge(self, result): node, affiliation = result persistItems = node.getConfiguration()["pubsub#persist_items"] if affiliation != 'owner': raise error.Forbidden() if not persistItems: raise error.NodeNotPersistent() d = node.purge() d.addCallback(self._doNotifyPurge, node.nodeIdentifier) return d
def _doRetract(self, result, itemIdentifiers): node, affiliation = result persistItems = node.getConfiguration()["pubsub#persist_items"] if affiliation not in ['owner', 'publisher']: raise error.Forbidden() if not persistItems: raise error.NodeNotPersistent() d = node.removeItems(itemIdentifiers) d.addCallback(self._doNotifyRetraction, node.nodeIdentifier) return d
def _doGetItems(self, result, maxItems, itemIdentifiers): node, affiliation = result if not ILeafNode.providedBy(node): return [] if affiliation == 'outcast': raise error.Forbidden() if itemIdentifiers: return node.getItemsById(itemIdentifiers) else: return node.getItems(maxItems)
def _doSubscribe(self, result, subscriber): node, affiliation = result if affiliation == 'outcast': raise error.Forbidden() def trapExists(failure): failure.trap(error.SubscriptionExists) return False def cb(sendLast): d = node.getSubscription(subscriber) if sendLast: d.addCallback(self._sendLastPublished, node) return d d = node.addSubscription(subscriber, 'subscribed', {}) d.addCallbacks(lambda _: True, trapExists) d.addCallback(cb) return d
def check(affiliation, node): if affiliation not in ['owner', 'publisher']: raise error.Forbidden() return node