Mercurial > libervia-pubsub
comparison sat_pubsub/backend.py @ 352:efbdca10f0fb
schema: node schema implementation
node schema is an experimental (not standard yet, protoXEP should follow) feature allowing to attach a data schema to a node.
This commit implement it and method needed to retrieve/set a schema.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 08 Sep 2017 08:02:05 +0200 |
parents | 20b82fb8de02 |
children | 7c5d85c6fb3a |
comparison
equal
deleted
inserted
replaced
351:2098295747fd | 352:efbdca10f0fb |
---|---|
525 nodeType = 'leaf' | 525 nodeType = 'leaf' |
526 config = self.storage.getDefaultConfiguration(nodeType) | 526 config = self.storage.getDefaultConfiguration(nodeType) |
527 config['pubsub#node_type'] = nodeType | 527 config['pubsub#node_type'] = nodeType |
528 config.update(options) | 528 config.update(options) |
529 | 529 |
530 d = self.storage.createNode(nodeIdentifier, requestor, config, pep, recipient) | 530 # TODO: handle schema on creation |
531 d = self.storage.createNode(nodeIdentifier, requestor, config, None, pep, recipient) | |
531 d.addCallback(lambda _: nodeIdentifier) | 532 d.addCallback(lambda _: nodeIdentifier) |
532 return d | 533 return d |
533 | 534 |
534 | 535 |
535 def getDefaultConfiguration(self, nodeType): | 536 def getDefaultConfiguration(self, nodeType): |
562 | 563 |
563 if affiliation != 'owner': | 564 if affiliation != 'owner': |
564 raise error.Forbidden() | 565 raise error.Forbidden() |
565 | 566 |
566 return node.setConfiguration(options) | 567 return node.setConfiguration(options) |
568 | |
569 | |
570 def getNodeSchema(self, nodeIdentifier, pep, recipient): | |
571 if not nodeIdentifier: | |
572 return defer.fail(error.NoRootNode()) | |
573 | |
574 d = self.storage.getNode(nodeIdentifier, pep, recipient) | |
575 d.addCallback(lambda node: node.getSchema()) | |
576 | |
577 return d | |
578 | |
579 | |
580 def setNodeSchema(self, nodeIdentifier, schema, requestor, pep, recipient): | |
581 """set or remove Schema of a node | |
582 | |
583 @param NodeIdentifier(unicode): identifier of the pubusb node | |
584 @param schema(domish.Element, None): schema to set | |
585 None to remove schema | |
586 """ | |
587 if not nodeIdentifier: | |
588 return defer.fail(error.NoRootNode()) | |
589 | |
590 d = self.storage.getNode(nodeIdentifier, pep, recipient) | |
591 d.addCallback(_getAffiliation, requestor) | |
592 d.addCallback(self._doSetNodeSchema, schema) | |
593 return d | |
594 | |
595 | |
596 def _doSetNodeSchema(self, result, schema): | |
597 node, affiliation = result | |
598 | |
599 if affiliation != 'owner': | |
600 raise error.Forbidden() | |
601 | |
602 return node.setSchema(schema) | |
567 | 603 |
568 | 604 |
569 def getAffiliations(self, entity, nodeIdentifier, pep, recipient): | 605 def getAffiliations(self, entity, nodeIdentifier, pep, recipient): |
570 return self.storage.getAffiliations(entity, nodeIdentifier, pep, recipient) | 606 return self.storage.getAffiliations(entity, nodeIdentifier, pep, recipient) |
571 | 607 |