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