Mercurial > libervia-backend
diff sat/plugins/plugin_misc_merge_requests.py @ 3452:bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
this implementation replaces the former non standard node schema, and works in a similar
way (the schema is put in a separated node instead of a special field, thus it will now
work with most/all PubSub services, and not only SàT PubSub).
The implementation has been done in a way that nothing should be changed in frontends
(bridge methods names and arguments stay the same). The nodes are modified, but if values
are taken from backend, it's automatically adapted.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 Dec 2020 17:57:00 +0100 |
parents | 71761e9fb984 |
children | 6deea0d8d0e7 |
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_merge_requests.py Fri Dec 11 17:50:53 2020 +0100 +++ b/sat/plugins/plugin_misc_merge_requests.py Fri Dec 11 17:57:00 2020 +0100 @@ -29,14 +29,14 @@ log = getLogger(__name__) -NS_MERGE_REQUESTS = 'org.salut-a-toi.merge_requests:0' +APP_NS_MERGE_REQUESTS = 'org.salut-a-toi.merge_requests:0' PLUGIN_INFO = { C.PI_NAME: _("Merge requests management"), C.PI_IMPORT_NAME: "MERGE_REQUESTS", C.PI_TYPE: "EXP", C.PI_PROTOCOLS: [], - C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "TICKETS", "TEXT_SYNTAXES"], + C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "TICKETS", "TEXT_SYNTAXES"], C.PI_MAIN: "MergeRequests", C.PI_HANDLER: "no", C.PI_DESCRIPTION: _("""Merge requests management plugin""") @@ -68,9 +68,10 @@ def __init__(self, host): log.info(_("Merge requests plugin initialization")) self.host = host - host.registerNamespace('merge_requests', NS_MERGE_REQUESTS) + self._s = self.host.plugins["XEP-0346"] + self.namespace = self._s.getSubmittedNS(APP_NS_MERGE_REQUESTS) + host.registerNamespace('merge_requests', self.namespace) self._p = self.host.plugins["XEP-0060"] - self._s = self.host.plugins["PUBSUB_SCHEMA"] self._t = self.host.plugins["TICKETS"] self._handlers = {} self._handlers_list = [] # handlers sorted by priority @@ -89,7 +90,7 @@ method=lambda service, nodeIdentifier, profile_key: self._s._getUISchema(service, nodeIdentifier, - default_node=NS_MERGE_REQUESTS, + default_node=self.namespace, profile_key=profile_key), async_=True) host.bridge.addMethod("mergeRequestParseData", ".plugin", @@ -172,7 +173,7 @@ - list of parsed request data (if extra['parse'] is set, else empty list) """ if not node: - node = NS_MERGE_REQUESTS + node = self.namespace if extra is None: extra = {} # XXX: Q&D way to get list for labels when displaying them, but text when we @@ -181,17 +182,19 @@ filters = {'labels': self._s.textbox2ListFilter} else: filters = {} - tickets_xmlui, metadata = yield self._s.getDataFormItems( - client, - service, - node, - max_items=max_items, - item_ids=item_ids, - sub_id=sub_id, - rsm_request=rsm_request, - extra=extra, - form_ns=NS_MERGE_REQUESTS, - filters = filters) + tickets_xmlui, metadata = yield defer.ensureDeferred( + self._s.getDataFormItems( + client, + service, + node, + max_items=max_items, + item_ids=item_ids, + sub_id=sub_id, + rsm_request=rsm_request, + extra=extra, + form_ns=APP_NS_MERGE_REQUESTS, + filters = filters) + ) parsed_patches = [] if extra.get('parse', False): for ticket in tickets_xmlui: @@ -228,7 +231,7 @@ @return (unicode): id of the created item """ if not node: - node = NS_MERGE_REQUESTS + node = self.namespace if values is None: values = {} update = extra.get('update', False) @@ -285,7 +288,7 @@ values[FIELD_DATA] = data item_id = await self._t.set(client, service, node, values, schema, item_id, extra, - deserialise, form_ns=NS_MERGE_REQUESTS) + deserialise, form_ns=APP_NS_MERGE_REQUESTS) return item_id def _parseData(self, data_type, data): @@ -326,14 +329,16 @@ @param repository(unicode): path to the repository where the code stands """ if not node: - node = NS_MERGE_REQUESTS - tickets_xmlui, metadata = yield self._s.getDataFormItems( - client, - service, - node, - max_items=1, - item_ids=[item], - form_ns=NS_MERGE_REQUESTS) + node = self.namespace + tickets_xmlui, metadata = yield defer.ensureDeferred( + self._s.getDataFormItems( + client, + service, + node, + max_items=1, + item_ids=[item], + form_ns=APP_NS_MERGE_REQUESTS) + ) ticket_xmlui = tickets_xmlui[0] data = ticket_xmlui.named_widgets[FIELD_DATA].value data_type = ticket_xmlui.named_widgets[FIELD_DATA_TYPE].value