annotate sat_pubsub/backend.py @ 489:fa0d2a4783fa default tip

install: use PEP-440 compatible version in `setup`: setuptools from version v66 doesn't accept anymore non PEP-440 compatible version. This is a Q&D fix, move to `pyproject.toml` with proper versioning as for Libervia backend should be done sooner than later.
author Goffi <goffi@goffi.org>
date Fri, 12 Jan 2024 23:46:24 +0100
parents 70eddf92bf51
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
1 #!/usr/bin/env python3
237
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
2 #
440
074037832daf dates update
Goffi <goffi@goffi.org>
parents: 438
diff changeset
3 # Copyright (c) 2012-2021 Jérôme Poisson
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
4 # Copyright (c) 2013-2016 Adrien Cossa
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
5 # Copyright (c) 2003-2011 Ralph Meijer
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
6
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
7
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
8 # This program is free software: you can redistribute it and/or modify
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
11 # (at your option) any later version.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
12
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
13 # This program is distributed in the hope that it will be useful,
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
16 # GNU Affero General Public License for more details.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
17
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
20 # --
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
21
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
22 # This program is based on Idavoll (http://idavoll.ik.nu/),
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
23 # originaly written by Ralph Meijer (http://ralphm.net/blog/)
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
24 # It is sublicensed under AGPL v3 (or any later version) as allowed by the original
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
25 # license.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
26
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
27 # --
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
28
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
29 # Here is a copy of the original license:
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
30
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
31 # Copyright (c) 2003-2011 Ralph Meijer
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
32
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
33 # Permission is hereby granted, free of charge, to any person obtaining
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
34 # a copy of this software and associated documentation files (the
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
35 # "Software"), to deal in the Software without restriction, including
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
36 # without limitation the rights to use, copy, modify, merge, publish,
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
37 # distribute, sublicense, and/or sell copies of the Software, and to
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
38 # permit persons to whom the Software is furnished to do so, subject to
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
39 # the following conditions:
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
40
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
41 # The above copyright notice and this permission notice shall be
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
42 # included in all copies or substantial portions of the Software.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
43
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
44 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
45 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
46 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
47 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
48 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
49 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
50 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
51
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 153
diff changeset
52
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
53 """
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
54 Generic publish-subscribe backend.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
55
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
56 This module implements a generic publish-subscribe backend service with
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
57 business logic as per
200
2189c663ba44 Epytext fixes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
58 U{XEP-0060<http://www.xmpp.org/extensions/xep-0060.html>} that interacts with
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
59 a given storage facility. It also provides an adapter from the XMPP
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
60 publish-subscribe protocol.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
61 """
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
62
394
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
63 import copy
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
64 import uuid
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
65 import hashlib
481
0e801ae1869f backend: use `typing.Dict[]` instead of `dict[]` to be compatible with Python 3.7
Goffi <goffi@goffi.org>
parents: 478
diff changeset
66 from typing import Optional, List, Tuple, Dict
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
67
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
68 from zope.interface import implementer
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
69
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
70 from twisted.application import service
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
71 from twisted.python import components, failure, log
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents: 181
diff changeset
72 from twisted.internet import defer, reactor
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
73 from twisted.words.protocols.jabber.error import StanzaError
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
74 from twisted.words.protocols.jabber import jid
381
7c490bb60847 backend: items ids are returned in payload if not specified on publish
Goffi <goffi@goffi.org>
parents: 380
diff changeset
75 from twisted.words.xish import domish, utility
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
76
317
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
77 from wokkel import disco
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
78 from wokkel import data_form
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
79 from wokkel import rsm
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
80 from wokkel import iwokkel
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
81 from wokkel import pubsub
375
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
82 from wokkel.subprotocols import XMPPHandler
20
eddea65d1032 Added two exceptions: NoInstantNodes and NodeExists.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
83
317
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
84 from sat_pubsub import error
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
85 from sat_pubsub import iidavoll
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
86 from sat_pubsub import const
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
87 from sat_pubsub import container
15
46cd13c68ac0 Redone memory storage of nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 5
diff changeset
88
430
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
89 # TODO: modernise the code, get rid of legacy Twisted logging, use coroutines,
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
90 # better formatting
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
91
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
92
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
93 def _getAffiliation(node, entity):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
94 d = node.getAffiliation(entity)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
95 d.addCallback(lambda affiliation: (node, affiliation))
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
96 return d
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 20
diff changeset
97
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
98
394
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
99 def elementCopy(element):
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
100 """Make a copy of a domish.Element
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
101
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
102 The copy will have its own children list, so other elements
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
103 can be added as direct children without modifying orignal one.
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
104 Children are not deeply copied, so if an element is added to a child or grandchild,
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
105 it will also affect original element.
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
106 @param element(domish.Element): Element to clone
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
107 """
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
108 new_elt = domish.Element(
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
109 (element.uri, element.name),
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
110 defaultUri = element.defaultUri,
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
111 attribs = element.attributes,
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
112 localPrefixes = element.localPrefixes)
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
113 new_elt.parent = element.parent
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
114 new_elt.children = element.children[:]
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
115 return new_elt
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
116
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
117
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
118 def itemDataCopy(item_data):
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
119 """Make a copy of an item_data
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
120
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
121 deep copy every element of the tuple but item
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
122 do an elementCopy of item_data.item
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
123 @param item_data(ItemData): item data to copy
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
124 @return (ItemData): copied data
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
125 """
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
126 return container.ItemData(*[elementCopy(item_data.item)]
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
127 + [copy.deepcopy(d) for d in item_data[1:]])
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
128
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
129
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
130 @implementer(iidavoll.IBackendService)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
131 class BackendService(service.Service, utility.EventDispatcher):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
132 """
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
133 Generic publish-subscribe backend service.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
134
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
135 @cvar nodeOptions: Node configuration form as a mapping from the field
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
136 name to a dictionary that holds the field's type, label
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
137 and possible options to choose from.
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
138 @type nodeOptions: C{dict}.
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
139 @cvar defaultConfig: The default node configuration.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
140 """
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
141
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
142
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
143 nodeOptions = {
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
144 const.OPT_PERSIST_ITEMS:
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
145 {"type": "boolean",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
146 "label": "Persist items to storage"},
422
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
147 const.OPT_MAX_ITEMS:
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
148 {"type": "text-single",
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
149 "label": 'number of items to keep ("max" for unlimited)'},
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
150 const.OPT_DELIVER_PAYLOADS:
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
151 {"type": "boolean",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
152 "label": "Deliver payloads with event notifications"},
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
153 const.OPT_SEND_LAST_PUBLISHED_ITEM:
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
154 {"type": "list-single",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
155 "label": "When to send the last published item",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
156 "options": {
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
157 "never": "Never",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
158 "on_sub": "When a new subscription is processed"}
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
159 },
259
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
160 const.OPT_ACCESS_MODEL:
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
161 {"type": "list-single",
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
162 "label": "Who can subscribe to this node",
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
163 "options": {
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
164 const.VAL_AMODEL_OPEN: "Public node",
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
165 const.VAL_AMODEL_PRESENCE: "Node restricted to entites subscribed to owner presence",
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
166 const.VAL_AMODEL_PUBLISHER_ROSTER: "Node restricted to some groups of publisher's roster",
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
167 const.VAL_AMODEL_WHITELIST: "Node restricted to some jids",
259
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
168 }
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
169 },
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
170 const.OPT_ROSTER_GROUPS_ALLOWED:
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
171 {"type": "list-multi",
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
172 "label": "Groups of the roster allowed to access the node",
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
173 },
260
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
174 const.OPT_PUBLISH_MODEL:
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
175 {"type": "list-single",
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
176 "label": "Who can publish to this node",
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
177 "options": {
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
178 const.VAL_PMODEL_OPEN: "Everybody can publish",
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
179 const.VAL_PMODEL_PUBLISHERS: "Only owner and publishers can publish",
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
180 const.VAL_PMODEL_SUBSCRIBERS: "Everybody which subscribed to the node",
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
181 }
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
182 },
438
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
183 const.OPT_OVERWRITE_POLICY:
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
184 {"type": "list-single",
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
185 "label": "Who can overwrite an item",
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
186 "options": {
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
187 const.VAL_OWPOL_ORIGINAL: "Only original publisher of the item",
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
188 const.VAL_OWPOL_ANY_PUB: "Any publisher",
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
189 }
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
190 },
367
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
191 const.OPT_SERIAL_IDS:
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
192 {"type": "boolean",
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
193 "label": "Use serial ids"},
403
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
194 const.OPT_CONSISTENT_PUBLISHER:
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
195 {"type": "boolean",
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
196 "label": "Keep publisher on update"},
430
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
197 const.OPT_FTS_LANGUAGE:
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
198 {"type": "list-single",
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
199 "label": "Default language to use for full text search",
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
200 "options": {
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
201 const.VAL_FTS_GENERIC: (
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
202 "Generic (use if unsure of if your language is not present)"
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
203 )
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
204 }
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
205 },
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
206 }
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
207
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
208 subscriptionOptions = {
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
209 "pubsub#subscription_type":
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
210 {"type": "list-single",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
211 "options": {
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
212 "items": "Receive notification of new items only",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
213 "nodes": "Receive notification of new nodes only"}
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
214 },
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
215 "pubsub#subscription_depth":
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
216 {"type": "list-single",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
217 "options": {
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
218 "1": "Receive notification from direct child nodes only",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
219 "all": "Receive notification from all descendent nodes"}
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
220 },
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
221 }
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
222
380
e81964db3cd6 administrators entities:
Goffi <goffi@goffi.org>
parents: 377
diff changeset
223 def __init__(self, storage, config):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
224 utility.EventDispatcher.__init__(self)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
225 self.storage = storage
380
e81964db3cd6 administrators entities:
Goffi <goffi@goffi.org>
parents: 377
diff changeset
226 self.config = config
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
227 self.admins = config['admins_jids_list']
460
607616f9ef5b backend: new `server_jid` option:
Goffi <goffi@goffi.org>
parents: 459
diff changeset
228 self.jid = config["jid"]
607616f9ef5b backend: new `server_jid` option:
Goffi <goffi@goffi.org>
parents: 459
diff changeset
229 if config["server_jid"] is None:
607616f9ef5b backend: new `server_jid` option:
Goffi <goffi@goffi.org>
parents: 459
diff changeset
230 self.server_jid = jid.JID(str(self.jid).split(".", 1)[1])
607616f9ef5b backend: new `server_jid` option:
Goffi <goffi@goffi.org>
parents: 459
diff changeset
231 else:
607616f9ef5b backend: new `server_jid` option:
Goffi <goffi@goffi.org>
parents: 459
diff changeset
232 self.server_jid = jid.JID(config["server_jid"])
430
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
233 d = self.storage.getFTSLanguages()
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
234 d.addCallbacks(self._getFTSLanguagesCb, self._getFTSLanguagesEb)
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
235
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
236 def _getFTSLanguagesCb(self, languages):
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
237 # we skip the first one which is always "generic", as we already have it
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
238 for l in languages[1:]:
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
239 self.nodeOptions[const.OPT_FTS_LANGUAGE]["options"][l] = l.title()
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
240
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
241 def _getFTSLanguagesEb(self, failure_):
5a0ada3b61ca Full-Text Search implementation:
Goffi <goffi@goffi.org>
parents: 422
diff changeset
242 log.msg(f"WARNING: can get FTS languages: {failure_}")
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
243
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
244 def isAdmin(self, entity_jid: jid.JID) -> bool:
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
245 """Return True if an entity is an administrator"""
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
246 return entity_jid.userhostJID() in self.admins
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
247
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
248 def isFromServer(self, entity_jid: jid.JID) -> bool:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
249 """Return True if an entity come from our server"""
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
250 return entity_jid.host == self.server_jid.host
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
251
363
a98b3d52c2ff added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents: 358
diff changeset
252 def supportsPublishOptions(self):
a98b3d52c2ff added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents: 358
diff changeset
253 return True
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
254
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
255 def supportsPublisherAffiliation(self):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
256 return True
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
257
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
258 def supportsGroupBlog(self):
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
259 return True
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
260
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
261 def supportsOutcastAffiliation(self):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
262 return True
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
263
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
264 def supportsPersistentItems(self):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
265 return True
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
266
260
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
267 def supportsPublishModel(self):
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
268 return True
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
269
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
270 def getNodeType(self, nodeIdentifier, pep, recipient=None):
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
271 # FIXME: manage pep and recipient
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
272 d = self.storage.getNode(nodeIdentifier, pep, recipient)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
273 d.addCallback(lambda node: node.getType())
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
274 return d
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
275
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
276 def _getNodesIds(self, subscribed, pep, recipient):
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
277 # TODO: filter whitelist nodes
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
278 # TODO: handle publisher-roster (should probably be renamed to owner-roster for nodes)
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
279 if not subscribed:
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
280 allowed_accesses = {'open', 'whitelist'}
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
281 else:
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
282 allowed_accesses = {'open', 'presence', 'whitelist'}
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
283 return self.storage.getNodeIds(pep, recipient, allowed_accesses)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
284
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
285 async def getNodes(self, requestor, pep, recipient):
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
286 if pep:
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
287 subscribed = await self.privilege.isSubscribedFrom(requestor, recipient)
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
288 return await self._getNodesIds(subscribed, pep, recipient)
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
289 return await self.storage.getNodeIds(pep, recipient)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
290
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
291 def getNodeMetaData(self, nodeIdentifier, pep, recipient=None):
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
292 # FIXME: manage pep and recipient
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
293 d = self.storage.getNode(nodeIdentifier, pep, recipient)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
294 d.addCallback(lambda node: node.getMetaData())
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
295 d.addCallback(self._makeMetaData)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
296 return d
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
297
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
298 def _makeMetaData(self, metaData):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
299 options = []
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
300 for key, value in metaData.items():
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
301 if key in self.nodeOptions:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
302 option = {"var": key}
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
303 option.update(self.nodeOptions[key])
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
304 option["value"] = value
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
305 options.append(option)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
306
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
307 return options
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
308
461
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
309 async def _checkAuth(self, node, requestor):
260
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
310 """ Check authorisation of publishing in node for requestor """
461
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
311 affiliation = await node.getAffiliation(requestor)
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
312 configuration = node.getConfiguration()
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
313 publish_model = configuration[const.OPT_PUBLISH_MODEL]
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
314 if publish_model == const.VAL_PMODEL_PUBLISHERS:
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
315 if affiliation not in ['owner', 'publisher']:
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
316 raise error.Forbidden()
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
317 elif publish_model == const.VAL_PMODEL_SUBSCRIBERS:
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
318 if affiliation not in ['owner', 'publisher']:
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
319 # we are in subscribers publish model, we must check that
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
320 # the requestor is a subscriber to allow him to publish
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
321 subscribed = await node.isSubscribed(requestor)
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
322 if not subscribed:
260
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
323 raise error.Forbidden()
461
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
324 elif publish_model != const.VAL_PMODEL_OPEN:
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
325 # publish_model must be publishers (default), subscribers or open.
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
326 raise ValueError('Unexpected value')
260
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
327
461
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
328 return (affiliation, node)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
329
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
330 def parseItemConfig(self, item):
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
331 """Get and remove item configuration information
301
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
332
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
333 @param item (domish.Element): item to parse
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
334 @return (tuple[unicode, dict)): (access_model, item_config)
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
335 """
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
336 item_config = None
259
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
337 access_model = const.VAL_AMODEL_DEFAULT
336
a468c187bbb5 fixed parseItemConfig (was iterating on children instead of elements)
Goffi <goffi@goffi.org>
parents: 333
diff changeset
338 for idx, elt in enumerate(item.elements()):
395
9bc3fbf3e685 backend: fixed elements filtering in parseItemConfig
Goffi <goffi@goffi.org>
parents: 394
diff changeset
339 if elt.uri != data_form.NS_X_DATA or elt.name != 'x':
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
340 continue
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
341 form = data_form.Form.fromElement(elt)
300
c5acb4995fde cleaner parseItemConfig
Goffi <goffi@goffi.org>
parents: 299
diff changeset
342 if form.formNamespace == const.NS_ITEM_CONFIG:
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
343 item_config = form
300
c5acb4995fde cleaner parseItemConfig
Goffi <goffi@goffi.org>
parents: 299
diff changeset
344 del item.children[idx] #we need to remove the config from item
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
345 break
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
346
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
347 if item_config:
259
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
348 access_model = item_config.get(const.OPT_ACCESS_MODEL, const.VAL_AMODEL_DEFAULT)
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
349 return (access_model, item_config)
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
350
301
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
351 def parseCategories(self, item_elt):
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
352 """Check if item contain an atom entry, and parse categories if possible
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
353
364
8bd8be6815ab completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents: 363
diff changeset
354 @param item_elt (domish.Element): item to parse
301
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
355 @return (list): list of found categories
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
356 """
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
357 categories = []
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
358 try:
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
359 entry_elt = next(item_elt.elements(const.NS_ATOM, "entry"))
301
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
360 except StopIteration:
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
361 return categories
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
362
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
363 for category_elt in entry_elt.elements(const.NS_ATOM, 'category'):
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
364 category = category_elt.getAttribute('term')
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
365 if category:
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
366 categories.append(category)
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
367
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
368 return categories
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
369
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
370 def enforceSchema(self, item_elt, schema, affiliation):
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
371 """modifify item according to element, or refuse publishing
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
372
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
373 @param item_elt(domish.Element): item to check/modify
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
374 @param schema(domish.Eement): schema to enfore
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
375 @param affiliation(unicode): affiliation of the publisher
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
376 """
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
377 try:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
378 x_elt = next(item_elt.elements(data_form.NS_X_DATA, 'x'))
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
379 item_form = data_form.Form.fromElement(x_elt)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
380 except (StopIteration, data_form.Error):
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
381 raise pubsub.BadRequest(text="node has a schema but item has no form")
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
382 else:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
383 item_elt.children.remove(x_elt)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
384
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
385 schema_form = data_form.Form.fromElement(schema)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
386
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
387 # we enforce restrictions
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
388 for field_elt in schema.elements(data_form.NS_X_DATA, 'field'):
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
389 var = field_elt['var']
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
390 for restrict_elt in field_elt.elements(const.NS_SCHEMA_RESTRICT, 'restrict'):
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
391 write_restriction = restrict_elt.attributes.get('write')
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
392 if write_restriction is not None:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
393 if write_restriction == 'owner':
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
394 if affiliation != 'owner':
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
395 # write is not allowed on this field, we use default value
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
396 # we can safely use Field from schema_form because
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
397 # we have created this instance only for this method
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
398 try:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
399 item_form.removeField(item_form.fields[var])
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
400 except KeyError:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
401 pass
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
402 item_form.addField(schema_form.fields[var])
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
403 else:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
404 raise StanzaError('feature-not-implemented', text='unknown write restriction {}'.format(write_restriction))
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
405
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
406 # we now remove every field which is not in data schema
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
407 to_remove = set()
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
408 for item_var, item_field in item_form.fields.items():
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
409 if item_var not in schema_form.fields:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
410 to_remove.add(item_field)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
411
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
412 for field in to_remove:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
413 item_form.removeField(field)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
414 item_elt.addChild(item_form.toElement())
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
415
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
416 def _getFDPSubmittedNode(
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
417 self,
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
418 nodeIdentifier: str,
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
419 pep: bool,
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
420 recipient: jid.JID,
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
421 ) -> Optional[defer.Deferred]:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
422 """Get submitted forms node for Form Discovery and Publishing
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
423
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
424 @param nodeIdentifier: template node (must start with const.FDP_TEMPLATE_PREFIX)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
425 @êeturn: node or None if the node doesn't exist
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
426 """
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
427 app_ns = nodeIdentifier[len(const.FDP_TEMPLATE_PREFIX):]
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
428 submitted_node_id = f"{const.FDP_SUBMITTED_PREFIX}{app_ns}"
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
429 try:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
430 return self.storage.getNode(submitted_node_id, pep, recipient)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
431 except error.NodeNotFound:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
432 return None
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
433
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
434 async def publish(self, nodeIdentifier, items, requestor, options, pep, recipient):
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
435 if len(items) == 0:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
436 raise pubsub.BadRequest(text="no item to publish")
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
437 node = await self.storage.getNode(nodeIdentifier, pep, recipient)
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
438 affiliation, node = await self._checkAuth(node, requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
439
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
440 if node.nodeType == 'collection':
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
441 raise error.NoPublishing()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
442
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
443 configuration = node.getConfiguration()
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
444 persistItems = configuration[const.OPT_PERSIST_ITEMS]
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
445 deliverPayloads = configuration[const.OPT_DELIVER_PAYLOADS]
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
446
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
447 # we check that publish-options are satisfied
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
448 for field, value in options.items():
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
449 try:
484
70eddf92bf51 backend: fix check of boolean settings with `publish-options`
Goffi <goffi@goffi.org>
parents: 481
diff changeset
450 current_value = str(configuration[field]).lower()
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
451 except KeyError:
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
452 raise error.ConstraintFailed(
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
453 f"publish-options {field!r} doesn't exist in node configuration"
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
454 )
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
455 if current_value != value:
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
456 raise error.ConstraintFailed(
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
457 f"configuration field {field!r} has a value of {current_value!r} "
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
458 f"which doesn't fit publish-options expected {value!r}"
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
459 )
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
460
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
461 if items and not persistItems and not deliverPayloads:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
462 raise error.ItemForbidden()
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
463 elif not items and (persistItems or deliverPayloads):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
464 raise error.ItemRequired()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
465
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
466 items_data = []
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
467 check_overwrite = False
381
7c490bb60847 backend: items ids are returned in payload if not specified on publish
Goffi <goffi@goffi.org>
parents: 380
diff changeset
468 ret_payload = None # payload returned, None or domish.Element
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
469 for item in items:
299
07ad8d8fde77 item publisher is enforced
Goffi <goffi@goffi.org>
parents: 298
diff changeset
470 # we enforce publisher (cf XEP-0060 §7.1.2.3)
07ad8d8fde77 item publisher is enforced
Goffi <goffi@goffi.org>
parents: 298
diff changeset
471 item['publisher'] = requestor.full()
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
472 if persistItems or deliverPayloads:
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
473 item.uri = None
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
474 item.defaultUri = None
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
475 if not item.getAttribute("id"):
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
476 item["id"] = await node.getNextId()
367
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
477 new_item = True
389
66128656f76c backend: fixed items returned on publishing:
Goffi <goffi@goffi.org>
parents: 388
diff changeset
478 if ret_payload is None:
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
479 ret_pubsub_elt = domish.Element((pubsub.NS_PUBSUB, 'pubsub'))
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
480 ret_publish_elt = ret_pubsub_elt.addElement('publish')
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
481 ret_publish_elt['node'] = node.nodeIdentifier
389
66128656f76c backend: fixed items returned on publishing:
Goffi <goffi@goffi.org>
parents: 388
diff changeset
482 ret_payload = ret_pubsub_elt
66128656f76c backend: fixed items returned on publishing:
Goffi <goffi@goffi.org>
parents: 388
diff changeset
483 ret_publish_elt = ret_payload.publish
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
484 ret_item_elt = ret_publish_elt.addElement('item')
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
485 ret_item_elt["id"] = item["id"]
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
486 else:
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
487 check_overwrite = True
367
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
488 new_item = False
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
489 access_model, item_config = self.parseItemConfig(item)
301
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
490 categories = self.parseCategories(item)
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
491 schema = node.getSchema()
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
492 if schema is not None:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
493 self.enforceSchema(item, schema, affiliation)
367
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
494 items_data.append(container.ItemData(item, access_model, item_config, categories, new=new_item))
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
495
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
496 if persistItems:
367
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
497
403
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
498 if check_overwrite:
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
499 itemIdentifiers = [item['id'] for item in items
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
500 if item.getAttribute('id')]
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
501
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
502 if affiliation == 'owner' or self.isAdmin(requestor):
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
503 if configuration[const.OPT_CONSISTENT_PUBLISHER]:
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
504 pub_map = await node.getItemsPublishers(itemIdentifiers)
415
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
505 if pub_map:
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
506 # if we have existing items, we replace publishers with
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
507 # original one to stay consistent
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
508 publishers = set(pub_map.values())
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
509 if len(publishers) != 1:
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
510 # TODO: handle multiple items publishing (from several
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
511 # publishers)
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
512 raise error.NoPublishing(
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
513 "consistent_publisher is currently only possible when "
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
514 "publishing items from a single publisher. Try to "
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
515 "publish one item at a time")
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
516 # we replace requestor and new payload's publisher by original
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
517 # item publisher to keep publisher consistent
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
518 requestor = publishers.pop()
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
519 for item in items:
4179ed660a85 backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents: 414
diff changeset
520 item['publisher'] = requestor.full()
438
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
521 elif configuration[const.OPT_OVERWRITE_POLICY] == const.VAL_OWPOL_ORIGINAL:
403
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
522 # we don't want a publisher to overwrite the item
1dc606612405 implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents: 397
diff changeset
523 # of an other publisher
438
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
524 item_pub_map = await node.getItemsPublishers(itemIdentifiers)
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
525 for item_publisher in item_pub_map.values():
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
526 if item_publisher.userhost() != requestor.userhost():
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
527 raise error.ItemForbidden(
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
528 "Item can only be overwritten by original publisher"
b5e1e8d93dd4 backend, pgsql: new `overwrite_policy` node setting:
Goffi <goffi@goffi.org>
parents: 437
diff changeset
529 )
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
530
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
531 if node.nodeIdentifier.startswith(const.FDP_TEMPLATE_PREFIX):
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
532 schema_item = items_data[-1].item
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
533 try:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
534 schema = next(schema_item.elements(data_form.NS_X_DATA, 'x'))
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
535 except StopIteration:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
536 raise pubsub.BadRequest(text="Data form is missing in FDP request")
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
537 submitted_node = await self._getFDPSubmittedNode(
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
538 node.nodeIdentifier, pep, recipient)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
539 if submitted_node is not None:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
540 await submitted_node.setSchema(schema)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
541
367
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
542 # TODO: check conflict and recalculate max id if serial_ids is set
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
543 await node.storeItems(items_data, requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
544
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
545 self._doNotify(node, items_data, deliverPayloads, pep, recipient)
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
546 return ret_payload
367
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
547
a772f7dac930 backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents: 365
diff changeset
548 def _doNotify(self, node, items_data, deliverPayloads, pep, recipient):
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
549 if items_data and not deliverPayloads:
301
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
550 for item_data in items_data:
05c875a13a62 categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents: 300
diff changeset
551 item_data.item.children = []
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
552 self.dispatch({'items_data': items_data, 'node': node, 'pep': pep, 'recipient': recipient},
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
553 '//event/pubsub/notify')
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
554
339
516b282aa542 backend (notifications): avoid useless database request in getNotifications
Goffi <goffi@goffi.org>
parents: 336
diff changeset
555 def getNotifications(self, node, items_data):
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
556 """Build a list of subscriber to the node
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
557
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
558 subscribers will be associated with subscribed items,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
559 and subscription type.
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
560 """
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
561
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
562 def toNotifications(subscriptions, items_data):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
563 subsBySubscriber = {}
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
564 for subscription in subscriptions:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
565 if subscription.options.get('pubsub#subscription_type',
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
566 'items') == 'items':
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
567 subs = subsBySubscriber.setdefault(subscription.subscriber,
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
568 set())
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
569 subs.add(subscription)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
570
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
571 notifications = [(subscriber, subscriptions_, items_data)
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
572 for subscriber, subscriptions_
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
573 in subsBySubscriber.items()]
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
574
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
575 return notifications
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
576
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
577 def rootNotFound(failure):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
578 failure.trap(error.NodeNotFound)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
579 return []
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
580
339
516b282aa542 backend (notifications): avoid useless database request in getNotifications
Goffi <goffi@goffi.org>
parents: 336
diff changeset
581 d1 = node.getSubscriptions('subscribed')
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
582 # FIXME: must add root node subscriptions ?
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
583 # d2 = self.storage.getNode('', False) # FIXME: to check
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
584 # d2.addCallback(lambda node: node.getSubscriptions('subscribed'))
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
585 # d2.addErrback(rootNotFound)
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
586 # d = defer.gatherResults([d1, d2])
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
587 # d.addCallback(lambda result: result[0] + result[1])
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
588 d1.addCallback(toNotifications, items_data)
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
589 return d1
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
590
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
591 def registerPublishNotifier(self, observerfn, *args, **kwargs):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
592 self.addObserver('//event/pubsub/notify', observerfn, *args, **kwargs)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
593
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
594 def registerRetractNotifier(self, observerfn, *args, **kwargs):
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
595 self.addObserver('//event/pubsub/retract', observerfn, *args, **kwargs)
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
596
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
597 def registerDeleteNotifier(self, observerfn, *args, **kwargs):
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
598 self.addObserver('//event/pubsub/delete', observerfn, *args, **kwargs)
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
599
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
600 def registerPurgeNotifier(self, observerfn, *args, **kwargs):
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
601 self.addObserver('//event/pubsub/purge', observerfn, *args, **kwargs)
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
602
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
603 async def subscribe(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
604 self,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
605 nodeIdentifier: str,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
606 subscriber: jid.JID,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
607 requestor: jid.JID,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
608 options: Optional[dict],
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
609 pep: bool,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
610 recipient: jid.JID
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
611 ) -> pubsub.Subscription:
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
612 subscriberEntity = subscriber.userhostJID()
216
53d2c0019458 Fix subscription and unsubscription JID checks.
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
613 if subscriberEntity != requestor.userhostJID():
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
614 raise error.Forbidden()
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
615
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
616 node = await self.storage.getNode(nodeIdentifier, pep, recipient)
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
617 __, affiliation = await _getAffiliation(node, subscriberEntity)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
618
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
619 if affiliation == 'outcast':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
620 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
621
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
622 access_model = node.getAccessModel()
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
623
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
624 if access_model == const.VAL_AMODEL_OPEN:
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
625 pass
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
626 elif access_model == const.VAL_AMODEL_PRESENCE:
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
627 await self.checkPresenceSubscription(node, subscriber)
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
628 elif access_model == const.VAL_AMODEL_PUBLISHER_ROSTER:
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
629 await self.checkRosterGroups(node, subscriber)
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
630 elif access_model == const.VAL_AMODEL_WHITELIST:
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
631 await self.checkNodeAffiliations(node, subscriber)
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
632 else:
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
633 raise NotImplementedError
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
634
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
635 config = {}
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
636 if options and options.get(f"{{{const.NS_PPS}}}public"):
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
637 config["public"] = True
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
638 try:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
639 await node.addSubscription(subscriber, 'subscribed', config)
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
640 except error.SubscriptionExists:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
641 send_last = False
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
642 else:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
643 send_last = True
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
644
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
645 subscription = await node.getSubscription(subscriber)
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents: 181
diff changeset
646
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
647 if send_last:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
648 config = node.getConfiguration()
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
649 sendLastPublished = config.get(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
650 'pubsub#send_last_published_item', 'never'
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
651 )
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
652 if sendLastPublished == 'on_sub' and node.nodeType == 'leaf':
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
653 entity = subscription.subscriber.userhostJID()
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
654 items_data, __ = await self.getItemsData(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
655 node.nodeIdentifier, entity, recipient, maxItems=1,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
656 ext_data={'pep': pep}
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
657 )
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
658 if items_data:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
659 reactor.callLater(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
660 0,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
661 self.dispatch,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
662 {'items_data': items_data,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
663 'node': node,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
664 'pep': pep,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
665 'recipient': recipient,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
666 'subscription': subscription,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
667 },
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
668 '//event/pubsub/notify'
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
669 )
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
670
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
671 return subscription
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
672
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
673 async def unsubscribe(self, nodeIdentifier, subscriber, requestor, pep, recipient):
216
53d2c0019458 Fix subscription and unsubscription JID checks.
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
674 if subscriber.userhostJID() != requestor.userhostJID():
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
675 raise error.Forbidden()
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
676
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
677 node = await self.storage.getNode(nodeIdentifier, pep, recipient)
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
678 await node.removeSubscription(subscriber)
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
679 return pubsub.Subscription(nodeIdentifier, subscriber, "none")
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
680
357
1167e48e5f52 handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents: 355
diff changeset
681 def getSubscriptions(self, requestor, nodeIdentifier, pep, recipient):
1167e48e5f52 handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents: 355
diff changeset
682 """retrieve subscriptions of an entity
1167e48e5f52 handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents: 355
diff changeset
683
1167e48e5f52 handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents: 355
diff changeset
684 @param requestor(jid.JID): entity who want to check subscriptions
1167e48e5f52 handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents: 355
diff changeset
685 @param nodeIdentifier(unicode, None): identifier of the node
1167e48e5f52 handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents: 355
diff changeset
686 node to get all subscriptions of a service
364
8bd8be6815ab completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents: 363
diff changeset
687 @param pep(bool): True if it's a PEP request
8bd8be6815ab completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents: 363
diff changeset
688 @param recipient(jid.JID, None): recipient of the PEP request
357
1167e48e5f52 handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents: 355
diff changeset
689 """
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
690 return self.storage.getSubscriptions(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
691 requestor, nodeIdentifier, None, pep, recipient
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
692 )
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
693
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
694 def supportsAutoCreate(self):
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
695 return True
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
696
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
697 def supportsInstantNodes(self):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
698 return True
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
699
461
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
700 async def _createNode(
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
701 self,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
702 nodeIdentifier: Optional[str],
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
703 requestor: jid.JID,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
704 options: Optional[dict] = None,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
705 pep: bool = False,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
706 recipient: Optional[jid.JID] = None
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
707 ) -> str:
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
708 if pep:
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
709 if recipient == self.server_jid:
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
710 if not self.isAdmin(requestor):
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
711 raise error.Forbidden()
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
712 elif requestor.userhostJID() != recipient.userhostJID():
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
713 raise error.Forbidden()
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
714
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
715 if not nodeIdentifier:
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
716 nodeIdentifier = 'generic/%s' % uuid.uuid4()
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
717
259
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
718 if not options:
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
719 options = {}
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
720
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
721 nodeType = 'leaf'
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
722 config = self.storage.getDefaultConfiguration(nodeType)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
723 config['pubsub#node_type'] = nodeType
259
6fe7da6b4b32 node "roster" access model management
Goffi <goffi@goffi.org>
parents: 258
diff changeset
724 config.update(options)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
725
352
efbdca10f0fb schema: node schema implementation
Goffi <goffi@goffi.org>
parents: 349
diff changeset
726 # TODO: handle schema on creation
461
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
727 await self.storage.createNode(
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
728 nodeIdentifier, requestor, config, None, pep, recipient
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
729 )
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
730 return nodeIdentifier
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
731
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
732 def createNode(
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
733 self,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
734 nodeIdentifier: Optional[str],
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
735 requestor: jid.JID,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
736 options: Optional[dict] = None,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
737 pep: bool = False,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
738 recipient: Optional[jid.JID] = None
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
739 ) -> defer.Deferred:
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
740 return defer.ensureDeferred(self._createNode(
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
741 nodeIdentifier=nodeIdentifier,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
742 requestor=requestor,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
743 options=options,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
744 pep=pep,
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
745 recipient=recipient
c9238fca1fb3 backend: fix node creation permission check for PEP
Goffi <goffi@goffi.org>
parents: 460
diff changeset
746 ))
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
747
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
748 def getDefaultConfiguration(self, nodeType):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
749 d = defer.succeed(self.storage.getDefaultConfiguration(nodeType))
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
750 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
751
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
752 def getNodeConfiguration(self, nodeIdentifier, pep, recipient):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
753 if not nodeIdentifier:
196
00a6dbfbee42 Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
754 return defer.fail(error.NoRootNode())
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
755
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
756 if ((nodeIdentifier == const.NS_PPS_SUBSCRIPTIONS
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
757 or nodeIdentifier.startswith(const.PPS_SUBSCRIBERS_PREFIX))):
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
758 return defer.succeed({const.OPT_ACCESS_MODEL: const.VAL_AMODEL_OPEN})
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
759
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
760 d = self.storage.getNode(nodeIdentifier, pep, recipient)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
761 d.addCallback(lambda node: node.getConfiguration())
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
762
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
763 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
764
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
765 def setNodeConfiguration(self, nodeIdentifier, options, requestor, pep, recipient):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
766 if not nodeIdentifier:
196
00a6dbfbee42 Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
767 return defer.fail(error.NoRootNode())
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
768
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
769 d = self.storage.getNode(nodeIdentifier, pep, recipient)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
770 d.addCallback(_getAffiliation, requestor)
422
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
771 d.addCallback(
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
772 lambda result: defer.ensureDeferred(
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
773 self._doSetNodeConfiguration(result, requestor, options))
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
774 )
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
775 return d
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
776
422
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
777 async def _doSetNodeConfiguration(self, result, requestor, options):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
778 node, affiliation = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
779
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
780 if affiliation != 'owner' and not self.isAdmin(requestor):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
781 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
782
422
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
783 max_items = options.get(const.OPT_MAX_ITEMS, '').strip().lower()
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
784 if not max_items:
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
785 pass
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
786 elif max_items == 'max':
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
787 # FIXME: we use "0" for max for now, but as "0" may be used as legal value
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
788 # in XEP-0060 ("max" is used otherwise), we should use "None" instead.
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
789 # This require a schema update, as NULL is not allowed at the moment
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
790 options.fields[const.OPT_MAX_ITEMS].value = "0"
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
791 else:
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
792 # max_items is a number, we have to check that it's not bigger than the
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
793 # total number of items on this node
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
794 try:
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
795 max_items = int(max_items)
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
796 except ValueError:
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
797 raise error.InvalidConfigurationValue('Invalid "max_items" value')
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
798 else:
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
799 options.fields[const.OPT_MAX_ITEMS].value = str(max_items)
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
800 if max_items:
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
801 items_count = await node.getItemsCount(None, True)
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
802 if max_items < items_count:
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
803 raise error.ConstraintFailed(
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
804 "\"max_items\" can't be set to a value lower than the total "
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
805 "number of items on this node. Please increase \"max_items\" "
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
806 "or delete items from this node")
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
807
c21f31355ab9 configuration: "max_items" option:
Goffi <goffi@goffi.org>
parents: 419
diff changeset
808 return await node.setConfiguration(options)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
809
331
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
810 def getAffiliations(self, entity, nodeIdentifier, pep, recipient):
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
811 return self.storage.getAffiliations(entity, nodeIdentifier, pep, recipient)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
812
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
813 def getAffiliationsOwner(self, nodeIdentifier, requestor, pep, recipient):
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
814 d = self.storage.getNode(nodeIdentifier, pep, recipient)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
815 d.addCallback(_getAffiliation, requestor)
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
816 d.addCallback(self._doGetAffiliationsOwner, requestor)
331
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
817 return d
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
818
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
819 def _doGetAffiliationsOwner(self, result, requestor):
331
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
820 node, affiliation = result
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
821
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
822 if affiliation != 'owner' and not self.isAdmin(requestor):
331
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
823 raise error.Forbidden()
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
824 return node.getAffiliations()
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
825
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
826 def setAffiliationsOwner(self, nodeIdentifier, requestor, affiliations, pep, recipient):
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
827 d = self.storage.getNode(nodeIdentifier, pep, recipient)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
828 d.addCallback(_getAffiliation, requestor)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
829 d.addCallback(self._doSetAffiliationsOwner, requestor, affiliations)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
830 return d
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
831
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
832 def _doSetAffiliationsOwner(self, result, requestor, affiliations):
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
833 # Check that requestor is allowed to set affiliations, and delete entities
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
834 # with "none" affiliation
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
835
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
836 # TODO: return error with failed affiliations in case of failure
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
837 node, requestor_affiliation = result
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
838
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
839 if requestor_affiliation != 'owner' and not self.isAdmin(requestor):
331
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
840 raise error.Forbidden()
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
841
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
842 # we don't allow requestor to change its own affiliation
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
843 requestor_bare = requestor.userhostJID()
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
844 if requestor_bare in affiliations and affiliations[requestor_bare] != 'owner':
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
845 # FIXME: it may be interesting to allow the owner to ask for ownership removal
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
846 # if at least one other entity is owner for this node
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
847 raise error.Forbidden("You can't change your own affiliation")
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
848
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
849 to_delete = [jid_ for jid_, affiliation in affiliations.items() if affiliation == 'none']
331
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
850 for jid_ in to_delete:
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
851 del affiliations[jid_]
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
852
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
853 if to_delete:
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
854 d = node.deleteAffiliations(to_delete)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
855 if affiliations:
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
856 d.addCallback(lambda dummy: node.setAffiliations(affiliations))
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
857 else:
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
858 d = node.setAffiliations(affiliations)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
859
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
860 return d
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
861
341
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
862 def getSubscriptionsOwner(self, nodeIdentifier, requestor, pep, recipient):
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
863 d = self.storage.getNode(nodeIdentifier, pep, recipient)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
864 d.addCallback(_getAffiliation, requestor)
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
865 d.addCallback(self._doGetSubscriptionsOwner, requestor)
341
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
866 return d
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
867
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
868 def _doGetSubscriptionsOwner(self, result, requestor):
341
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
869 node, affiliation = result
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
870
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
871 if affiliation != 'owner' and not self.isAdmin(requestor):
341
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
872 raise error.Forbidden()
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
873 return node.getSubscriptions()
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
874
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
875 def setSubscriptionsOwner(self, nodeIdentifier, requestor, subscriptions, pep, recipient):
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
876 d = self.storage.getNode(nodeIdentifier, pep, recipient)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
877 d.addCallback(_getAffiliation, requestor)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
878 d.addCallback(self._doSetSubscriptionsOwner, requestor, subscriptions)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
879 return d
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
880
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
881 def unwrapFirstError(self, failure):
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
882 failure.trap(defer.FirstError)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
883 return failure.value.subFailure
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
884
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
885 def _doSetSubscriptionsOwner(self, result, requestor, subscriptions):
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
886 # Check that requestor is allowed to set subscriptions, and delete entities
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
887 # with "none" subscription
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
888
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
889 # TODO: return error with failed subscriptions in case of failure
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
890 node, requestor_affiliation = result
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
891
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
892 if requestor_affiliation != 'owner' and not self.isAdmin(requestor):
341
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
893 raise error.Forbidden()
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
894
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
895 d_list = []
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
896
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
897 for subscription in subscriptions.copy():
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
898 if subscription.state == 'none':
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
899 subscriptions.remove(subscription)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
900 d_list.append(node.removeSubscription(subscription.subscriber))
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
901
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
902 if subscriptions:
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
903 d_list.append(node.setSubscriptions(subscriptions))
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
904
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
905 d = defer.gatherResults(d_list, consumeErrors=True)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
906 d.addCallback(lambda _: None)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
907 d.addErrback(self.unwrapFirstError)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
908 return d
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
909
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
910 def filterItemsWithSchema(self, items_data, schema, owner):
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
911 """Check schema restriction and remove fields/items if they don't comply
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
912
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
913 @param items_data(list[ItemData]): items to filter
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
914 items in this list will be modified
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
915 @param schema(domish.Element): node schema
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
916 @param owner(bool): True is requestor is a owner of the node
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
917 """
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
918 fields_to_remove = set()
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
919 for field_elt in schema.elements(data_form.NS_X_DATA, 'field'):
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
920 for restrict_elt in field_elt.elements(const.NS_SCHEMA_RESTRICT, 'restrict'):
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
921 read_restriction = restrict_elt.attributes.get('read')
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
922 if read_restriction is not None:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
923 if read_restriction == 'owner':
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
924 if not owner:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
925 fields_to_remove.add(field_elt['var'])
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
926 else:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
927 raise StanzaError('feature-not-implemented', text='unknown read restriction {}'.format(read_restriction))
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
928 items_to_remove = []
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
929 for idx, item_data in enumerate(items_data):
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
930 item_elt = item_data.item
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
931 try:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
932 x_elt = next(item_elt.elements(data_form.NS_X_DATA, 'x'))
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
933 except StopIteration:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
934 log.msg("WARNING, item {id} has a schema but no form, ignoring it")
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
935 items_to_remove.append(item_data)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
936 continue
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
937 form = data_form.Form.fromElement(x_elt)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
938 # we remove fields which are not visible for this user
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
939 for field in fields_to_remove:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
940 try:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
941 form.removeField(form.fields[field])
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
942 except KeyError:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
943 continue
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
944 item_elt.children.remove(x_elt)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
945 item_elt.addChild(form.toElement())
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
946
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
947 for item_data in items_to_remove:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
948 items_data.remove(item_data)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
949
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
950 def checkPresenceSubscription(self, node, requestor):
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
951 """check if requestor has presence subscription from node owner
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
952
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
953 @param node(Node): node to check
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
954 @param requestor(jid.JID): entity who want to access node
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
955 """
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
956 def gotRoster(roster):
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
957 if roster is None:
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
958 raise error.Forbidden()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
959
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
960 if requestor not in roster:
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
961 raise error.Forbidden()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
962
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
963 if not roster[requestor].subscriptionFrom:
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
964 raise error.Forbidden()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
965
467
d86e0f8a1405 privilege: store roster cache in database:
Goffi <goffi@goffi.org>
parents: 464
diff changeset
966 d = defer.ensureDeferred(self.getOwnerRoster(node))
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
967 d.addCallback(gotRoster)
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
968 return d
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
969
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
970 @defer.inlineCallbacks
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
971 def checkRosterGroups(self, node, requestor):
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
972 """check if requestor is in allowed groups of a node
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
973
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
974 @param node(Node): node to check
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
975 @param requestor(jid.JID): entity who want to access node
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
976 """
467
d86e0f8a1405 privilege: store roster cache in database:
Goffi <goffi@goffi.org>
parents: 464
diff changeset
977 roster = yield defer.ensureDeferred(self.getOwnerRoster(node))
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
978
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
979 if roster is None:
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
980 raise error.Forbidden()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
981
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
982 if requestor not in roster:
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
983 raise error.Forbidden()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
984
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
985 authorized_groups = yield node.getAuthorizedGroups()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
986
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
987 if not roster[requestor].groups.intersection(authorized_groups):
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
988 # requestor is in roster but not in one of the allowed groups
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
989 raise error.Forbidden()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
990
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
991 def checkNodeAffiliations(self, node, requestor):
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
992 """check if requestor is in white list of a node
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
993
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
994 @param node(Node): node to check
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
995 @param requestor(jid.JID): entity who want to access node
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
996 """
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
997 def gotAffiliations(affiliations):
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
998 try:
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
999 affiliation = affiliations[requestor.userhostJID()]
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1000 except KeyError:
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1001 raise error.Forbidden()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1002 else:
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1003 if affiliation not in ('owner', 'publisher', 'member'):
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1004 raise error.Forbidden()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1005
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1006 d = node.getAffiliations()
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1007 d.addCallback(gotAffiliations)
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1008 return d
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1009
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1010 @defer.inlineCallbacks
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1011 def checkNodeAccess(self, node, requestor):
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1012 """check if a requestor can access data of a node
341
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
1013
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1014 @param node(Node): node to check
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1015 @param requestor(jid.JID): entity who want to access node
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1016 @return (tuple): permissions data with:
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1017 - owner(bool): True if requestor is owner of the node
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1018 - roster(None, ): roster of the requestor
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1019 None if not needed/available
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1020 - access_model(str): access model of the node
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1021 @raise error.Forbidden: access is not granted
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1022 @raise error.NotLeafNodeError: this node is not a leaf
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1023 """
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1024 node, affiliation = yield _getAffiliation(node, requestor)
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1025
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1026 if not iidavoll.ILeafNode.providedBy(node):
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1027 raise error.NotLeafNodeError()
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1028
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1029 if affiliation == 'outcast':
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1030 raise error.Forbidden()
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1031
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1032 # node access check
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1033 owner = affiliation == 'owner'
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1034 access_model = node.getAccessModel()
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1035 roster = None
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1036
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1037 if access_model == const.VAL_AMODEL_OPEN or owner:
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1038 pass
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1039 elif access_model == const.VAL_AMODEL_PRESENCE:
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1040 yield self.checkPresenceSubscription(node, requestor)
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1041 elif access_model == const.VAL_AMODEL_PUBLISHER_ROSTER:
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1042 # FIXME: for node, access should be renamed owner-roster, not publisher
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1043 yield self.checkRosterGroups(node, requestor)
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1044 elif access_model == const.VAL_AMODEL_WHITELIST:
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1045 yield self.checkNodeAffiliations(node, requestor)
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1046 else:
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
1047 raise Exception("Unknown access_model")
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1048
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1049 defer.returnValue((affiliation, owner, roster, access_model))
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1050
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1051 async def getItemsIds(
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1052 self,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1053 nodeIdentifier: str,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1054 requestor: jid.JID,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1055 authorized_groups: Optional[List[str]],
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1056 unrestricted: bool,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1057 maxItems: Optional[int] = None,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1058 ext_data: Optional[dict] = None,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1059 pep: bool = False,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1060 recipient: Optional[jid.JID] = None
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1061 ) -> List[str]:
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1062 """Retrieve IDs of items from a nodeIdentifier
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1063
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1064 Requestor permission is checked before retrieving items IDs
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1065 """
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1066 # FIXME: items access model are not checked
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1067 # TODO: check items access model
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1068 node = await self.storage.getNode(nodeIdentifier, pep, recipient)
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1069 await self.checkNodeAccess(node, requestor)
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1070 ids = await node.getItemsIds(
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1071 authorized_groups,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1072 unrestricted,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1073 maxItems,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1074 ext_data
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1075 )
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1076 return ids
346
3bbab2173ebc implemented disco items:
Goffi <goffi@goffi.org>
parents: 343
diff changeset
1077
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1078 async def getItems(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1079 self,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1080 nodeIdentifier: str,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1081 requestor: jid.JID,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1082 recipient: jid.JID,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1083 maxItems: Optional[int] = None,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1084 itemIdentifiers: Optional[List[str]] = None,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1085 ext_data: Optional[dict] = None
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1086 ) -> Tuple[List[domish.Element], Optional[rsm.RSMResponse]]:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1087 items_data, rsm_response = await self.getItemsData(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1088 nodeIdentifier, requestor, recipient, maxItems, itemIdentifiers, ext_data
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1089 )
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1090 return [item_data.item for item_data in items_data], rsm_response
320
29c2553ef863 added getItemsData to get list of ItemData instead of only the list of domish.Element
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1091
467
d86e0f8a1405 privilege: store roster cache in database:
Goffi <goffi@goffi.org>
parents: 464
diff changeset
1092 async def getOwnerRoster(self, node, owners=None):
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1093 # FIXME: roster of publisher, not owner, must be used
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1094 if owners is None:
467
d86e0f8a1405 privilege: store roster cache in database:
Goffi <goffi@goffi.org>
parents: 464
diff changeset
1095 owners = await node.getOwners()
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1096
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1097 if len(owners) != 1:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1098 log.msg('publisher-roster access is not allowed with more than 1 owner')
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1099 return
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1100
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1101 owner_jid = owners[0]
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1102
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1103 try:
467
d86e0f8a1405 privilege: store roster cache in database:
Goffi <goffi@goffi.org>
parents: 464
diff changeset
1104 roster = await self.privilege.getRoster(owner_jid)
471
ed9e12701e0f backend: return empty roster when `NotAllowedError` is raised in `getOwnerRoster`:
Goffi <goffi@goffi.org>
parents: 467
diff changeset
1105 except error.NotAllowedError:
ed9e12701e0f backend: return empty roster when `NotAllowedError` is raised in `getOwnerRoster`:
Goffi <goffi@goffi.org>
parents: 467
diff changeset
1106 return
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1107 except Exception as e:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1108 log.msg("Error while getting roster of {owner_jid}: {msg}".format(
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1109 owner_jid = owner_jid.full(),
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1110 msg = e))
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1111 return
467
d86e0f8a1405 privilege: store roster cache in database:
Goffi <goffi@goffi.org>
parents: 464
diff changeset
1112 return roster
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1113
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1114 async def getItemsData(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1115 self,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1116 nodeIdentifier: str,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1117 requestor: jid.JID,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1118 recipient: jid.JID,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1119 maxItems: Optional[int] = None,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1120 itemIdentifiers: Optional[List[str]] = None,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1121 ext_data: Optional[dict] = None
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1122 ) -> Tuple[List[container.ItemData], Optional[rsm.RSMResponse]]:
320
29c2553ef863 added getItemsData to get list of ItemData instead of only the list of domish.Element
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1123 """like getItems but return the whole ItemData"""
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1124 if maxItems == 0:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1125 log.msg("WARNING: maxItems=0 on items retrieval")
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1126 return [], None
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1127
278
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
1128 if ext_data is None:
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
1129 ext_data = {}
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1130
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1131 if nodeIdentifier == const.NS_PPS_SUBSCRIPTIONS:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1132 return await self.getPublicSubscriptions(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1133 requestor, maxItems, itemIdentifiers, ext_data,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1134 ext_data.pop("pep", False), recipient
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1135 )
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1136 elif nodeIdentifier.startswith(f"{const.NS_PPS_SUBSCRIBERS}/"):
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1137 target_node = nodeIdentifier[len(const.NS_PPS_SUBSCRIBERS)+1:]
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1138 return await self.getPublicNodeSubscriptions(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1139 target_node, requestor, maxItems, itemIdentifiers, ext_data,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1140 ext_data.pop("pep", False), recipient
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1141 )
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1142
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1143 node = await self.storage.getNode(nodeIdentifier, ext_data.get('pep', False), recipient)
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1144 try:
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1145 affiliation, owner, roster, access_model = await self.checkNodeAccess(node, requestor)
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1146 except error.NotLeafNodeError:
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1147 return [], None
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1148
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1149 # at this point node access is checked
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
1150
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1151 if owner:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1152 # requestor_groups is only used in restricted access
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1153 requestor_groups = None
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1154 else:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1155 if roster is None:
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1156 # FIXME: publisher roster should be used, not owner
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1157 roster = await self.getOwnerRoster(node)
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1158 if roster is None:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1159 roster = {}
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1160 roster_item = roster.get(requestor.userhostJID())
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1161 requestor_groups = tuple(roster_item.groups) if roster_item else tuple()
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
1162
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1163 if itemIdentifiers:
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1164 items_data = await node.getItemsById(requestor_groups, owner, itemIdentifiers)
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1165 else:
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1166 items_data = await node.getItems(requestor_groups, owner, maxItems, ext_data)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1167
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1168 if owner:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1169 # Add item config data form to items with roster access model
302
b8b25efae0bc fixed item_data issues after introduction of ItemData namedtuple
Goffi <goffi@goffi.org>
parents: 301
diff changeset
1170 for item_data in items_data:
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1171 if item_data.access_model == const.VAL_AMODEL_OPEN:
252
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
1172 pass
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1173 elif item_data.access_model == const.VAL_AMODEL_PUBLISHER_ROSTER:
252
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
1174 form = data_form.Form('submit', formNamespace=const.NS_ITEM_CONFIG)
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1175 access = data_form.Field(None, const.OPT_ACCESS_MODEL, value=const.VAL_AMODEL_PUBLISHER_ROSTER)
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1176 allowed = data_form.Field(None, const.OPT_ROSTER_GROUPS_ALLOWED, values=item_data.config[const.OPT_ROSTER_GROUPS_ALLOWED])
252
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
1177 form.addField(access)
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
1178 form.addField(allowed)
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1179 item_data.item.addChild(form.toElement())
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1180 elif access_model == const.VAL_AMODEL_WHITELIST:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1181 #FIXME
252
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
1182 raise NotImplementedError
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
1183 else:
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
1184 raise error.BadAccessTypeError(access_model)
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
1185
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1186 schema = node.getSchema()
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1187 if schema is not None:
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1188 self.filterItemsWithSchema(items_data, schema, owner)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1189
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1190 return await self._items_rsm(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1191 items_data, node, requestor_groups, owner, itemIdentifiers, ext_data
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1192 )
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1193
315
720d73e30bf7 backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents: 314
diff changeset
1194 def _setCount(self, value, response):
720d73e30bf7 backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents: 314
diff changeset
1195 response.count = value
720d73e30bf7 backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents: 314
diff changeset
1196
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1197 def _setIndex(self, value, response, adjust):
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1198 """Set index in RSM response
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1199
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1200 @param value(int): value of the reference index (i.e. before or after item)
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1201 @param response(RSMResponse): response instance to fill
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1202 @param adjust(int): adjustement term (i.e. difference between reference index and first item of the result)
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1203 """
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1204 response.index = value + adjust
315
720d73e30bf7 backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents: 314
diff changeset
1205
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1206 async def _items_rsm(self, items_data, node, authorized_groups, owner,
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1207 itemIdentifiers, ext_data):
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1208 # FIXME: move this to a separate module
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1209 # TODO: Index can be optimized by keeping a cache of the last RSM request
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1210 # An other optimisation would be to look for index first and use it as offset
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1211 try:
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1212 rsm_request = ext_data['rsm']
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1213 except KeyError:
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1214 # No RSM in this request, nothing to do
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1215 return items_data, None
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1216
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1217 if itemIdentifiers:
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1218 log.msg("WARNING, itemIdentifiers used with RSM, ignoring the RSM part")
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1219 return items_data, None
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1220
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1221 rsm_response = rsm.RSMResponse()
278
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
1222
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1223 d_count = node.getItemsCount(authorized_groups, owner, ext_data)
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1224 d_count.addCallback(self._setCount, rsm_response)
278
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
1225 d_list = [d_count]
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
1226
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1227 if items_data:
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1228 rsm_response.first = items_data[0].item['id']
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1229 rsm_response.last = items_data[-1].item['id']
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1230
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1231 # index handling
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1232 if rsm_request.index is not None:
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1233 rsm_response.index = rsm_request.index
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1234 elif rsm_request.before:
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1235 # The last page case (before == '') is managed in render method
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1236 d_index = node.getItemsIndex(rsm_request.before, authorized_groups, owner, ext_data)
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1237 d_index.addCallback(self._setIndex, rsm_response, -len(items_data))
278
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
1238 d_list.append(d_index)
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1239 elif rsm_request.after is not None:
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1240 d_index = node.getItemsIndex(rsm_request.after, authorized_groups, owner, ext_data)
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1241 d_index.addCallback(self._setIndex, rsm_response, 1)
318
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1242 d_list.append(d_index)
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1243 else:
d13526c0eb32 RSM improvments/refactoring:
Goffi <goffi@goffi.org>
parents: 317
diff changeset
1244 # the first page was requested
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1245 rsm_response.index = 0
278
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
1246
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1247
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1248 await defer.DeferredList(d_list)
278
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
1249
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1250 if rsm_request.before == '':
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1251 # the last page was requested
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1252 rsm_response.index = rsm_response.count - len(items_data)
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1253
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1254 return items_data, rsm_response
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1255
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1256 def addEltFromSubDict(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1257 self,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1258 parent_elt: domish.Element,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1259 from_jid: Optional[jid.JID],
481
0e801ae1869f backend: use `typing.Dict[]` instead of `dict[]` to be compatible with Python 3.7
Goffi <goffi@goffi.org>
parents: 478
diff changeset
1260 sub_dict: Dict[str, str],
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1261 namespace: Optional[str] = None,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1262 ) -> None:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1263 """Generate <subscription> element from storage.getAllSubscriptions's dict
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1264
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1265 @param parent_elt: element where the new subscription element must be added
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1266 @param sub_dict: subscription data as returned by storage.getAllSubscriptions
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1267 @param namespace: if not None, namespace to use for <subscription> element
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1268 @param service_attribute: name of the attribute to use for the subscribed service
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1269 """
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1270 subscription_elt = parent_elt.addElement(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1271 "subscription" if namespace is None else (namespace, "subscription")
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1272 )
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1273 if from_jid is not None:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1274 subscription_elt["jid"] = from_jid.userhost()
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1275 if sub_dict["node"] is not None:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1276 if sub_dict["pep"] is not None:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1277 subscription_elt["service"] = sub_dict["pep"]
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1278 else:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1279 subscription_elt["service"] = self.jid.full()
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1280 subscription_elt["node"] = sub_dict["node"]
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1281 else:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1282 subscription_elt["service"] = sub_dict["ext_service"]
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1283 subscription_elt["node"] = sub_dict["ext_node"]
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1284 subscription_elt["subscription"] = sub_dict["state"]
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1285
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1286 async def getPublicSubscriptions(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1287 self,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1288 requestor: jid.JID,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1289 maxItems: Optional[int],
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1290 itemIdentifiers: Optional[List[str]],
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1291 ext_data: dict,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1292 pep: bool,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1293 recipient: jid.JID
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1294 ) -> Tuple[List[container.ItemData], Optional[rsm.RSMResponse]]:
278
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
1295
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1296 if itemIdentifiers or ext_data.get("rsm") or ext_data.get("mam"):
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1297 raise NotImplementedError(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1298 "item identifiers, RSM and MAM are not implemented yet"
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1299 )
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1300
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1301 if not pep:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1302 return [], None
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1303
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1304 subs = await self.storage.getAllSubscriptions(recipient, True)
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1305 items_data = []
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1306 for sub in subs:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1307 if sub["state"] != "subscribed":
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1308 continue
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1309 item = domish.Element((pubsub.NS_PUBSUB, "item"))
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1310 item["id"] = sub["id"]
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1311 self.addEltFromSubDict(item, None, sub, const.NS_PPS)
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1312 items_data.append(container.ItemData(item))
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1313
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1314 return items_data, None
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1315
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1316 async def getPublicNodeSubscriptions(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1317 self,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1318 nodeIdentifier: str,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1319 requestor: jid.JID,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1320 maxItems: Optional[int],
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1321 itemIdentifiers: Optional[List[str]],
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1322 ext_data: dict,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1323 pep: bool,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1324 recipient: jid.JID
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1325 ) -> Tuple[List[container.ItemData], Optional[rsm.RSMResponse]]:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1326
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1327 if itemIdentifiers or ext_data.get("rsm") or ext_data.get("mam"):
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1328 raise NotImplementedError(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1329 "item identifiers, RSM and MAM are not implemented yet"
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1330 )
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1331
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1332 node = await self.storage.getNode(nodeIdentifier, pep, recipient)
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1333
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1334 subs = await node.getSubscriptions(public=True)
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1335 items_data = []
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1336 for sub in subs:
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1337 item = domish.Element((pubsub.NS_PUBSUB, "item"))
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1338 item["id"] = sub.id
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1339 subscriber_elt = item.addElement((const.NS_PPS, "subscriber"))
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1340 subscriber_elt["jid"] = sub.subscriber.full()
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1341 items_data.append(container.ItemData(item))
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1342
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1343 return items_data, None
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1344
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1345 async def retractItem(self, nodeIdentifier, itemIdentifiers, requestor, notify, pep, recipient):
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1346 node = await self.storage.getNode(nodeIdentifier, pep, recipient)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1347 node, affiliation = await _getAffiliation(node, requestor)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1348
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1349 persistItems = node.getConfiguration()[const.OPT_PERSIST_ITEMS]
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1350
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1351 if not persistItems:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1352 raise error.NodeNotPersistent()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1353
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1354 # we need to get the items before removing them, for the notifications
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1355
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1356 if affiliation not in ['owner', 'publisher']:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1357 # the requestor doesn't have right to retract on the whole node
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1358 # we check if he is a publisher for all items he wants to retract
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1359 # and forbid the retraction else.
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1360 publishers_map = await node.getItemsPublishers(itemIdentifiers)
309
890b24b37b56 Re-implemented feature which allows an entity to retract an item from somebody else node (i.e. a node from which he is neither owner or publisher) if he is the publisher of the item.
Goffi <goffi@goffi.org>
parents: 308
diff changeset
1361 # TODO: the behaviour should be configurable (per node ?)
388
1c13ba86a421 backend: allow admins to retract any item
Goffi <goffi@goffi.org>
parents: 387
diff changeset
1362 if (any((requestor.userhostJID() != publisher.userhostJID()
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
1363 for publisher in publishers_map.values()))
388
1c13ba86a421 backend: allow admins to retract any item
Goffi <goffi@goffi.org>
parents: 387
diff changeset
1364 and not self.isAdmin(requestor)
1c13ba86a421 backend: allow admins to retract any item
Goffi <goffi@goffi.org>
parents: 387
diff changeset
1365 ):
309
890b24b37b56 Re-implemented feature which allows an entity to retract an item from somebody else node (i.e. a node from which he is neither owner or publisher) if he is the publisher of the item.
Goffi <goffi@goffi.org>
parents: 308
diff changeset
1366 raise error.Forbidden()
890b24b37b56 Re-implemented feature which allows an entity to retract an item from somebody else node (i.e. a node from which he is neither owner or publisher) if he is the publisher of the item.
Goffi <goffi@goffi.org>
parents: 308
diff changeset
1367
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1368 items_data = await node.getItemsById(None, True, itemIdentifiers)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1369 # Remove the items and keep only actually removed ones in items_data
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1370 removed = await node.removeItems(itemIdentifiers)
437
454f61a32427 backend: fixed item retractation notification
Goffi <goffi@goffi.org>
parents: 431
diff changeset
1371 retracted_items_data = [
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1372 item_data for item_data in items_data if item_data.item["id"] in removed
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1373 ]
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1374 if nodeIdentifier.startswith(const.FDP_TEMPLATE_PREFIX):
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1375 app_ns = nodeIdentifier[len(const.FDP_TEMPLATE_PREFIX):]
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1376 submitted_node_id = f"{const.FDP_SUBMITTED_PREFIX}{app_ns}"
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1377 submitted_node = await self.storage.getNode(submitted_node_id, pep, recipient)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1378 schema_items = await node.getItems([], True, maxItems=1)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1379 if not schema_items:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1380 # no more schema, we need to remove it from submitted node
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1381 submitted_node = await self._getFDPSubmittedNode(
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1382 nodeIdentifier, pep, recipient)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1383 if submitted_node is not None:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1384 submitted_node.setSchema(None)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1385 else:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1386 # not all items have been removed from the FDP template node, we check
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1387 # if the last one correspond to current submitted node schema, and if not,
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1388 # we update it.
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1389 current_schema = next(schema_items[0].item.elements(
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1390 data_form.NS_X_DATA, 'x'))
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1391 if current_schema == node.schema:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1392 submitted_node = await self._getFDPSubmittedNode(
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1393 nodeIdentifier, pep, recipient)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1394 if submitted_node is not None:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1395 submitted_node.setSchema(current_schema)
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1396
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1397 if notify:
437
454f61a32427 backend: fixed item retractation notification
Goffi <goffi@goffi.org>
parents: 431
diff changeset
1398 self._doNotifyRetraction(retracted_items_data, node, pep, recipient)
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1399
437
454f61a32427 backend: fixed item retractation notification
Goffi <goffi@goffi.org>
parents: 431
diff changeset
1400 return [r.item for r in retracted_items_data]
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1401
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1402 def _doNotifyRetraction(self, items_data, node, pep, recipient):
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1403 self.dispatch({'items_data': items_data,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1404 'node': node,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1405 'pep': pep,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1406 'recipient': recipient},
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1407 '//event/pubsub/retract')
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1408
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1409 async def purgeNode(self, nodeIdentifier, requestor, pep, recipient):
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1410 node = await self.storage.getNode(nodeIdentifier, pep, recipient)
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1411 node, affiliation = await _getAffiliation(node, requestor)
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1412 persistItems = node.getConfiguration()[const.OPT_PERSIST_ITEMS]
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1413
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
1414 if affiliation != 'owner' and not self.isAdmin(requestor):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1415 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1416
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1417 if not persistItems:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1418 raise error.NodeNotPersistent()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1419
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1420 await node.purge()
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1421
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1422 subscribers = await self.getSubscribers(nodeIdentifier, pep, recipient)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1423
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1424 # now we can send notifications
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1425 self.dispatch(
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1426 {
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1427 'node': node,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1428 'pep': pep,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1429 'recipient': recipient,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1430 'subscribers': subscribers,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1431 },
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1432 '//event/pubsub/purge'
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1433 )
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1434
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1435 def getSubscribers(self, nodeIdentifier, pep, recipient):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1436 def cb(subscriptions):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1437 return [subscription.subscriber for subscription in subscriptions]
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1438
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1439 d = self.storage.getNode(nodeIdentifier, pep, recipient)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1440 d.addCallback(lambda node: node.getSubscriptions('subscribed'))
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1441 d.addCallback(cb)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1442 return d
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1443
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1444 async def deleteNode(
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1445 self,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1446 nodeIdentifier: str,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1447 requestor: jid.JID,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1448 pep: bool,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1449 recipient: jid.JID,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1450 redirectURI: str = None
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1451 ) -> None:
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1452 node = await self.storage.getNode(nodeIdentifier, pep, recipient)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1453 node, affiliation = await _getAffiliation(node, requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1454
387
04e7dcc436ca backend: admins can delete node, change schema, change config or delete items even if they are not owner of a node
Goffi <goffi@goffi.org>
parents: 384
diff changeset
1455 if affiliation != 'owner' and not self.isAdmin(requestor):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1456 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1457
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1458 # we have to get subscribers (for notifications) before the node is deleted
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1459 subscribers = await self.getSubscribers(nodeIdentifier, pep, recipient)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1460
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1461 await self.storage.deleteNodeByDbId(node.nodeDbId)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1462
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1463 if node.nodeIdentifier.startswith(const.FDP_TEMPLATE_PREFIX):
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1464 # we need to delete the associated schema
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1465 submitted_node = await self._getFDPSubmittedNode(
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1466 node.nodeIdentifier, pep, recipient)
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1467 if submitted_node is not None:
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
1468 await submitted_node.setSchema(None)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1469
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1470 # now we can send notifications
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1471 self.dispatch(
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1472 {
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1473 'node': node,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1474 'pep': pep,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1475 'recipient': recipient,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1476 'redirectURI': redirectURI,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1477 'subscribers': subscribers,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1478 },
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1479 '//event/pubsub/delete'
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1480 )
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1481
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1482
317
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
1483 class PubSubResourceFromBackend(pubsub.PubSubResource):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1484 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1485 Adapts a backend to an xmpp publish-subscribe service.
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1486 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1487
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1488 features = [
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1489 "config-node",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1490 "create-nodes",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1491 "delete-any",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1492 "delete-nodes",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1493 "item-ids",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1494 "meta-data",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1495 "publish",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1496 "purge-nodes",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1497 "retract-items",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1498 "retrieve-affiliations",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1499 "retrieve-default",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1500 "retrieve-items",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1501 "retrieve-subscriptions",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1502 "subscribe",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1503 ]
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1504
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1505 discoIdentity = disco.DiscoIdentity('pubsub',
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1506 'service',
453
1a179ad10125 backend: service name can now be specified with `service_name` parameter
Goffi <goffi@goffi.org>
parents: 452
diff changeset
1507 const.SERVICE_NAME)
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1508
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1509 pubsubService = None
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1510
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1511 _errorMap = {
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1512 error.NodeNotFound: ('item-not-found', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1513 error.NodeExists: ('conflict', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1514 error.Forbidden: ('forbidden', None, None),
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
1515 error.NotAuthorized: ('not-authorized', None, None),
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1516 error.ItemNotFound: ('item-not-found', None, None),
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1517 error.ItemForbidden: ('bad-request', 'item-forbidden', None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1518 error.ItemRequired: ('bad-request', 'item-required', None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1519 error.NoInstantNodes: ('not-acceptable',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1520 'unsupported',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1521 'instant-nodes'),
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
1522 error.NotSubscribed: ('unexpected-request', 'not-subscribed', None),
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1523 error.InvalidConfigurationOption: ('not-acceptable', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1524 error.InvalidConfigurationValue: ('not-acceptable', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1525 error.NodeNotPersistent: ('feature-not-implemented',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1526 'unsupported',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1527 'persistent-node'),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1528 error.NoRootNode: ('bad-request', None, None),
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1529 error.NoCollections: ('feature-not-implemented',
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1530 'unsupported',
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1531 'collections'),
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1532 error.NoPublishing: ('feature-not-implemented',
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1533 'unsupported',
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1534 'publish'),
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1535 error.ConstraintFailed: ('conflict', 'precondition-not-met', None),
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1536 }
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1537
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1538 def __init__(self, backend):
317
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
1539 pubsub.PubSubResource.__init__(self)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1540
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1541 self.backend = backend
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1542 self.hideNodes = False
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
1543
453
1a179ad10125 backend: service name can now be specified with `service_name` parameter
Goffi <goffi@goffi.org>
parents: 452
diff changeset
1544 self.__class__.discoIdentity.name = backend.config["service_name"]
1a179ad10125 backend: service name can now be specified with `service_name` parameter
Goffi <goffi@goffi.org>
parents: 452
diff changeset
1545
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1546 self.backend.registerPublishNotifier(self._notifyPublish)
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1547 self.backend.registerRetractNotifier(self._notifyRetract)
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1548 self.backend.registerDeleteNotifier(self._notifyDelete)
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1549 self.backend.registerPurgeNotifier(self._notifyPurge)
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
1550
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
1551 if self.backend.supportsAutoCreate():
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
1552 self.features.append("auto-create")
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
1553
363
a98b3d52c2ff added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents: 358
diff changeset
1554 if self.backend.supportsPublishOptions():
a98b3d52c2ff added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents: 358
diff changeset
1555 self.features.append("publish-options")
a98b3d52c2ff added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents: 358
diff changeset
1556
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1557 if self.backend.supportsInstantNodes():
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1558 self.features.append("instant-nodes")
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1559
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1560 if self.backend.supportsOutcastAffiliation():
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1561 self.features.append("outcast-affiliation")
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1562
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1563 if self.backend.supportsPersistentItems():
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1564 self.features.append("persistent-items")
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1565
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1566 if self.backend.supportsPublisherAffiliation():
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1567 self.features.append("publisher-affiliation")
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1568
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
1569 if self.backend.supportsGroupBlog():
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
1570 self.features.append("groupblog")
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
1571
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1572 # XXX: this feature is not really described in XEP-0060, we just can see it in
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1573 # examples but it's necessary for microblogging comments (see XEP-0277)
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1574 if self.backend.supportsPublishModel():
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1575 self.features.append("publish_model")
260
f0cd02c032b3 publish model management
Goffi <goffi@goffi.org>
parents: 259
diff changeset
1576
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1577 def getFullItem(self, item_data):
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1578 """ Attach item configuration to this item
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1579
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1580 Used to give item configuration back to node's owner (and *only* to owner)
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1581 """
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1582 # TODO: a test should check that only the owner get the item configuration back
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1583
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1584 item, item_config = item_data.item, item_data.config
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1585 if item_config:
394
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
1586 new_item = elementCopy(item)
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1587 new_item.addChild(item_config.toElement())
394
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
1588 return new_item
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
1589 else:
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
1590 return item
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1591
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1592 def _notifyPublish(self, data: dict) -> defer.Deferred:
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1593 return defer.ensureDeferred(self.notifyPublish(data))
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1594
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1595 async def notifyPublish(self, data: dict) -> None:
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1596 items_data = data['items_data']
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
1597 node = data['node']
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1598 pep = data['pep']
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1599 recipient = data['recipient']
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
1600
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1601 owners, notifications_filtered = await self._prepareNotify(
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1602 items_data, node, data.get('subscription'), pep, recipient
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1603 )
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
1604
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1605 # we notify the owners
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1606 # FIXME: check if this comply with XEP-0060 (option needed ?)
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1607 # TODO: item's access model have to be sent back to owner
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1608 # TODO: same thing for getItems
252
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
1609
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1610 for owner_jid in owners:
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1611 notifications_filtered.append(
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1612 (owner_jid,
364
8bd8be6815ab completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents: 363
diff changeset
1613 {pubsub.Subscription(node.nodeIdentifier,
8bd8be6815ab completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents: 363
diff changeset
1614 owner_jid,
8bd8be6815ab completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents: 363
diff changeset
1615 'subscribed')},
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1616 [self.getFullItem(item_data) for item_data in items_data]))
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1617
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1618 if pep:
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1619 self.backend.privilege.notifyPublish(
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1620 recipient,
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1621 node.nodeIdentifier,
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1622 notifications_filtered
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1623 )
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1624
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1625 else:
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1626 self.pubsubService.notifyPublish(
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1627 self.serviceJID,
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1628 node.nodeIdentifier,
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1629 notifications_filtered)
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1630
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1631 def _notifyRetract(self, data: dict) -> defer.Deferred:
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1632 return defer.ensureDeferred(self.notifyRetract(data))
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1633
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1634 async def notifyRetract(self, data: dict) -> None:
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1635 items_data = data['items_data']
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1636 node = data['node']
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1637 pep = data['pep']
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1638 recipient = data['recipient']
251
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
1639
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1640 owners, notifications_filtered = await self._prepareNotify(
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1641 items_data, node, data.get('subscription'), pep, recipient
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1642 )
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1643
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1644 #we add the owners
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1645
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1646 for owner_jid in owners:
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1647 notifications_filtered.append(
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1648 (owner_jid,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1649 {pubsub.Subscription(node.nodeIdentifier,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1650 owner_jid,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1651 'subscribed')},
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1652 [item_data.item for item_data in items_data]))
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1653
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1654 if pep:
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1655 return self.backend.privilege.notifyRetract(
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1656 recipient,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1657 node.nodeIdentifier,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1658 notifications_filtered)
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1659
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1660 else:
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1661 return self.pubsubService.notifyRetract(
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1662 self.serviceJID,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1663 node.nodeIdentifier,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1664 notifications_filtered)
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1665
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1666 async def _prepareNotify(
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1667 self,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1668 items_data: Tuple[domish.Element, str, dict],
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1669 node,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1670 subscription: Optional[pubsub.Subscription] = None,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1671 pep: bool = False,
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1672 recipient: Optional[jid.JID] = None
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1673 ) -> Tuple:
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1674 """Do a bunch of permissions check and filter notifications
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1675
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1676 The owner is not added to these notifications,
340
567e486bce24 backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents: 339
diff changeset
1677 it must be added by the calling method
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1678 @param items_data: must contain:
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1679 - item
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1680 - access_model
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1681 - access_list (dict as returned getItemsById, or item_config)
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1682 @param node(LeafNode): node hosting the items
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1683 @param subscription: TODO
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1684
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1685 @return: will contain:
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1686 - notifications_filtered
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1687 - node_owner_jid
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1688 - items_data
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1689 """
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1690 if subscription is None:
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1691 notifications = await self.backend.getNotifications(node, items_data)
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
1692 else:
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1693 notifications = [(subscription.subscriber, [subscription], items_data)]
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1694
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1695 if ((pep
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1696 and node.getConfiguration()[const.OPT_ACCESS_MODEL] in ('open', 'presence')
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1697 )):
343
ff8aff4c9b79 backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents: 341
diff changeset
1698 # for PEP we need to manage automatic subscriptions (cf. XEP-0163 §4)
ff8aff4c9b79 backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents: 341
diff changeset
1699 explicit_subscribers = {subscriber for subscriber, _, _ in notifications}
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1700 auto_subscribers = await self.backend.privilege.getAutoSubscribers(
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1701 recipient, node.nodeIdentifier, explicit_subscribers
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1702 )
343
ff8aff4c9b79 backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents: 341
diff changeset
1703 for sub_jid in auto_subscribers:
ff8aff4c9b79 backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents: 341
diff changeset
1704 sub = pubsub.Subscription(node.nodeIdentifier, sub_jid, 'subscribed')
ff8aff4c9b79 backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents: 341
diff changeset
1705 notifications.append((sub_jid, [sub], items_data))
ff8aff4c9b79 backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents: 341
diff changeset
1706
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1707 owners = await node.getOwners()
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1708 owner_roster = None
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1709
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1710 # now we check access of subscriber for each item, and keep only allowed ones
285
a87c155d0fd5 replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents: 283
diff changeset
1711
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1712 #we filter items not allowed for the subscribers
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1713 notifications_filtered = []
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1714 schema = node.getSchema()
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1715
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1716 for subscriber, subscriptions, items_data in notifications:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1717 subscriber_bare = subscriber.userhostJID()
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1718 if subscriber_bare in owners:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1719 # as notification is always sent to owner,
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1720 # we ignore owner if he is here
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1721 continue
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1722 allowed_items = [] #we keep only item which subscriber can access
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1723
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1724 if schema is not None:
394
dc83b1d837cf backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents: 392
diff changeset
1725 # we have to copy items_data because different subscribers may receive
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1726 # different items (e.g. read restriction in schema)
397
a4980d03b3a3 backend: fixed items data copy on notification
Goffi <goffi@goffi.org>
parents: 396
diff changeset
1727 items_data = [itemDataCopy(item_data) for item_data in items_data]
353
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1728 self.backend.filterItemsWithSchema(items_data, schema, False)
7c5d85c6fb3a backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1729
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1730 for item_data in items_data:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1731 item, access_model = item_data.item, item_data.access_model
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1732 access_list = item_data.config
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1733 if access_model == const.VAL_AMODEL_OPEN:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1734 allowed_items.append(item)
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1735 elif access_model == const.VAL_AMODEL_PUBLISHER_ROSTER:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1736 if owner_roster is None:
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1737 # FIXME: publisher roster should be used, not owner
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1738 owner_roster= await self.backend.getOwnerRoster(node, owners)
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1739 if owner_roster is None:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1740 owner_roster = {}
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1741 if not subscriber_bare in owner_roster:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1742 continue
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1743 #the subscriber is known, is he in the right group ?
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1744 authorized_groups = access_list[const.OPT_ROSTER_GROUPS_ALLOWED]
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1745 if owner_roster[subscriber_bare].groups.intersection(authorized_groups):
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1746 allowed_items.append(item)
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1747 else: #unknown access_model
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1748 # TODO: white list access
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1749 raise NotImplementedError
251
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
1750
330
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1751 if allowed_items:
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1752 notifications_filtered.append((subscriber, subscriptions, allowed_items))
82d1259b3e36 backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents: 320
diff changeset
1753
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1754 return (owners, notifications_filtered)
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
1755
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1756 async def _aNotifyDelete(self, data):
261
65d4fed44edf fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents: 260
diff changeset
1757 nodeIdentifier = data['node'].nodeIdentifier
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1758 pep = data['pep']
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1759 recipient = data['recipient']
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
1760 redirectURI = data.get('redirectURI', None)
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1761 subscribers = data['subscribers']
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1762 if pep:
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1763 self.backend.privilege.notifyDelete(
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1764 recipient,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1765 nodeIdentifier,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1766 subscribers,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1767 redirectURI
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1768 )
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1769 else:
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1770 self.pubsubService.notifyDelete(
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1771 self.serviceJID,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1772 nodeIdentifier,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1773 subscribers,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1774 redirectURI
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1775 )
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1776
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1777 def _notifyDelete(self, data):
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1778 d = defer.ensureDeferred(self._aNotifyDelete(data))
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1779 d.addErrback(log.err)
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1780
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1781 async def _aNotifyPurge(self, data):
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1782 nodeIdentifier = data['node'].nodeIdentifier
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1783 pep = data['pep']
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1784 recipient = data['recipient']
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1785 subscribers = data['subscribers']
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1786 if pep:
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1787 self.backend.privilege.notifyPurge(
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1788 recipient,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1789 nodeIdentifier,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1790 subscribers,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1791 )
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1792 else:
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1793 self.pubsubService.notifyPurge(
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1794 self.serviceJID,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1795 nodeIdentifier,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1796 subscribers,
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1797 )
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1798
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1799 def _notifyPurge(self, data):
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1800 d = defer.ensureDeferred(self._aNotifyPurge(data))
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
1801 d.addErrback(log.err)
174
79d451d186b1 Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
1802
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1803 def _mapErrors(self, failure):
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
1804 e = failure.trap(*list(self._errorMap.keys()))
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1805
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1806 condition, pubsubCondition, feature = self._errorMap[e]
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1807 msg = failure.value.msg
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1808
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1809 if pubsubCondition:
317
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
1810 exc = pubsub.PubSubError(condition, pubsubCondition, feature, msg)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1811 else:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1812 exc = StanzaError(condition, text=msg)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1813
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1814 raise exc
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1815
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1816 async def _getInfo(
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1817 self,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1818 requestor: jid.JID,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1819 service: jid.JID,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1820 nodeIdentifier: str,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1821 pep: bool = False,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1822 recipient: Optional[jid.JID] = None
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1823 ) -> Optional[dict]:
288
073161f6f143 namespace delegation: disco nesting management
Goffi <goffi@goffi.org>
parents: 285
diff changeset
1824 if not requestor.resource:
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1825 # this avoid error when getting a disco request from server during namespace
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1826 # delegation
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1827 return None
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1828 info = {}
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1829 try:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1830 info["type"] = await self.backend.getNodeType(nodeIdentifier, pep, recipient)
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1831 info["meta-data"] = await self.backend.getNodeMetaData(
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1832 nodeIdentifier, pep, recipient
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1833 )
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1834 except error.NodeNotFound:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1835 info["meta-data"] = None
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1836 return None
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1837 except failure.Failure as e:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1838 self._mapErrors(e)
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1839 except Exception as e:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1840 self._mapErrors(failure.Failure(e))
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1841 else:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1842 return info
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1843
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1844 def getInfo(self, requestor, service, nodeIdentifier):
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1845 try:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1846 pep = service.delegated
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1847 except AttributeError:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1848 pep = False
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1849 recipient = None
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1850 else:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1851 recipient = service if pep else None
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1852 return defer.ensureDeferred(
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1853 self._getInfo(
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1854 requestor, service, nodeIdentifier, pep, recipient
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1855 )
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1856 )
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1857
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1858 async def _getNodes(self, requestor, service, nodeIdentifier):
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1859 """return nodes for disco#items
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1860
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1861 Pubsub/PEP nodes will be returned if disco node is not specified
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1862 else Pubsub/PEP items will be returned
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1863 (according to what requestor can access)
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1864 """
346
3bbab2173ebc implemented disco items:
Goffi <goffi@goffi.org>
parents: 343
diff changeset
1865 try:
3bbab2173ebc implemented disco items:
Goffi <goffi@goffi.org>
parents: 343
diff changeset
1866 pep = service.pep
3bbab2173ebc implemented disco items:
Goffi <goffi@goffi.org>
parents: 343
diff changeset
1867 except AttributeError:
3bbab2173ebc implemented disco items:
Goffi <goffi@goffi.org>
parents: 343
diff changeset
1868 pep = False
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
1869
464
391aa65f72b2 backend: restored `--hide-nodes` effect
Goffi <goffi@goffi.org>
parents: 463
diff changeset
1870 if self.hideNodes or service.resource:
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1871 return []
346
3bbab2173ebc implemented disco items:
Goffi <goffi@goffi.org>
parents: 343
diff changeset
1872
3bbab2173ebc implemented disco items:
Goffi <goffi@goffi.org>
parents: 343
diff changeset
1873 if nodeIdentifier:
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1874 items = await self.backend.getItemsIds(
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1875 nodeIdentifier,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1876 requestor,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1877 [],
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1878 requestor.userhostJID() == service,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1879 None,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1880 None,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1881 pep,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1882 service
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1883 )
349
20b82fb8de02 backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents: 346
diff changeset
1884 # items must be set as name, not node
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1885 return [(None, item) for item in items]
346
3bbab2173ebc implemented disco items:
Goffi <goffi@goffi.org>
parents: 343
diff changeset
1886 else:
459
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1887 try:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1888 return await self.backend.getNodes(
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1889 requestor.userhostJID(),
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1890 pep,
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1891 service
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1892 )
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1893 except failure.Failure as e:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1894 self._mapErrors(e)
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1895 except Exception as e:
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1896 self._mapErrors(failure.Failure(e))
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1897
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1898 def getNodes(self, requestor, service, nodeIdentifier):
cebcb7f56889 backend, delegation: update to XEP-0355 v0.5 (namespace bump) + disco:
Goffi <goffi@goffi.org>
parents: 455
diff changeset
1899 return defer.ensureDeferred(self._getNodes(requestor, service, nodeIdentifier))
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1900
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
1901 def getConfigurationOptions(self):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
1902 return self.backend.nodeOptions
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
1903
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
1904 def _publish_errb(self, failure, request):
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
1905 if failure.type == error.NodeNotFound and self.backend.supportsAutoCreate():
463
f520ac3164b0 privilege: improvment on last message sending on presence with `+notify`:
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1906 print(f"Auto-creating node {request.nodeIdentifier}")
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
1907 d = self.backend.createNode(request.nodeIdentifier,
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1908 request.sender,
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1909 request.options,
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1910 pep=self._isPep(request),
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1911 recipient=request.recipient)
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1912 d.addCallback(
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1913 lambda __, request: defer.ensureDeferred(self.backend.publish(
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1914 request.nodeIdentifier,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1915 request.items,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1916 request.sender,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1917 request.options,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1918 self._isPep(request),
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1919 request.recipient,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1920 )),
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1921 request,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1922 )
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
1923 return d
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
1924
240
70c8bb90d75f added access_model to config, default to 'open'
Goffi <goffi@goffi.org>
parents: 237
diff changeset
1925 return failure
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
1926
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1927 def _isPep(self, request):
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1928 try:
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1929 return request.delegated
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1930 except AttributeError:
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1931 return False
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1932
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1933 def publish(self, request):
419
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1934 d = defer.ensureDeferred(self.backend.publish(
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1935 request.nodeIdentifier,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1936 request.items,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1937 request.sender,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1938 request.options,
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1939 self._isPep(request),
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1940 request.recipient
794593086517 backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents: 415
diff changeset
1941 ))
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
1942 d.addErrback(self._publish_errb, request)
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1943 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1944
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1945 def subscribe(self, request):
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1946 d = defer.ensureDeferred(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1947 self.backend.subscribe(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1948 request.nodeIdentifier,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1949 request.subscriber,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1950 request.sender,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1951 request.options,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1952 self._isPep(request),
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1953 request.recipient
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1954 )
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1955 )
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1956 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1957
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1958 def unsubscribe(self, request):
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1959 d = defer.ensureDeferred(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1960 self.backend.unsubscribe(request.nodeIdentifier,
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1961 request.subscriber,
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1962 request.sender,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1963 self._isPep(request),
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1964 request.recipient)
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1965 )
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1966 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1967
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1968 def subscriptions(self, request):
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1969 d = self.backend.getSubscriptions(request.sender,
357
1167e48e5f52 handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents: 355
diff changeset
1970 request.nodeIdentifier,
354
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1971 self._isPep(request),
18b983fe9e1b backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1972 request.recipient)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1973 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1974
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1975 def affiliations(self, request):
331
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1976 """Retrieve affiliation for normal entity (cf. XEP-0060 §5.7)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1977
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1978 retrieve all node where this jid is affiliated
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1979 """
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1980 d = self.backend.getAffiliations(request.sender,
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1981 request.nodeIdentifier,
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1982 self._isPep(request),
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1983 request.recipient)
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1984 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1985
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1986 def create(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1987 d = self.backend.createNode(request.nodeIdentifier,
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1988 request.sender, request.options,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1989 self._isPep(request),
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1990 request.recipient)
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1991 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1992
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1993 def default(self, request):
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1994 d = self.backend.getDefaultConfiguration(request.nodeType,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1995 self._isPep(request),
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
1996 request.sender)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1997 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
1998
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
1999 def configureGet(self, request):
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2000 d = self.backend.getNodeConfiguration(request.nodeIdentifier,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2001 self._isPep(request),
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2002 request.recipient)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
2003 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
2004
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2005 def configureSet(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2006 d = self.backend.setNodeConfiguration(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2007 request.options,
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2008 request.sender,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2009 self._isPep(request),
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2010 request.recipient)
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2011 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2012
331
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2013 def affiliationsGet(self, request):
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2014 """Retrieve affiliations for owner (cf. XEP-0060 §8.9.1)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2015
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2016 retrieve all affiliations for a node
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2017 """
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2018 d = self.backend.getAffiliationsOwner(request.nodeIdentifier,
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2019 request.sender,
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2020 self._isPep(request),
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2021 request.recipient)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2022 return d.addErrback(self._mapErrors)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2023
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2024 def affiliationsSet(self, request):
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2025 d = self.backend.setAffiliationsOwner(request.nodeIdentifier,
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2026 request.sender,
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2027 request.affiliations,
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2028 self._isPep(request),
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2029 request.recipient)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2030 return d.addErrback(self._mapErrors)
e93a9fd329d9 affiliations XMPP handling:
Goffi <goffi@goffi.org>
parents: 330
diff changeset
2031
341
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2032 def subscriptionsGet(self, request):
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2033 """Retrieve subscriptions for owner (cf. XEP-0060 §8.8.1)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2034
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2035 retrieve all affiliations for a node
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2036 """
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2037 d = self.backend.getSubscriptionsOwner(request.nodeIdentifier,
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2038 request.sender,
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2039 self._isPep(request),
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2040 request.recipient)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2041 return d.addErrback(self._mapErrors)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2042
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2043 def subscriptionsSet(self, request):
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2044 d = self.backend.setSubscriptionsOwner(request.nodeIdentifier,
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2045 request.sender,
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2046 request.subscriptions,
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2047 self._isPep(request),
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2048 request.recipient)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2049 return d.addErrback(self._mapErrors)
b49f75a26156 backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents: 340
diff changeset
2050
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2051 def items(self, request):
278
8a71486c3e95 implements RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 263
diff changeset
2052 ext_data = {}
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2053 if const.FLAG_ENABLE_RSM and request.rsm is not None:
377
ded7657b03fa backend: send a BadRequest if RSM max is negative
Goffi <goffi@goffi.org>
parents: 375
diff changeset
2054 if request.rsm.max < 0:
ded7657b03fa backend: send a BadRequest if RSM max is negative
Goffi <goffi@goffi.org>
parents: 375
diff changeset
2055 raise pubsub.BadRequest(text="max can't be negative")
290
9f612fa19eea backend: fixed a crash when there is no RSM in request
Goffi <goffi@goffi.org>
parents: 288
diff changeset
2056 ext_data['rsm'] = request.rsm
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2057 try:
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2058 ext_data['pep'] = request.delegated
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2059 except AttributeError:
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2060 pass
375
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2061 ext_data['order_by'] = request.orderBy or []
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2062 d = defer.ensureDeferred(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2063 self.backend.getItems(
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2064 request.nodeIdentifier,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2065 request.sender,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2066 request.recipient,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2067 request.maxItems,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2068 request.itemIdentifiers,
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2069 ext_data
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2070 )
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2071 )
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
2072 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
2073
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2074 def retract(self, request):
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
2075 d = defer.ensureDeferred(
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
2076 self.backend.retractItem(request.nodeIdentifier,
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2077 request.itemIdentifiers,
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2078 request.sender,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2079 request.notify,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2080 self._isPep(request),
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2081 request.recipient)
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
2082 )
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
2083 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
2084
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2085 def purge(self, request):
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
2086 d = defer.ensureDeferred(
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
2087 self.backend.purgeNode(request.nodeIdentifier,
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2088 request.sender,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2089 self._isPep(request),
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2090 request.recipient)
455
0b5233981671 backend: fix `delete` notification + add `purge` notification
Goffi <goffi@goffi.org>
parents: 453
diff changeset
2091 )
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
2092 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
2093
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2094 def delete(self, request):
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
2095 d = defer.ensureDeferred(
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
2096 self.backend.deleteNode(request.nodeIdentifier,
294
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2097 request.sender,
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2098 self._isPep(request),
df1edebb0466 PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents: 290
diff changeset
2099 request.recipient)
431
5e8b8ef5c862 implentation of XEP-0346 (Form Discovery and Publishing):
Goffi <goffi@goffi.org>
parents: 430
diff changeset
2100 )
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2101 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2102
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
2103 components.registerAdapter(PubSubResourceFromBackend,
317
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
2104 iidavoll.IBackendService,
34adc4a8aa64 new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents: 315
diff changeset
2105 iwokkel.IPubSubResource)
375
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2106
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2107
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2108
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
2109 @implementer(iwokkel.IDisco)
375
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2110 class ExtraDiscoHandler(XMPPHandler):
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2111 # see comment in twisted/plugins/pubsub.py
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2112 # FIXME: upstream must be fixed so we can use custom (non pubsub#) disco features
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2113
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2114 def getDiscoInfo(self, requestor, service, nodeIdentifier=''):
452
8da3db1e82a9 backend: advertise RSM on disco
Goffi <goffi@goffi.org>
parents: 440
diff changeset
2115 return [
8da3db1e82a9 backend: advertise RSM on disco
Goffi <goffi@goffi.org>
parents: 440
diff changeset
2116 disco.DiscoFeature(rsm.NS_RSM),
8da3db1e82a9 backend: advertise RSM on disco
Goffi <goffi@goffi.org>
parents: 440
diff changeset
2117 # cf. https://xmpp.org/extensions/xep-0060.html#subscriber-retrieve-returnsome
8da3db1e82a9 backend: advertise RSM on disco
Goffi <goffi@goffi.org>
parents: 440
diff changeset
2118 disco.DiscoFeature(const.NS_PUBSUB_RSM),
8da3db1e82a9 backend: advertise RSM on disco
Goffi <goffi@goffi.org>
parents: 440
diff changeset
2119 disco.DiscoFeature(pubsub.NS_ORDER_BY),
478
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2120 disco.DiscoFeature(const.NS_FDP),
b544109ab4c4 Privileged Entity update + Pubsub Account Management partial implementation + Public Pubsub Subscription
Goffi <goffi@goffi.org>
parents: 471
diff changeset
2121 disco.DiscoFeature(const.NS_PPS)
452
8da3db1e82a9 backend: advertise RSM on disco
Goffi <goffi@goffi.org>
parents: 440
diff changeset
2122 ]
375
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2123
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2124 def getDiscoItems(self, requestor, service, nodeIdentifier=''):
9a787881b824 implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents: 369
diff changeset
2125 return []