Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0470.py @ 3945:2b2856ae5eeb
plugin XEP-0470: fix autocreate in `create_attachments_node`:
Due to config check, `create_attachments_node` was failing when the target node was not
already existing. However, this is the case when an item is published and `autocreate` is
expected, thus the node is now created if not already existing and new `autocreate`
argument is set.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 15 Oct 2022 20:38:33 +0200 |
parents | 43024e50b701 |
children | 3cb9ade2ab84 |
comparison
equal
deleted
inserted
replaced
3944:748094d5a74d | 3945:2b2856ae5eeb |
---|---|
162 node: str, | 162 node: str, |
163 item: domish.Element, | 163 item: domish.Element, |
164 data: dict | 164 data: dict |
165 ) -> bool: | 165 ) -> bool: |
166 """trigger to create attachment node on each publication""" | 166 """trigger to create attachment node on each publication""" |
167 await self.create_attachments_node(client, service, node, item["id"]) | 167 await self.create_attachments_node( |
168 client, service, node, item["id"], autocreate=True | |
169 ) | |
168 return True | 170 return True |
169 | 171 |
170 async def create_attachments_node( | 172 async def create_attachments_node( |
171 self, | 173 self, |
172 client: SatXMPPEntity, | 174 client: SatXMPPEntity, |
173 service: jid.JID, | 175 service: jid.JID, |
174 node: str, | 176 node: str, |
175 item_id: str | 177 item_id: str, |
178 autocreate: bool = False | |
176 ): | 179 ): |
177 """Create node for attachements if necessary""" | 180 """Create node for attachements if necessary |
178 node_config = await self._p.getConfiguration(client, service, node) | 181 |
182 @param service: service of target node | |
183 @param node: node where target item is published | |
184 @param item_id: ID of target item | |
185 @param autocrate: if True, target node is create if it doesn't exist | |
186 """ | |
187 try: | |
188 node_config = await self._p.getConfiguration(client, service, node) | |
189 except error.StanzaError as e: | |
190 if e.condition == "item-not-found" and autocreate: | |
191 # we auto-create the missing node | |
192 await self._p.createNode( | |
193 client, service, node | |
194 ) | |
195 node_config = await self._p.getConfiguration(client, service, node) | |
196 else: | |
197 raise e | |
179 try: | 198 try: |
180 # FIXME: check if this is the best publish_model option | 199 # FIXME: check if this is the best publish_model option |
181 node_config.fields["pubsub#publish_model"].value = "open" | 200 node_config.fields["pubsub#publish_model"].value = "open" |
182 except KeyError: | 201 except KeyError: |
183 log.warning("pubsub#publish_model field is missing") | 202 log.warning("pubsub#publish_model field is missing") |