Mercurial > libervia-pubsub
annotate sat_pubsub/backend.py @ 426:6f8e1c180c83
added "~/.config/sat" as search patch for config
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 13 Sep 2020 15:52:17 +0200 |
parents | c21f31355ab9 |
children | 5a0ada3b61ca |
rev | line source |
---|---|
414 | 1 #!/usr/bin/env python3 |
237 | 2 # |
384 | 3 # Copyright (c) 2012-2019 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 | 6 |
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 | 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 | 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 | 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 | 26 |
312
5d7c3787672e
fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
27 # -- |
233 | 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 | 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 | 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 | 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 | 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 | 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 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
65 |
414 | 66 from zope.interface import implementer |
2 | 67 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
68 from twisted.application import service |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
69 from twisted.python import components, log |
183
c21b986cff30
Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
181
diff
changeset
|
70 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
|
71 from twisted.words.protocols.jabber.error import StanzaError |
381
7c490bb60847
backend: items ids are returned in payload if not specified on publish
Goffi <goffi@goffi.org>
parents:
380
diff
changeset
|
72 from twisted.words.xish import domish, utility |
1 | 73 |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
74 from wokkel import disco |
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
75 from wokkel import data_form |
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
76 from wokkel import rsm |
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
77 from wokkel import iwokkel |
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
78 from wokkel import pubsub |
375
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
79 from wokkel.subprotocols import XMPPHandler |
20
eddea65d1032
Added two exceptions: NoInstantNodes and NodeExists.
Ralph Meijer <ralphm@ik.nu>
parents:
18
diff
changeset
|
80 |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
81 from sat_pubsub import error |
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
82 from sat_pubsub import iidavoll |
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
83 from sat_pubsub import const |
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
84 from sat_pubsub import container |
15 | 85 |
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
|
86 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
87 def _getAffiliation(node, entity): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
88 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
|
89 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
|
90 return d |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
20
diff
changeset
|
91 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
92 |
394
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
93 def elementCopy(element): |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
94 """Make a copy of a domish.Element |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
95 |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 it will also affect original element. |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
100 @param element(domish.Element): Element to clone |
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 new_elt = domish.Element( |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
103 (element.uri, element.name), |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
104 defaultUri = element.defaultUri, |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
105 attribs = element.attributes, |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
106 localPrefixes = element.localPrefixes) |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
107 new_elt.parent = element.parent |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
108 new_elt.children = element.children[:] |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
109 return new_elt |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
110 |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
111 |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
112 def itemDataCopy(item_data): |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
113 """Make a copy of an item_data |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
114 |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
115 deep copy every element of the tuple but item |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
116 do an elementCopy of item_data.item |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
117 @param item_data(ItemData): item data to copy |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
118 @return (ItemData): copied data |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
119 """ |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
120 return container.ItemData(*[elementCopy(item_data.item)] |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
121 + [copy.deepcopy(d) for d in item_data[1:]]) |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
122 |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
123 |
414 | 124 @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
|
125 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
|
126 """ |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
127 Generic publish-subscribe backend service. |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
128 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
129 @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
|
130 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
|
131 and possible options to choose from. |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
132 @type nodeOptions: C{dict}. |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
133 @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
|
134 """ |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
135 |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
136 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
137 nodeOptions = { |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
138 const.OPT_PERSIST_ITEMS: |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
139 {"type": "boolean", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
140 "label": "Persist items to storage"}, |
422 | 141 const.OPT_MAX_ITEMS: |
142 {"type": "text-single", | |
143 "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
|
144 const.OPT_DELIVER_PAYLOADS: |
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": "Deliver payloads with event notifications"}, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
147 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
|
148 {"type": "list-single", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
149 "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
|
150 "options": { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
151 "never": "Never", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
152 "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
|
153 }, |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
154 const.OPT_ACCESS_MODEL: |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
155 {"type": "list-single", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
156 "label": "Who can subscribe to this node", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
157 "options": { |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
158 const.VAL_AMODEL_OPEN: "Public node", |
354
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
159 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
|
160 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
|
161 const.VAL_AMODEL_WHITELIST: "Node restricted to some jids", |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
162 } |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
163 }, |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
164 const.OPT_ROSTER_GROUPS_ALLOWED: |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
165 {"type": "list-multi", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
166 "label": "Groups of the roster allowed to access the node", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
167 }, |
260 | 168 const.OPT_PUBLISH_MODEL: |
169 {"type": "list-single", | |
170 "label": "Who can publish to this node", | |
171 "options": { | |
172 const.VAL_PMODEL_OPEN: "Everybody can publish", | |
173 const.VAL_PMODEL_PUBLISHERS: "Only owner and publishers can publish", | |
174 const.VAL_PMODEL_SUBSCRIBERS: "Everybody which subscribed to the node", | |
175 } | |
176 }, | |
367
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
177 const.OPT_SERIAL_IDS: |
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
178 {"type": "boolean", |
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
179 "label": "Use serial ids"}, |
403
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
180 const.OPT_CONSISTENT_PUBLISHER: |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
181 {"type": "boolean", |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
182 "label": "Keep publisher on update"}, |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
183 } |
159
6fe78048baf9
Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents:
155
diff
changeset
|
184 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
185 subscriptionOptions = { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
186 "pubsub#subscription_type": |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
187 {"type": "list-single", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
188 "options": { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
189 "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
|
190 "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
|
191 }, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
192 "pubsub#subscription_depth": |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
193 {"type": "list-single", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
194 "options": { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
195 "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
|
196 "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
|
197 }, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
198 } |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
199 |
380 | 200 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
|
201 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
|
202 self.storage = storage |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
203 self._callbackList = [] |
380 | 204 self.config = config |
414 | 205 self.admins = config['admins_jids_list'] |
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
|
206 |
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
|
207 def isAdmin(self, entity_jid): |
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
|
208 """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
|
209 return entity_jid.userhostJID() in self.admins |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
210 |
363
a98b3d52c2ff
added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents:
358
diff
changeset
|
211 def supportsPublishOptions(self): |
a98b3d52c2ff
added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents:
358
diff
changeset
|
212 return True |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
213 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
214 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
|
215 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
216 |
250 | 217 def supportsGroupBlog(self): |
218 return True | |
219 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
220 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
|
221 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
222 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
223 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
|
224 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
225 |
260 | 226 def supportsPublishModel(self): |
227 return True | |
228 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
229 def getNodeType(self, nodeIdentifier, pep, recipient=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
230 # FIXME: manage pep and recipient |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
231 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
|
232 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
|
233 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
234 |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
235 def _getNodesIds(self, subscribed, pep, recipient): |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
236 # TODO: filter whitelist nodes |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
237 # 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
|
238 if not subscribed: |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
239 allowed_accesses = {'open', 'whitelist'} |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
240 else: |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
241 allowed_accesses = {'open', 'presence', 'whitelist'} |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
242 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
|
243 |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
244 def getNodes(self, requestor, pep, recipient): |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
245 if pep: |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
246 d = self.privilege.isSubscribedFrom(requestor, recipient) |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
247 d.addCallback(self._getNodesIds, pep, recipient) |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
248 return d |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
249 return 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
|
250 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
251 def getNodeMetaData(self, nodeIdentifier, pep, recipient=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
252 # FIXME: manage pep and recipient |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
253 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
|
254 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
|
255 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
|
256 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
257 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
258 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
|
259 options = [] |
414 | 260 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
|
261 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
|
262 option = {"var": key} |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
263 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
|
264 option["value"] = value |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
265 options.append(option) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
266 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
267 return options |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
268 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
269 def _checkAuth(self, node, requestor): |
260 | 270 """ Check authorisation of publishing in node for requestor """ |
271 | |
272 def check(affiliation): | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
273 d = defer.succeed((affiliation, node)) |
260 | 274 configuration = node.getConfiguration() |
275 publish_model = configuration[const.OPT_PUBLISH_MODEL] | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
276 if publish_model == const.VAL_PMODEL_PUBLISHERS: |
260 | 277 if affiliation not in ['owner', 'publisher']: |
278 raise error.Forbidden() | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
279 elif publish_model == const.VAL_PMODEL_SUBSCRIBERS: |
260 | 280 if affiliation not in ['owner', 'publisher']: |
281 # we are in subscribers publish model, we must check that | |
282 # the requestor is a subscriber to allow him to publish | |
283 | |
284 def checkSubscription(subscribed): | |
285 if not subscribed: | |
286 raise error.Forbidden() | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
287 return (affiliation, node) |
260 | 288 |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
289 d.addCallback(lambda __: node.isSubscribed(requestor)) |
260 | 290 d.addCallback(checkSubscription) |
291 elif publish_model != const.VAL_PMODEL_OPEN: | |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
292 # publish_model must be publishers (default), subscribers or open. |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
293 raise ValueError('Unexpected value') |
260 | 294 |
295 return d | |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
296 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
297 d = node.getAffiliation(requestor) |
260 | 298 d.addCallback(check) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
299 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
300 |
250 | 301 def parseItemConfig(self, item): |
302 """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
|
303 |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
304 @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
|
305 @return (tuple[unicode, dict)): (access_model, item_config) |
250 | 306 """ |
307 item_config = None | |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
308 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
|
309 for idx, elt in enumerate(item.elements()): |
395
9bc3fbf3e685
backend: fixed elements filtering in parseItemConfig
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
310 if elt.uri != data_form.NS_X_DATA or elt.name != 'x': |
250 | 311 continue |
312 form = data_form.Form.fromElement(elt) | |
300 | 313 if form.formNamespace == const.NS_ITEM_CONFIG: |
250 | 314 item_config = form |
300 | 315 del item.children[idx] #we need to remove the config from item |
250 | 316 break |
317 | |
318 if item_config: | |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
319 access_model = item_config.get(const.OPT_ACCESS_MODEL, const.VAL_AMODEL_DEFAULT) |
250 | 320 return (access_model, item_config) |
321 | |
301
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
322 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
|
323 """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
|
324 |
364
8bd8be6815ab
completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents:
363
diff
changeset
|
325 @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
|
326 @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
|
327 """ |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
328 categories = [] |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
329 try: |
414 | 330 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
|
331 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
|
332 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
|
333 |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 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
|
338 |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
339 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
|
340 |
353
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
341 def enforceSchema(self, item_elt, schema, affiliation): |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
342 """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
|
343 |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
344 @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
|
345 @param schema(domish.Eement): schema to enfore |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
346 @param affiliation(unicode): affiliation of the publisher |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
347 """ |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
348 try: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
349 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
|
350 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
|
351 except (StopIteration, data_form.Error): |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
352 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
|
353 else: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
354 item_elt.children.remove(x_elt) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
355 |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
356 schema_form = data_form.Form.fromElement(schema) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
357 |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
358 # we enforce restrictions |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
359 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
|
360 var = field_elt['var'] |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
361 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
|
362 write_restriction = restrict_elt.attributes.get('write') |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
363 if write_restriction is not None: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
364 if write_restriction == 'owner': |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
365 if affiliation != 'owner': |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
366 # 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
|
367 # 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
|
368 # 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
|
369 try: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
370 item_form.removeField(item_form.fields[var]) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
371 except KeyError: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
372 pass |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
373 item_form.addField(schema_form.fields[var]) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
374 else: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
375 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
|
376 |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
377 # 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
|
378 to_remove = set() |
414 | 379 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
|
380 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
|
381 to_remove.add(item_field) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
382 |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
383 for field in to_remove: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
384 item_form.removeField(field) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
385 item_elt.addChild(item_form.toElement()) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
386 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
387 def _checkOverwrite(self, node, itemIdentifiers, publisher): |
403
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
388 """Check that publisher can overwrite items |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
389 |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
390 current publisher must correspond to each item publisher |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
391 """ |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
392 def doCheck(item_pub_map): |
414 | 393 for item_publisher in item_pub_map.values(): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
394 if item_publisher.userhost() != publisher.userhost(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
395 raise error.ItemForbidden() |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
396 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
397 d = node.getItemsPublishers(itemIdentifiers) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
398 d.addCallback(doCheck) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
399 return d |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
400 |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
401 async def publish(self, nodeIdentifier, items, requestor, options, pep, recipient): |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
402 node = await self.storage.getNode(nodeIdentifier, pep, recipient) |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
403 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
|
404 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
405 if node.nodeType == 'collection': |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
406 raise error.NoPublishing() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
407 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
408 configuration = node.getConfiguration() |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
409 persistItems = configuration[const.OPT_PERSIST_ITEMS] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
410 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
|
411 |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
412 # we check that publish-options are satisfied |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
413 for field, value in options.items(): |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
414 try: |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
415 current_value = configuration[field] |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
416 except KeyError: |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
417 raise error.ConstraintFailed( |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
418 f"publish-options {field!r} doesn't exist in node configuration" |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
419 ) |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
420 if current_value != value: |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
421 raise error.ConstraintFailed( |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
422 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
|
423 f"which doesn't fit publish-options expected {value!r}" |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
424 ) |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
425 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
426 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
|
427 raise error.ItemForbidden() |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
428 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
|
429 raise error.ItemRequired() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
430 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
431 items_data = [] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
432 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
|
433 ret_payload = None # payload returned, None or domish.Element |
250 | 434 for item in items: |
299 | 435 # we enforce publisher (cf XEP-0060 §7.1.2.3) |
436 item['publisher'] = requestor.full() | |
250 | 437 if persistItems or deliverPayloads: |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
438 item.uri = None |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
439 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
|
440 if not item.getAttribute("id"): |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
441 item["id"] = await node.getNextId() |
367
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
442 new_item = True |
389
66128656f76c
backend: fixed items returned on publishing:
Goffi <goffi@goffi.org>
parents:
388
diff
changeset
|
443 if ret_payload is None: |
414 | 444 ret_pubsub_elt = domish.Element((pubsub.NS_PUBSUB, 'pubsub')) |
445 ret_publish_elt = ret_pubsub_elt.addElement('publish') | |
446 ret_publish_elt['node'] = node.nodeIdentifier | |
389
66128656f76c
backend: fixed items returned on publishing:
Goffi <goffi@goffi.org>
parents:
388
diff
changeset
|
447 ret_payload = ret_pubsub_elt |
66128656f76c
backend: fixed items returned on publishing:
Goffi <goffi@goffi.org>
parents:
388
diff
changeset
|
448 ret_publish_elt = ret_payload.publish |
414 | 449 ret_item_elt = ret_publish_elt.addElement('item') |
450 ret_item_elt["id"] = item["id"] | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
451 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
452 check_overwrite = True |
367
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
453 new_item = False |
250 | 454 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
|
455 categories = self.parseCategories(item) |
353
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
456 schema = node.getSchema() |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
457 if schema is not None: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
458 self.enforceSchema(item, schema, affiliation) |
367
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
459 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
|
460 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
461 if persistItems: |
367
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
462 |
403
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
463 if check_overwrite: |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
464 itemIdentifiers = [item['id'] for item in items |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
465 if item.getAttribute('id')] |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
466 |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
467 if affiliation == 'owner' or self.isAdmin(requestor): |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
468 if configuration[const.OPT_CONSISTENT_PUBLISHER]: |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
469 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
|
470 if pub_map: |
4179ed660a85
backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents:
414
diff
changeset
|
471 # 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
|
472 # 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
|
473 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
|
474 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
|
475 # 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
|
476 # publishers) |
4179ed660a85
backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents:
414
diff
changeset
|
477 raise error.NoPublishing( |
4179ed660a85
backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents:
414
diff
changeset
|
478 "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
|
479 "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
|
480 "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
|
481 # 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
|
482 # 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
|
483 requestor = publishers.pop() |
4179ed660a85
backend: fixed publishing with "consistent_publisher" when no item was previously available
Goffi <goffi@goffi.org>
parents:
414
diff
changeset
|
484 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
|
485 item['publisher'] = requestor.full() |
403
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
486 else: |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
487 # we don't want a publisher to overwrite the item |
1dc606612405
implemented experimental "consistent_publisher" option:
Goffi <goffi@goffi.org>
parents:
397
diff
changeset
|
488 # of an other publisher |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
489 await self._checkOverwrite(node, itemIdentifiers, requestor) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
490 |
367
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
491 # 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
|
492 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
|
493 |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
494 self._doNotify(node, items_data, deliverPayloads, pep, recipient) |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
495 return ret_payload |
367
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
496 |
a772f7dac930
backend, storage(pgsql): creation/update date + serial ids:
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
497 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
|
498 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
|
499 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
|
500 item_data.item.children = [] |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
501 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
|
502 '//event/pubsub/notify') |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
503 |
339
516b282aa542
backend (notifications): avoid useless database request in getNotifications
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
504 def getNotifications(self, node, items_data): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
505 """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
|
506 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
507 subscribers will be associated with subscribed items, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
508 and subscription type. |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
509 """ |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
510 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
511 def toNotifications(subscriptions, items_data): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
512 subsBySubscriber = {} |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
513 for subscription in subscriptions: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
514 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
|
515 'items') == 'items': |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
516 subs = subsBySubscriber.setdefault(subscription.subscriber, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
517 set()) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
518 subs.add(subscription) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
519 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
520 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
|
521 for subscriber, subscriptions_ |
414 | 522 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
|
523 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
524 return notifications |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
525 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
526 def rootNotFound(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
527 failure.trap(error.NodeNotFound) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
528 return [] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
529 |
339
516b282aa542
backend (notifications): avoid useless database request in getNotifications
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
530 d1 = node.getSubscriptions('subscribed') |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
531 # FIXME: must add root node subscriptions ? |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
532 # d2 = self.storage.getNode('', False) # FIXME: to check |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
533 # d2.addCallback(lambda node: node.getSubscriptions('subscribed')) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
534 # d2.addErrback(rootNotFound) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
535 # d = defer.gatherResults([d1, d2]) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
536 # d.addCallback(lambda result: result[0] + result[1]) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
537 d1.addCallback(toNotifications, items_data) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
538 return d1 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
539 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
540 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
|
541 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
|
542 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
543 def registerRetractNotifier(self, observerfn, *args, **kwargs): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
544 self.addObserver('//event/pubsub/retract', observerfn, *args, **kwargs) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
545 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
546 def subscribe(self, nodeIdentifier, subscriber, requestor, pep, recipient): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
547 subscriberEntity = subscriber.userhostJID() |
216
53d2c0019458
Fix subscription and unsubscription JID checks.
Ralph Meijer <ralphm@ik.nu>
parents:
211
diff
changeset
|
548 if subscriberEntity != requestor.userhostJID(): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
549 return defer.fail(error.Forbidden()) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
550 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
551 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
|
552 d.addCallback(_getAffiliation, subscriberEntity) |
355
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
553 d.addCallback(self._doSubscribe, subscriber, pep, recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
554 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
555 |
355
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
556 def _doSubscribe(self, result, subscriber, pep, recipient): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
557 node, affiliation = result |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
558 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
559 if affiliation == 'outcast': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
560 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
561 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
562 access_model = node.getAccessModel() |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
563 |
354
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
564 if access_model == const.VAL_AMODEL_OPEN: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
565 d = defer.succeed(None) |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
566 elif access_model == const.VAL_AMODEL_PRESENCE: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
567 d = self.checkPresenceSubscription(node, subscriber) |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
568 elif access_model == const.VAL_AMODEL_PUBLISHER_ROSTER: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
569 d = self.checkRosterGroups(node, subscriber) |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
570 elif access_model == const.VAL_AMODEL_WHITELIST: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
571 d = self.checkNodeAffiliations(node, subscriber) |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
572 else: |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
573 raise NotImplementedError |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
574 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
575 def trapExists(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
576 failure.trap(error.SubscriptionExists) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
577 return False |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
578 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
579 def cb(sendLast): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
580 d = node.getSubscription(subscriber) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
581 if sendLast: |
355
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
582 d.addCallback(self._sendLastPublished, node, pep, recipient) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
583 return d |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
584 |
355
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
585 d.addCallback(lambda _: node.addSubscription(subscriber, 'subscribed', {})) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
586 d.addCallbacks(lambda _: True, trapExists) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
587 d.addCallback(cb) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
588 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
589 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
590 |
355
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
591 def _sendLastPublished(self, subscription, node, pep, recipient): |
183
c21b986cff30
Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
181
diff
changeset
|
592 |
355
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
593 def notifyItem(items_data): |
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
594 if items_data: |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
595 reactor.callLater(0, self.dispatch, |
355
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
596 {'items_data': items_data, |
261
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
597 'node': node, |
355
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
598 'pep': pep, |
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
599 'recipient': recipient, |
261
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
600 'subscription': subscription, |
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
601 }, |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
602 '//event/pubsub/notify') |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
603 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
604 config = node.getConfiguration() |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
605 sendLastPublished = config.get('pubsub#send_last_published_item', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
606 'never') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
607 if sendLastPublished == 'on_sub' and node.nodeType == 'leaf': |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
608 entity = subscription.subscriber.userhostJID() |
355
c72fcbdcdab7
backend: fixed subscription, PEP was not handled correctly
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
609 d = self.getItemsData(node.nodeIdentifier, entity, recipient, maxItems=1, ext_data={'pep': pep}) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
610 d.addCallback(notifyItem) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
611 d.addErrback(log.err) |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
612 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
613 return subscription |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
614 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
615 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
|
616 if subscriber.userhostJID() != requestor.userhostJID(): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
617 return defer.fail(error.Forbidden()) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
618 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
619 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
|
620 d.addCallback(lambda node: node.removeSubscription(subscriber)) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
621 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
622 |
357
1167e48e5f52
handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents:
355
diff
changeset
|
623 def getSubscriptions(self, requestor, nodeIdentifier, pep, recipient): |
1167e48e5f52
handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents:
355
diff
changeset
|
624 """retrieve subscriptions of an entity |
1167e48e5f52
handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents:
355
diff
changeset
|
625 |
1167e48e5f52
handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents:
355
diff
changeset
|
626 @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
|
627 @param nodeIdentifier(unicode, None): identifier of the node |
1167e48e5f52
handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents:
355
diff
changeset
|
628 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
|
629 @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
|
630 @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
|
631 """ |
1167e48e5f52
handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents:
355
diff
changeset
|
632 return self.storage.getSubscriptions(requestor, nodeIdentifier, pep, recipient) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
633 |
228 | 634 def supportsAutoCreate(self): |
635 return True | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
636 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
637 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
|
638 return True |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
639 |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
640 def createNode(self, nodeIdentifier, requestor, options=None, pep=False, recipient=None): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
641 if not nodeIdentifier: |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
642 nodeIdentifier = 'generic/%s' % uuid.uuid4() |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
643 |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
644 if not options: |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
645 options = {} |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
646 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
647 nodeType = 'leaf' |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
648 config = self.storage.getDefaultConfiguration(nodeType) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
649 config['pubsub#node_type'] = nodeType |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
650 config.update(options) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
651 |
352 | 652 # TODO: handle schema on creation |
653 d = self.storage.createNode(nodeIdentifier, requestor, config, None, pep, recipient) | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
654 d.addCallback(lambda _: nodeIdentifier) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
655 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
656 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
657 def getDefaultConfiguration(self, nodeType): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
658 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
|
659 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
660 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
661 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
|
662 if not nodeIdentifier: |
196
00a6dbfbee42
Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents:
183
diff
changeset
|
663 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
|
664 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
665 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
|
666 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
|
667 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
668 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
669 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
670 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
|
671 if not nodeIdentifier: |
196
00a6dbfbee42
Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents:
183
diff
changeset
|
672 return defer.fail(error.NoRootNode()) |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
673 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
674 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
|
675 d.addCallback(_getAffiliation, requestor) |
422 | 676 d.addCallback( |
677 lambda result: defer.ensureDeferred( | |
678 self._doSetNodeConfiguration(result, requestor, options)) | |
679 ) | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
680 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
681 |
422 | 682 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
|
683 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
684 |
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
|
685 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
|
686 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
687 |
422 | 688 max_items = options.get(const.OPT_MAX_ITEMS, '').strip().lower() |
689 if not max_items: | |
690 pass | |
691 elif max_items == 'max': | |
692 # FIXME: we use "0" for max for now, but as "0" may be used as legal value | |
693 # in XEP-0060 ("max" is used otherwise), we should use "None" instead. | |
694 # This require a schema update, as NULL is not allowed at the moment | |
695 options.fields[const.OPT_MAX_ITEMS].value = "0" | |
696 else: | |
697 # max_items is a number, we have to check that it's not bigger than the | |
698 # total number of items on this node | |
699 try: | |
700 max_items = int(max_items) | |
701 except ValueError: | |
702 raise error.InvalidConfigurationValue('Invalid "max_items" value') | |
703 else: | |
704 options.fields[const.OPT_MAX_ITEMS].value = str(max_items) | |
705 if max_items: | |
706 items_count = await node.getItemsCount(None, True) | |
707 if max_items < items_count: | |
708 raise error.ConstraintFailed( | |
709 "\"max_items\" can't be set to a value lower than the total " | |
710 "number of items on this node. Please increase \"max_items\" " | |
711 "or delete items from this node") | |
712 | |
713 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
|
714 |
352 | 715 def getNodeSchema(self, nodeIdentifier, pep, recipient): |
716 if not nodeIdentifier: | |
717 return defer.fail(error.NoRootNode()) | |
718 | |
719 d = self.storage.getNode(nodeIdentifier, pep, recipient) | |
720 d.addCallback(lambda node: node.getSchema()) | |
721 | |
722 return d | |
723 | |
724 def setNodeSchema(self, nodeIdentifier, schema, requestor, pep, recipient): | |
725 """set or remove Schema of a node | |
726 | |
357
1167e48e5f52
handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents:
355
diff
changeset
|
727 @param nodeIdentifier(unicode): identifier of the pubusb node |
352 | 728 @param schema(domish.Element, None): schema to set |
729 None to remove schema | |
364
8bd8be6815ab
completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents:
363
diff
changeset
|
730 @param requestor(jid.JID): entity doing the request |
8bd8be6815ab
completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents:
363
diff
changeset
|
731 @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
|
732 @param recipient(jid.JID, None): recipient of the PEP request |
352 | 733 """ |
734 if not nodeIdentifier: | |
735 return defer.fail(error.NoRootNode()) | |
736 | |
737 d = self.storage.getNode(nodeIdentifier, pep, recipient) | |
738 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
|
739 d.addCallback(self._doSetNodeSchema, requestor, schema) |
352 | 740 return d |
741 | |
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
|
742 def _doSetNodeSchema(self, result, requestor, schema): |
352 | 743 node, affiliation = result |
744 | |
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
|
745 if affiliation != 'owner' and not self.isAdmin(requestor): |
352 | 746 raise error.Forbidden() |
747 | |
748 return node.setSchema(schema) | |
749 | |
331 | 750 def getAffiliations(self, entity, nodeIdentifier, pep, recipient): |
751 return self.storage.getAffiliations(entity, nodeIdentifier, pep, recipient) | |
752 | |
753 def getAffiliationsOwner(self, nodeIdentifier, requestor, pep, recipient): | |
754 d = self.storage.getNode(nodeIdentifier, pep, recipient) | |
755 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
|
756 d.addCallback(self._doGetAffiliationsOwner, requestor) |
331 | 757 return d |
758 | |
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
|
759 def _doGetAffiliationsOwner(self, result, requestor): |
331 | 760 node, affiliation = result |
761 | |
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
|
762 if affiliation != 'owner' and not self.isAdmin(requestor): |
331 | 763 raise error.Forbidden() |
764 return node.getAffiliations() | |
765 | |
766 def setAffiliationsOwner(self, nodeIdentifier, requestor, affiliations, pep, recipient): | |
767 d = self.storage.getNode(nodeIdentifier, pep, recipient) | |
768 d.addCallback(_getAffiliation, requestor) | |
769 d.addCallback(self._doSetAffiliationsOwner, requestor, affiliations) | |
770 return d | |
771 | |
772 def _doSetAffiliationsOwner(self, result, requestor, affiliations): | |
773 # Check that requestor is allowed to set affiliations, and delete entities | |
774 # with "none" affiliation | |
775 | |
776 # TODO: return error with failed affiliations in case of failure | |
777 node, requestor_affiliation = result | |
778 | |
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
|
779 if requestor_affiliation != 'owner' and not self.isAdmin(requestor): |
331 | 780 raise error.Forbidden() |
781 | |
782 # we don't allow requestor to change its own affiliation | |
783 requestor_bare = requestor.userhostJID() | |
784 if requestor_bare in affiliations and affiliations[requestor_bare] != 'owner': | |
785 # FIXME: it may be interesting to allow the owner to ask for ownership removal | |
786 # if at least one other entity is owner for this node | |
787 raise error.Forbidden("You can't change your own affiliation") | |
788 | |
414 | 789 to_delete = [jid_ for jid_, affiliation in affiliations.items() if affiliation == 'none'] |
331 | 790 for jid_ in to_delete: |
791 del affiliations[jid_] | |
792 | |
793 if to_delete: | |
794 d = node.deleteAffiliations(to_delete) | |
795 if affiliations: | |
796 d.addCallback(lambda dummy: node.setAffiliations(affiliations)) | |
797 else: | |
798 d = node.setAffiliations(affiliations) | |
799 | |
800 return d | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
801 |
341
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
802 def getSubscriptionsOwner(self, nodeIdentifier, requestor, pep, recipient): |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
803 d = self.storage.getNode(nodeIdentifier, pep, recipient) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
804 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
|
805 d.addCallback(self._doGetSubscriptionsOwner, requestor) |
341
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
806 return d |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
807 |
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
|
808 def _doGetSubscriptionsOwner(self, result, requestor): |
341
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
809 node, affiliation = result |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
810 |
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
|
811 if affiliation != 'owner' and not self.isAdmin(requestor): |
341
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
812 raise error.Forbidden() |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
813 return node.getSubscriptions() |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
814 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
815 def setSubscriptionsOwner(self, nodeIdentifier, requestor, subscriptions, pep, recipient): |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
816 d = self.storage.getNode(nodeIdentifier, pep, recipient) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
817 d.addCallback(_getAffiliation, requestor) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
818 d.addCallback(self._doSetSubscriptionsOwner, requestor, subscriptions) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
819 return d |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
820 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
821 def unwrapFirstError(self, failure): |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
822 failure.trap(defer.FirstError) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
823 return failure.value.subFailure |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
824 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
825 def _doSetSubscriptionsOwner(self, result, requestor, subscriptions): |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
826 # 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
|
827 # with "none" subscription |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
828 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
829 # 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
|
830 node, requestor_affiliation = result |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
831 |
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
|
832 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
|
833 raise error.Forbidden() |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
834 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
835 d_list = [] |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
836 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
837 for subscription in subscriptions.copy(): |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
838 if subscription.state == 'none': |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
839 subscriptions.remove(subscription) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
840 d_list.append(node.removeSubscription(subscription.subscriber)) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
841 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
842 if subscriptions: |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
843 d_list.append(node.setSubscriptions(subscriptions)) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
844 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
845 d = defer.gatherResults(d_list, consumeErrors=True) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
846 d.addCallback(lambda _: None) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
847 d.addErrback(self.unwrapFirstError) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
848 return d |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
849 |
353
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
850 def filterItemsWithSchema(self, items_data, schema, owner): |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
851 """check schema restriction and remove fields/items if they don't comply |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
852 |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
853 @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
|
854 items in this list will be modified |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
855 @param schema(domish.Element): node schema |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
856 @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
|
857 """ |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
858 fields_to_remove = set() |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
859 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
|
860 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
|
861 read_restriction = restrict_elt.attributes.get('read') |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
862 if read_restriction is not None: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
863 if read_restriction == 'owner': |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
864 if not owner: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
865 fields_to_remove.add(field_elt['var']) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
866 else: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
867 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
|
868 items_to_remove = [] |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
869 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
|
870 item_elt = item_data.item |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
871 try: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
872 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
|
873 except StopIteration: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
874 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
|
875 items_to_remove.append(item_data) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
876 continue |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
877 form = data_form.Form.fromElement(x_elt) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
878 # 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
|
879 for field in fields_to_remove: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
880 try: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
881 form.removeField(form.fields[field]) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
882 except KeyError: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
883 continue |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
884 item_elt.children.remove(x_elt) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
885 item_elt.addChild(form.toElement()) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
886 |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
887 for item_data in items_to_remove: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
888 items_data.remove(item_data) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
889 |
354
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
890 def checkPresenceSubscription(self, node, requestor): |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
891 """check if requestor has presence subscription from node owner |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
892 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
893 @param node(Node): node to check |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
894 @param requestor(jid.JID): entity who want to access node |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
895 """ |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
896 def gotRoster(roster): |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
897 if roster is None: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
898 raise error.Forbidden() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
899 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
900 if requestor not in roster: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
901 raise error.Forbidden() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
902 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
903 if not roster[requestor].subscriptionFrom: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
904 raise error.Forbidden() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
905 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
906 d = self.getOwnerRoster(node) |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
907 d.addCallback(gotRoster) |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
908 return d |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
909 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
910 @defer.inlineCallbacks |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
911 def checkRosterGroups(self, node, requestor): |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
912 """check if requestor is in allowed groups of a node |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
913 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
914 @param node(Node): node to check |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
915 @param requestor(jid.JID): entity who want to access node |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
916 """ |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
917 roster = yield self.getOwnerRoster(node) |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
918 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
919 if roster is None: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
920 raise error.Forbidden() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
921 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
922 if requestor not in roster: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
923 raise error.Forbidden() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
924 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
925 authorized_groups = yield node.getAuthorizedGroups() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
926 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
927 if not roster[requestor].groups.intersection(authorized_groups): |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
928 # 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
|
929 raise error.Forbidden() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
930 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
931 def checkNodeAffiliations(self, node, requestor): |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
932 """check if requestor is in white list of a node |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
933 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
934 @param node(Node): node to check |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
935 @param requestor(jid.JID): entity who want to access node |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
936 """ |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
937 def gotAffiliations(affiliations): |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
938 try: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
939 affiliation = affiliations[requestor.userhostJID()] |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
940 except KeyError: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
941 raise error.Forbidden() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
942 else: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
943 if affiliation not in ('owner', 'publisher', 'member'): |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
944 raise error.Forbidden() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
945 |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
946 d = node.getAffiliations() |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
947 d.addCallback(gotAffiliations) |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
948 return d |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
949 |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
950 @defer.inlineCallbacks |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
951 def checkNodeAccess(self, node, requestor): |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
952 """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
|
953 |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
954 @param node(Node): node to check |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
955 @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
|
956 @return (tuple): permissions data with: |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
957 - 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
|
958 - roster(None, ): roster of the requestor |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
959 None if not needed/available |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
960 - 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
|
961 @raise error.Forbidden: access is not granted |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
962 @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
|
963 """ |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
964 node, affiliation = yield _getAffiliation(node, requestor) |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
965 |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
966 if not iidavoll.ILeafNode.providedBy(node): |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
967 raise error.NotLeafNodeError() |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
968 |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
969 if affiliation == 'outcast': |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
970 raise error.Forbidden() |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
971 |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
972 # node access check |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
973 owner = affiliation == 'owner' |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
974 access_model = node.getAccessModel() |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
975 roster = None |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
976 |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
977 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
|
978 pass |
354
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
979 elif access_model == const.VAL_AMODEL_PRESENCE: |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
980 yield self.checkPresenceSubscription(node, requestor) |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
981 elif access_model == const.VAL_AMODEL_PUBLISHER_ROSTER: |
354
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
982 # 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
|
983 yield self.checkRosterGroups(node, requestor) |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
984 elif access_model == const.VAL_AMODEL_WHITELIST: |
354
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
985 yield self.checkNodeAffiliations(node, requestor) |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
986 else: |
414 | 987 raise Exception("Unknown access_model") |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
988 |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
989 defer.returnValue((affiliation, owner, roster, access_model)) |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
990 |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
991 @defer.inlineCallbacks |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
992 def getItemsIds(self, nodeIdentifier, requestor, authorized_groups, unrestricted, maxItems=None, ext_data=None, pep=False, recipient=None): |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
993 # FIXME: items access model are not checked |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
994 # TODO: check items access model |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
995 node = yield self.storage.getNode(nodeIdentifier, pep, recipient) |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
996 affiliation, owner, roster, access_model = yield self.checkNodeAccess(node, requestor) |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
997 ids = yield node.getItemsIds(authorized_groups, |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
998 unrestricted, |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
999 maxItems, |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1000 ext_data) |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1001 defer.returnValue(ids) |
346 | 1002 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1003 def getItems(self, nodeIdentifier, requestor, recipient, maxItems=None, |
278 | 1004 itemIdentifiers=None, ext_data=None): |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1005 d = self.getItemsData(nodeIdentifier, requestor, recipient, maxItems, itemIdentifiers, ext_data) |
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
|
1006 d.addCallback(lambda items_data: [item_data.item for item_data in items_data]) |
29c2553ef863
added getItemsData to get list of ItemData instead of only the list of domish.Element
Goffi <goffi@goffi.org>
parents:
318
diff
changeset
|
1007 return d |
29c2553ef863
added getItemsData to get list of ItemData instead of only the list of domish.Element
Goffi <goffi@goffi.org>
parents:
318
diff
changeset
|
1008 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1009 @defer.inlineCallbacks |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1010 def getOwnerRoster(self, node, owners=None): |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1011 # 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
|
1012 if owners is None: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1013 owners = yield node.getOwners() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1014 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1015 if len(owners) != 1: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1016 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
|
1017 return |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1018 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1019 owner_jid = owners[0] |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1020 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1021 try: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1022 roster = yield self.privilege.getRoster(owner_jid) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1023 except Exception as e: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1024 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
|
1025 owner_jid = owner_jid.full(), |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1026 msg = e)) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1027 return |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1028 defer.returnValue(roster) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1029 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1030 @defer.inlineCallbacks |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1031 def getItemsData(self, nodeIdentifier, requestor, recipient, maxItems=None, |
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
|
1032 itemIdentifiers=None, ext_data=None): |
29c2553ef863
added getItemsData to get list of ItemData instead of only the list of domish.Element
Goffi <goffi@goffi.org>
parents:
318
diff
changeset
|
1033 """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
|
1034 if maxItems == 0: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1035 log.msg("WARNING: maxItems=0 on items retrieval") |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1036 defer.returnValue([]) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1037 |
278 | 1038 if ext_data is None: |
1039 ext_data = {} | |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1040 node = yield 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
|
1041 try: |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1042 affiliation, owner, roster, access_model = yield self.checkNodeAccess(node, requestor) |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1043 except error.NotLeafNodeError: |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1044 defer.returnValue([]) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1045 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1046 # 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
|
1047 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1048 if owner: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1049 # 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
|
1050 requestor_groups = None |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1051 else: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1052 if roster is None: |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1053 # FIXME: publisher roster should be used, not owner |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1054 roster = yield self.getOwnerRoster(node) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1055 if roster is None: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1056 roster = {} |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1057 roster_item = roster.get(requestor.userhostJID()) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1058 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
|
1059 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1060 if itemIdentifiers: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1061 items_data = yield node.getItemsById(requestor_groups, owner, itemIdentifiers) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1062 else: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1063 items_data = yield 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
|
1064 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1065 if owner: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1066 # 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
|
1067 for item_data in items_data: |
318 | 1068 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
|
1069 pass |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1070 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
|
1071 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
|
1072 access = data_form.Field(None, const.OPT_ACCESS_MODEL, value=const.VAL_AMODEL_PUBLISHER_ROSTER) |
318 | 1073 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
|
1074 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
|
1075 form.addField(allowed) |
318 | 1076 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
|
1077 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
|
1078 #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
|
1079 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
|
1080 else: |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1081 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
|
1082 |
353
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
1083 schema = node.getSchema() |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
1084 if schema is not None: |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
1085 self.filterItemsWithSchema(items_data, schema, owner) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
1086 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1087 yield self._items_rsm(items_data, node, requestor_groups, owner, itemIdentifiers, ext_data) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1088 defer.returnValue(items_data) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1089 |
315
720d73e30bf7
backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents:
314
diff
changeset
|
1090 def _setCount(self, value, response): |
720d73e30bf7
backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents:
314
diff
changeset
|
1091 response.count = value |
720d73e30bf7
backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents:
314
diff
changeset
|
1092 |
318 | 1093 def _setIndex(self, value, response, adjust): |
1094 """Set index in RSM response | |
1095 | |
1096 @param value(int): value of the reference index (i.e. before or after item) | |
1097 @param response(RSMResponse): response instance to fill | |
1098 @param adjust(int): adjustement term (i.e. difference between reference index and first item of the result) | |
1099 """ | |
1100 response.index = value + adjust | |
315
720d73e30bf7
backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents:
314
diff
changeset
|
1101 |
318 | 1102 def _items_rsm(self, items_data, node, authorized_groups, owner, |
1103 itemIdentifiers, ext_data): | |
1104 # FIXME: move this to a separate module | |
1105 # TODO: Index can be optimized by keeping a cache of the last RSM request | |
1106 # An other optimisation would be to look for index first and use it as offset | |
1107 try: | |
1108 rsm_request = ext_data['rsm'] | |
1109 except KeyError: | |
1110 # No RSM in this request, nothing to do | |
1111 return items_data | |
1112 | |
1113 if itemIdentifiers: | |
1114 log.msg("WARNING, itemIdentifiers used with RSM, ignoring the RSM part") | |
1115 return items_data | |
1116 | |
278 | 1117 response = rsm.RSMResponse() |
1118 | |
318 | 1119 d_count = node.getItemsCount(authorized_groups, owner, ext_data) |
315
720d73e30bf7
backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents:
314
diff
changeset
|
1120 d_count.addCallback(self._setCount, response) |
278 | 1121 d_list = [d_count] |
1122 | |
318 | 1123 if items_data: |
1124 response.first = items_data[0].item['id'] | |
1125 response.last = items_data[-1].item['id'] | |
1126 | |
1127 # index handling | |
1128 if rsm_request.index is not None: | |
1129 response.index = rsm_request.index | |
1130 elif rsm_request.before: | |
1131 # The last page case (before == '') is managed in render method | |
1132 d_index = node.getItemsIndex(rsm_request.before, authorized_groups, owner, ext_data) | |
1133 d_index.addCallback(self._setIndex, response, -len(items_data)) | |
278 | 1134 d_list.append(d_index) |
318 | 1135 elif rsm_request.after is not None: |
1136 d_index = node.getItemsIndex(rsm_request.after, authorized_groups, owner, ext_data) | |
1137 d_index.addCallback(self._setIndex, response, 1) | |
1138 d_list.append(d_index) | |
1139 else: | |
1140 # the first page was requested | |
1141 response.index = 0 | |
278 | 1142 |
1143 def render(result): | |
318 | 1144 if rsm_request.before == '': |
1145 # the last page was requested | |
1146 response.index = response.count - len(items_data) | |
1147 items_data.append(container.ItemData(response.toElement())) | |
1148 return items_data | |
278 | 1149 |
1150 return defer.DeferredList(d_list).addCallback(render) | |
1151 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1152 def retractItem(self, nodeIdentifier, itemIdentifiers, requestor, notify, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1153 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
|
1154 d.addCallback(_getAffiliation, requestor) |
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
|
1155 d.addCallback(self._doRetract, itemIdentifiers, requestor, notify, pep, recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1156 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1157 |
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
|
1158 def _doRetract(self, result, itemIdentifiers, requestor, notify, pep, recipient): |
263
9dfd3890e646
added the constant FLAG_RETRACT_ALLOW_PUBLISHER to allow a publisher to retract an item he has published in a node of "open" publish model.
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
1159 node, affiliation = result |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1160 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
|
1161 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1162 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
|
1163 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1164 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1165 # 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
|
1166 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1167 def removeItems(items_data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1168 """Remove the items and keep only actually removed ones in items_data""" |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1169 d = node.removeItems(itemIdentifiers) |
301
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
1170 d.addCallback(lambda removed: [item_data for item_data in items_data if item_data.item["id"] in removed]) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1171 return d |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1172 |
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
|
1173 def checkPublishers(publishers_map): |
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
|
1174 """Called when requestor is neither owner neither publisher of the Node |
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
|
1175 |
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
|
1176 We check that requestor is publisher of all the items he wants to retract |
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
|
1177 and raise error.Forbidden if it is not the case |
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
|
1178 """ |
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
|
1179 # 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
|
1180 if (any((requestor.userhostJID() != publisher.userhostJID() |
414 | 1181 for publisher in publishers_map.values())) |
388
1c13ba86a421
backend: allow admins to retract any item
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1182 and not self.isAdmin(requestor) |
1c13ba86a421
backend: allow admins to retract any item
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1183 ): |
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
|
1184 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
|
1185 |
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
|
1186 if affiliation in ['owner', 'publisher']: |
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
|
1187 # the requestor is owner or publisher of the node |
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
|
1188 # he can retract what he wants |
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
|
1189 d = defer.succeed(None) |
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
|
1190 else: |
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
|
1191 # the requestor doesn't have right to retract on the whole node |
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
|
1192 # we check if he is a publisher for all items he wants to retract |
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
|
1193 # and forbid the retraction else. |
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
|
1194 d = node.getItemsPublishers(itemIdentifiers) |
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
|
1195 d.addCallback(checkPublishers) |
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
|
1196 d.addCallback(lambda dummy: node.getItemsById(None, True, itemIdentifiers)) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1197 d.addCallback(removeItems) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1198 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1199 if notify: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1200 d.addCallback(self._doNotifyRetraction, node, pep, recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1201 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1202 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1203 def _doNotifyRetraction(self, items_data, node, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1204 self.dispatch({'items_data': items_data, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1205 'node': node, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1206 'pep': pep, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1207 'recipient': recipient}, |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1208 '//event/pubsub/retract') |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1209 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1210 def purgeNode(self, nodeIdentifier, requestor, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1211 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
|
1212 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
|
1213 d.addCallback(self._doPurge, requestor) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1214 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1215 |
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
|
1216 def _doPurge(self, result, requestor): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1217 node, affiliation = result |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1218 persistItems = node.getConfiguration()[const.OPT_PERSIST_ITEMS] |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1219 |
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
|
1220 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
|
1221 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1222 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1223 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
|
1224 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1225 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1226 d = node.purge() |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1227 d.addCallback(self._doNotifyPurge, node.nodeIdentifier) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1228 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1229 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1230 def _doNotifyPurge(self, result, nodeIdentifier): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1231 self.dispatch(nodeIdentifier, '//event/pubsub/purge') |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1232 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1233 def registerPreDelete(self, preDeleteFn): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1234 self._callbackList.append(preDeleteFn) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1235 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1236 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
|
1237 def cb(subscriptions): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1238 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
|
1239 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1240 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
|
1241 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
|
1242 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
|
1243 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1244 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1245 def deleteNode(self, nodeIdentifier, requestor, pep, recipient, redirectURI=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1246 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
|
1247 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
|
1248 d.addCallback(self._doPreDelete, requestor, redirectURI, pep, recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1249 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1250 |
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
|
1251 def _doPreDelete(self, result, requestor, redirectURI, pep, recipient): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1252 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1253 |
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
|
1254 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
|
1255 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1256 |
261
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
1257 data = {'node': node, |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
1258 'redirectURI': redirectURI} |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
1259 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1260 d = defer.DeferredList([cb(data, pep, recipient) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1261 for cb in self._callbackList], |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1262 consumeErrors=1) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1263 d.addCallback(self._doDelete, node.nodeDbId) |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
1264 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1265 def _doDelete(self, result, nodeDbId): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1266 dl = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1267 for succeeded, r in result: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1268 if succeeded and r: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1269 dl.extend(r) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1270 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1271 d = self.storage.deleteNodeByDbId(nodeDbId) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1272 d.addCallback(self._doNotifyDelete, dl) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1273 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1274 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1275 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1276 def _doNotifyDelete(self, result, dl): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1277 for d in dl: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1278 d.callback(None) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1279 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1280 |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
1281 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
|
1282 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1283 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
|
1284 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1285 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1286 features = [ |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1287 "config-node", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1288 "create-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1289 "delete-any", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1290 "delete-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1291 "item-ids", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1292 "meta-data", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1293 "publish", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1294 "purge-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1295 "retract-items", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1296 "retrieve-affiliations", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1297 "retrieve-default", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1298 "retrieve-items", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1299 "retrieve-subscriptions", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1300 "subscribe", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1301 ] |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1302 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1303 discoIdentity = disco.DiscoIdentity('pubsub', |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1304 'service', |
414 | 1305 'Salut à Toi pubsub service') |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1306 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1307 pubsubService = None |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1308 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1309 _errorMap = { |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1310 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
|
1311 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
|
1312 error.Forbidden: ('forbidden', None, None), |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
1313 error.NotAuthorized: ('not-authorized', None, None), |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1314 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
|
1315 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
|
1316 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
|
1317 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
|
1318 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1319 'instant-nodes'), |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
1320 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
|
1321 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
|
1322 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
|
1323 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
|
1324 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1325 'persistent-node'), |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1326 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
|
1327 error.NoCollections: ('feature-not-implemented', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1328 'unsupported', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1329 'collections'), |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1330 error.NoPublishing: ('feature-not-implemented', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1331 'unsupported', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1332 'publish'), |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1333 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
|
1334 } |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1335 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1336 def __init__(self, backend): |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
1337 pubsub.PubSubResource.__init__(self) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1338 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1339 self.backend = backend |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1340 self.hideNodes = False |
153 | 1341 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1342 self.backend.registerPublishNotifier(self._notifyPublish) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1343 self.backend.registerRetractNotifier(self._notifyRetract) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1344 self.backend.registerPreDelete(self._preDelete) |
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
|
1345 |
228 | 1346 if self.backend.supportsAutoCreate(): |
1347 self.features.append("auto-create") | |
1348 | |
363
a98b3d52c2ff
added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents:
358
diff
changeset
|
1349 if self.backend.supportsPublishOptions(): |
a98b3d52c2ff
added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents:
358
diff
changeset
|
1350 self.features.append("publish-options") |
a98b3d52c2ff
added missing #publish-options in disco features
Arnaud Joset <info@agayon.be>
parents:
358
diff
changeset
|
1351 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1352 if self.backend.supportsInstantNodes(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1353 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
|
1354 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1355 if self.backend.supportsOutcastAffiliation(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1356 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
|
1357 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1358 if self.backend.supportsPersistentItems(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1359 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
|
1360 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1361 if self.backend.supportsPublisherAffiliation(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1362 self.features.append("publisher-affiliation") |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1363 |
250 | 1364 if self.backend.supportsGroupBlog(): |
1365 self.features.append("groupblog") | |
1366 | |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1367 # 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
|
1368 # examples but it's necessary for microblogging comments (see XEP-0277) |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1369 if self.backend.supportsPublishModel(): |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1370 self.features.append("publish_model") |
260 | 1371 |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1372 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
|
1373 """ 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
|
1374 |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1375 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
|
1376 """ |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1377 # 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
|
1378 |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1379 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
|
1380 if item_config: |
394
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
1381 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
|
1382 new_item.addChild(item_config.toElement()) |
394
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
1383 return new_item |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
1384 else: |
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
1385 return item |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1386 |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1387 @defer.inlineCallbacks |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1388 def _notifyPublish(self, data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1389 items_data = data['items_data'] |
250 | 1390 node = data['node'] |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1391 pep = data['pep'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1392 recipient = data['recipient'] |
250 | 1393 |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1394 owners, notifications_filtered = yield self._prepareNotify(items_data, node, data.get('subscription'), pep, recipient) |
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
|
1395 |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1396 # 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
|
1397 # 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
|
1398 # 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
|
1399 # 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
|
1400 |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1401 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
|
1402 notifications_filtered.append( |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1403 (owner_jid, |
364
8bd8be6815ab
completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents:
363
diff
changeset
|
1404 {pubsub.Subscription(node.nodeIdentifier, |
8bd8be6815ab
completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents:
363
diff
changeset
|
1405 owner_jid, |
8bd8be6815ab
completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents:
363
diff
changeset
|
1406 'subscribed')}, |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1407 [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
|
1408 |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1409 if pep: |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1410 defer.returnValue(self.backend.privilege.notifyPublish( |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1411 recipient, |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1412 node.nodeIdentifier, |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1413 notifications_filtered)) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1414 |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1415 else: |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1416 defer.returnValue(self.pubsubService.notifyPublish( |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1417 self.serviceJID, |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1418 node.nodeIdentifier, |
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1419 notifications_filtered)) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1420 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1421 def _notifyRetract(self, data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1422 items_data = data['items_data'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1423 node = data['node'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1424 pep = data['pep'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1425 recipient = data['recipient'] |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1426 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1427 def afterPrepare(result): |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1428 owners, notifications_filtered = result |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1429 #we add the owners |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1430 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1431 for owner_jid in owners: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1432 notifications_filtered.append( |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1433 (owner_jid, |
364
8bd8be6815ab
completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents:
363
diff
changeset
|
1434 {pubsub.Subscription(node.nodeIdentifier, |
8bd8be6815ab
completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents:
363
diff
changeset
|
1435 owner_jid, |
8bd8be6815ab
completed docstrings + use short notation for sets
Arnaud Joset <info@agayon.be>
parents:
363
diff
changeset
|
1436 'subscribed')}, |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1437 [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
|
1438 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1439 if pep: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1440 return self.backend.privilege.notifyRetract( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1441 recipient, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1442 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1443 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1444 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1445 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1446 return self.pubsubService.notifyRetract( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1447 self.serviceJID, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1448 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1449 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1450 |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1451 d = self._prepareNotify(items_data, node, data.get('subscription'), pep, recipient) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1452 d.addCallback(afterPrepare) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1453 return d |
250 | 1454 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1455 @defer.inlineCallbacks |
340
567e486bce24
backend (notifications): use inline callbacks in _notifyPublish + added PEP data in _prepareNotify
Goffi <goffi@goffi.org>
parents:
339
diff
changeset
|
1456 def _prepareNotify(self, items_data, node, subscription=None, pep=None, recipient=None): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1457 """Do a bunch of permissions check and filter notifications |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1458 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1459 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
|
1460 it must be added by the calling method |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1461 @param items_data(tuple): must contain: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1462 - item (domish.Element) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1463 - access_model (unicode) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1464 - access_list (dict as returned getItemsById, or item_config) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1465 @param node(LeafNode): node hosting the items |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1466 @param subscription(pubsub.Subscription, None): TODO |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1467 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1468 @return (tuple): will contain: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1469 - notifications_filtered |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1470 - node_owner_jid |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1471 - items_data |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1472 """ |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1473 if subscription is None: |
339
516b282aa542
backend (notifications): avoid useless database request in getNotifications
Goffi <goffi@goffi.org>
parents:
336
diff
changeset
|
1474 notifications = yield 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
|
1475 else: |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1476 notifications = [(subscription.subscriber, [subscription], items_data)] |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1477 |
343
ff8aff4c9b79
backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
1478 if pep and node.getConfiguration()[const.OPT_ACCESS_MODEL] in ('open', 'presence'): |
ff8aff4c9b79
backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
1479 # 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
|
1480 explicit_subscribers = {subscriber for subscriber, _, _ in notifications} |
ff8aff4c9b79
backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
1481 auto_subscribers = yield self.backend.privilege.getAutoSubscribers(recipient, node.nodeIdentifier, explicit_subscribers) |
ff8aff4c9b79
backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
1482 for sub_jid in auto_subscribers: |
ff8aff4c9b79
backend, psql: implemented notifications for auto subscribers in PEP:
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
1483 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
|
1484 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
|
1485 |
333
0fcd0ea89c84
fixed getOwners call in _prepareNotify
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
1486 owners = yield node.getOwners() |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1487 owner_roster = None |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1488 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1489 # 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
|
1490 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1491 #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
|
1492 notifications_filtered = [] |
353
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
1493 schema = node.getSchema() |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1494 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1495 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
|
1496 subscriber_bare = subscriber.userhostJID() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1497 if subscriber_bare in owners: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1498 # 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
|
1499 # 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
|
1500 continue |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1501 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
|
1502 |
353
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
1503 if schema is not None: |
394
dc83b1d837cf
backend: fixed recursion error on getFullItem:
Goffi <goffi@goffi.org>
parents:
392
diff
changeset
|
1504 # 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
|
1505 # 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
|
1506 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
|
1507 self.backend.filterItemsWithSchema(items_data, schema, False) |
7c5d85c6fb3a
backend: enforce schema on get/publish and notifications
Goffi <goffi@goffi.org>
parents:
352
diff
changeset
|
1508 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1509 for item_data in items_data: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1510 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
|
1511 access_list = item_data.config |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1512 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
|
1513 allowed_items.append(item) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1514 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
|
1515 if owner_roster is None: |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1516 # FIXME: publisher roster should be used, not owner |
396
562e7a01218d
backend: fixed getOwnerRoster call in _prepareNotify
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
1517 owner_roster= yield self.backend.getOwnerRoster(node, owners) |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1518 if owner_roster is None: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1519 owner_roster = {} |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1520 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
|
1521 continue |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1522 #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
|
1523 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
|
1524 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
|
1525 allowed_items.append(item) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1526 else: #unknown access_model |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1527 # TODO: white list access |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1528 raise NotImplementedError |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1529 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1530 if allowed_items: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1531 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
|
1532 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1533 defer.returnValue((owners, notifications_filtered)) |
250 | 1534 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1535 def _preDelete(self, data, pep, recipient): |
261
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
1536 nodeIdentifier = data['node'].nodeIdentifier |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
1537 redirectURI = data.get('redirectURI', None) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1538 d = self.backend.getSubscribers(nodeIdentifier, pep, recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1539 d.addCallback(lambda subscribers: self.pubsubService.notifyDelete( |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1540 self.serviceJID, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1541 nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1542 subscribers, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1543 redirectURI)) |
174
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
1544 return d |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
1545 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1546 def _mapErrors(self, failure): |
414 | 1547 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
|
1548 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1549 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
|
1550 msg = failure.value.msg |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1551 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1552 if pubsubCondition: |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
1553 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
|
1554 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1555 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
|
1556 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1557 raise exc |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1558 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1559 def getInfo(self, requestor, service, nodeIdentifier, pep=None, recipient=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1560 return [] # FIXME: disabled for now, need to manage PEP |
288
073161f6f143
namespace delegation: disco nesting management
Goffi <goffi@goffi.org>
parents:
285
diff
changeset
|
1561 if not requestor.resource: |
073161f6f143
namespace delegation: disco nesting management
Goffi <goffi@goffi.org>
parents:
285
diff
changeset
|
1562 # this avoid error when getting a disco request from server during namespace delegation |
073161f6f143
namespace delegation: disco nesting management
Goffi <goffi@goffi.org>
parents:
285
diff
changeset
|
1563 return [] |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1564 info = {} |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1565 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1566 def saveType(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1567 info['type'] = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1568 return nodeIdentifier |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1569 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1570 def saveMetaData(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1571 info['meta-data'] = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1572 return info |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1573 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1574 def trapNotFound(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1575 failure.trap(error.NodeNotFound) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1576 return info |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1577 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1578 d = defer.succeed(nodeIdentifier) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1579 d.addCallback(self.backend.getNodeType) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1580 d.addCallback(saveType) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1581 d.addCallback(self.backend.getNodeMetaData) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1582 d.addCallback(saveMetaData) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1583 d.addErrback(trapNotFound) |
172
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
1584 d.addErrback(self._mapErrors) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1585 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1586 |
346 | 1587 def getNodes(self, requestor, service, nodeIdentifier): |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1588 """return nodes for disco#items |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1589 |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1590 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
|
1591 else Pubsub/PEP items will be returned |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1592 (according to what requestor can access) |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1593 """ |
346 | 1594 try: |
1595 pep = service.pep | |
1596 except AttributeError: | |
1597 pep = False | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1598 |
169
96afb248df5e
Fix typos in service creation. Make disco not respond when a resource is provided.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
1599 if service.resource: |
96afb248df5e
Fix typos in service creation. Make disco not respond when a resource is provided.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
1600 return defer.succeed([]) |
346 | 1601 |
1602 if nodeIdentifier: | |
1603 d = self.backend.getItemsIds(nodeIdentifier, | |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1604 requestor, |
346 | 1605 [], |
1606 requestor.userhostJID() == service, | |
1607 None, | |
1608 None, | |
1609 pep, | |
1610 service) | |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1611 # items must be set as name, not node |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1612 d.addCallback(lambda items: [(None, item) for item in items]) |
346 | 1613 |
1614 else: | |
349
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1615 d = self.backend.getNodes(requestor.userhostJID(), |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1616 pep, |
20b82fb8de02
backend: check nodes/items permission on disco#items:
Goffi <goffi@goffi.org>
parents:
346
diff
changeset
|
1617 service) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1618 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
|
1619 |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
1620 def getConfigurationOptions(self): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1621 return self.backend.nodeOptions |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
1622 |
228 | 1623 def _publish_errb(self, failure, request): |
1624 if failure.type == error.NodeNotFound and self.backend.supportsAutoCreate(): | |
414 | 1625 print("Auto-creating node %s" % (request.nodeIdentifier,)) |
228 | 1626 d = self.backend.createNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1627 request.sender, |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1628 request.options, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1629 pep=self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1630 recipient=request.recipient) |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1631 d.addCallback( |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1632 lambda __, request: defer.ensureDeferred(self.backend.publish( |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1633 request.nodeIdentifier, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1634 request.items, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1635 request.sender, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1636 request.options, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1637 self._isPep(request), |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1638 request.recipient, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1639 )), |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1640 request, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1641 ) |
228 | 1642 return d |
1643 | |
240
70c8bb90d75f
added access_model to config, default to 'open'
Goffi <goffi@goffi.org>
parents:
237
diff
changeset
|
1644 return failure |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
1645 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1646 def _isPep(self, request): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1647 try: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1648 return request.delegated |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1649 except AttributeError: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1650 return False |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1651 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1652 def publish(self, request): |
419
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1653 d = defer.ensureDeferred(self.backend.publish( |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1654 request.nodeIdentifier, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1655 request.items, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1656 request.sender, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1657 request.options, |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1658 self._isPep(request), |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1659 request.recipient |
794593086517
backend: publish-options implementation:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
1660 )) |
228 | 1661 d.addErrback(self._publish_errb, request) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1662 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1663 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1664 def subscribe(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1665 d = self.backend.subscribe(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1666 request.subscriber, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1667 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1668 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1669 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1670 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1671 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1672 def unsubscribe(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1673 d = self.backend.unsubscribe(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1674 request.subscriber, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1675 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1676 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1677 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1678 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1679 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1680 def subscriptions(self, request): |
354
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
1681 d = self.backend.getSubscriptions(request.sender, |
357
1167e48e5f52
handle single node on subscriptions request
Goffi <goffi@goffi.org>
parents:
355
diff
changeset
|
1682 request.nodeIdentifier, |
354
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
1683 self._isPep(request), |
18b983fe9e1b
backend: added "presence" access_model:
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
1684 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1685 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
|
1686 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1687 def affiliations(self, request): |
331 | 1688 """Retrieve affiliation for normal entity (cf. XEP-0060 §5.7) |
1689 | |
1690 retrieve all node where this jid is affiliated | |
1691 """ | |
1692 d = self.backend.getAffiliations(request.sender, | |
1693 request.nodeIdentifier, | |
1694 self._isPep(request), | |
1695 request.recipient) | |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1696 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1697 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1698 def create(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1699 d = self.backend.createNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1700 request.sender, request.options, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1701 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1702 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1703 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1704 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1705 def default(self, request): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1706 d = self.backend.getDefaultConfiguration(request.nodeType, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1707 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1708 request.sender) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1709 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1710 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1711 def configureGet(self, request): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1712 d = self.backend.getNodeConfiguration(request.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1713 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1714 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1715 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
|
1716 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1717 def configureSet(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1718 d = self.backend.setNodeConfiguration(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1719 request.options, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1720 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1721 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1722 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1723 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1724 |
331 | 1725 def affiliationsGet(self, request): |
1726 """Retrieve affiliations for owner (cf. XEP-0060 §8.9.1) | |
1727 | |
1728 retrieve all affiliations for a node | |
1729 """ | |
1730 d = self.backend.getAffiliationsOwner(request.nodeIdentifier, | |
1731 request.sender, | |
1732 self._isPep(request), | |
1733 request.recipient) | |
1734 return d.addErrback(self._mapErrors) | |
1735 | |
1736 def affiliationsSet(self, request): | |
1737 d = self.backend.setAffiliationsOwner(request.nodeIdentifier, | |
1738 request.sender, | |
1739 request.affiliations, | |
1740 self._isPep(request), | |
1741 request.recipient) | |
1742 return d.addErrback(self._mapErrors) | |
1743 | |
341
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1744 def subscriptionsGet(self, request): |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1745 """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
|
1746 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1747 retrieve all affiliations for a node |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1748 """ |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1749 d = self.backend.getSubscriptionsOwner(request.nodeIdentifier, |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1750 request.sender, |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1751 self._isPep(request), |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1752 request.recipient) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1753 return d.addErrback(self._mapErrors) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1754 |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1755 def subscriptionsSet(self, request): |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1756 d = self.backend.setSubscriptionsOwner(request.nodeIdentifier, |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1757 request.sender, |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1758 request.subscriptions, |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1759 self._isPep(request), |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1760 request.recipient) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1761 return d.addErrback(self._mapErrors) |
b49f75a26156
backend, pgsql: implemented subscriptionsGet and subscriptionsSet
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
1762 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1763 def items(self, request): |
278 | 1764 ext_data = {} |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1765 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
|
1766 if request.rsm.max < 0: |
ded7657b03fa
backend: send a BadRequest if RSM max is negative
Goffi <goffi@goffi.org>
parents:
375
diff
changeset
|
1767 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
|
1768 ext_data['rsm'] = request.rsm |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1769 try: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1770 ext_data['pep'] = request.delegated |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1771 except AttributeError: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1772 pass |
375
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1773 ext_data['order_by'] = request.orderBy or [] |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1774 d = self.backend.getItems(request.nodeIdentifier, |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1775 request.sender, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1776 request.recipient, |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1777 request.maxItems, |
278 | 1778 request.itemIdentifiers, |
1779 ext_data) | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1780 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1781 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1782 def retract(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1783 d = self.backend.retractItem(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1784 request.itemIdentifiers, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1785 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1786 request.notify, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1787 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1788 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1789 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
|
1790 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1791 def purge(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1792 d = self.backend.purgeNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1793 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1794 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1795 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1796 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
|
1797 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1798 def delete(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1799 d = self.backend.deleteNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1800 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1801 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1802 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1803 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1804 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1805 components.registerAdapter(PubSubResourceFromBackend, |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
1806 iidavoll.IBackendService, |
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
1807 iwokkel.IPubSubResource) |
375
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1808 |
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1809 |
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1810 |
414 | 1811 @implementer(iwokkel.IDisco) |
375
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1812 class ExtraDiscoHandler(XMPPHandler): |
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1813 # see comment in twisted/plugins/pubsub.py |
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1814 # 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
|
1815 |
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1816 def getDiscoInfo(self, requestor, service, nodeIdentifier=''): |
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1817 return [disco.DiscoFeature(pubsub.NS_ORDER_BY)] |
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1818 |
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1819 def getDiscoItems(self, requestor, service, nodeIdentifier=''): |
9a787881b824
implemented Order-By ProtoXEP (MAM + PubSub)
Goffi <goffi@goffi.org>
parents:
369
diff
changeset
|
1820 return [] |