Mercurial > libervia-pubsub
annotate sat_pubsub/backend.py @ 336:a468c187bbb5
fixed parseItemConfig (was iterating on children instead of elements)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 12 Aug 2017 18:10:14 +0200 |
parents | 0fcd0ea89c84 |
children | 516b282aa542 |
rev | line source |
---|---|
233 | 1 #!/usr/bin/python |
2 #-*- coding: utf-8 -*- | |
237 | 3 # |
312
5d7c3787672e
fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
4 # Copyright (c) 2012-2016 Jérôme Poisson |
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", |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
127 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
|
128 const.VAL_AMODEL_WHITELIST: "Node restricted to some jids", |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
129 } |
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 const.OPT_ROSTER_GROUPS_ALLOWED: |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
132 {"type": "list-multi", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
133 "label": "Groups of the roster allowed to access the node", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
134 }, |
260 | 135 const.OPT_PUBLISH_MODEL: |
136 {"type": "list-single", | |
137 "label": "Who can publish to this node", | |
138 "options": { | |
139 const.VAL_PMODEL_OPEN: "Everybody can publish", | |
140 const.VAL_PMODEL_PUBLISHERS: "Only owner and publishers can publish", | |
141 const.VAL_PMODEL_SUBSCRIBERS: "Everybody which subscribed to the node", | |
142 } | |
143 }, | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
144 } |
159
6fe78048baf9
Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents:
155
diff
changeset
|
145 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
146 subscriptionOptions = { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
147 "pubsub#subscription_type": |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
148 {"type": "list-single", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
149 "options": { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
150 "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
|
151 "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
|
152 }, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
153 "pubsub#subscription_depth": |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
154 {"type": "list-single", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
155 "options": { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
156 "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
|
157 "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
|
158 }, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
159 } |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
160 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
161 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
|
162 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
|
163 self.storage = storage |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
164 self._callbackList = [] |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
165 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
166 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
167 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
|
168 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
169 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
170 |
250 | 171 def supportsGroupBlog(self): |
172 return True | |
173 | |
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 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
179 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
|
180 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
181 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
182 |
260 | 183 def supportsPublishModel(self): |
184 return True | |
185 | |
186 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
187 def getNodeType(self, nodeIdentifier, pep, recipient=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
188 # FIXME: manage pep and recipient |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
189 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
|
190 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
|
191 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
192 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
193 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
194 def getNodes(self, pep): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
195 return self.storage.getNodeIds(pep) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
196 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
197 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
198 def getNodeMetaData(self, nodeIdentifier, pep, recipient=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
199 # FIXME: manage pep and recipient |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
204 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
205 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
206 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
|
207 options = [] |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
208 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
|
209 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
|
210 option = {"var": key} |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
211 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
|
212 option["value"] = value |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
213 options.append(option) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
214 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
215 return options |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
216 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
217 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
218 def _checkAuth(self, node, requestor): |
260 | 219 """ Check authorisation of publishing in node for requestor """ |
220 | |
221 def check(affiliation): | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
222 d = defer.succeed((affiliation, node)) |
260 | 223 configuration = node.getConfiguration() |
224 publish_model = configuration[const.OPT_PUBLISH_MODEL] | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
225 if publish_model == const.VAL_PMODEL_PUBLISHERS: |
260 | 226 if affiliation not in ['owner', 'publisher']: |
227 raise error.Forbidden() | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
228 elif publish_model == const.VAL_PMODEL_SUBSCRIBERS: |
260 | 229 if affiliation not in ['owner', 'publisher']: |
230 # we are in subscribers publish model, we must check that | |
231 # the requestor is a subscriber to allow him to publish | |
232 | |
233 def checkSubscription(subscribed): | |
234 if not subscribed: | |
235 raise error.Forbidden() | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
236 return (affiliation, node) |
260 | 237 |
238 d.addCallback(lambda ignore: node.isSubscribed(requestor)) | |
239 d.addCallback(checkSubscription) | |
240 elif publish_model != const.VAL_PMODEL_OPEN: | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
241 raise ValueError('Unexpected value') # publish_model must be publishers (default), subscribers or open. |
260 | 242 |
243 return d | |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
244 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
245 d = node.getAffiliation(requestor) |
260 | 246 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
|
247 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
248 |
250 | 249 def parseItemConfig(self, item): |
250 """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
|
251 |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
252 @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
|
253 @return (tuple[unicode, dict)): (access_model, item_config) |
250 | 254 """ |
255 item_config = None | |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
256 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
|
257 for idx, elt in enumerate(item.elements()): |
300 | 258 if elt.uri != 'data_form.NS_X_DATA' or elt.name != 'x': |
250 | 259 continue |
260 form = data_form.Form.fromElement(elt) | |
300 | 261 if form.formNamespace == const.NS_ITEM_CONFIG: |
250 | 262 item_config = form |
300 | 263 del item.children[idx] #we need to remove the config from item |
250 | 264 break |
265 | |
266 if item_config: | |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
267 access_model = item_config.get(const.OPT_ACCESS_MODEL, const.VAL_AMODEL_DEFAULT) |
250 | 268 return (access_model, item_config) |
269 | |
301
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
270 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
|
271 """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
|
272 |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
273 @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
|
274 @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
|
275 """ |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
276 categories = [] |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
277 try: |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
278 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
|
279 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
|
280 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
|
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 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
|
283 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
|
284 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
|
285 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
|
286 |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
287 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
|
288 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
289 def _checkOverwrite(self, node, itemIdentifiers, publisher): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
290 """Check that the itemIdentifiers correspond to items published |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
291 by the current publisher""" |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
292 def doCheck(item_pub_map): |
308
087b705493a6
fixed publisher check on item publishing
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
293 for item_publisher in item_pub_map.itervalues(): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
294 if item_publisher.userhost() != publisher.userhost(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
295 raise error.ItemForbidden() |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
296 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
297 d = node.getItemsPublishers(itemIdentifiers) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
298 d.addCallback(doCheck) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
299 return d |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
300 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
301 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
302 def publish(self, nodeIdentifier, items, requestor, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
303 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
|
304 d.addCallback(self._checkAuth, requestor) |
250 | 305 #FIXME: owner and publisher are not necessarly the same. So far we use only owner to get roster. |
306 #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
|
307 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
|
308 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
309 |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
310 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
311 def _doPublish(self, result, items, requestor, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
312 affiliation, node = result |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
313 if node.nodeType == 'collection': |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
314 raise error.NoPublishing() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
315 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
316 configuration = node.getConfiguration() |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
317 persistItems = configuration[const.OPT_PERSIST_ITEMS] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
318 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
|
319 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
320 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
|
321 raise error.ItemForbidden() |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
322 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
|
323 raise error.ItemRequired() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
324 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
325 items_data = [] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
326 check_overwrite = False |
250 | 327 for item in items: |
299 | 328 # we enforce publisher (cf XEP-0060 §7.1.2.3) |
329 item['publisher'] = requestor.full() | |
250 | 330 if persistItems or deliverPayloads: |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
331 item.uri = None |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
332 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
|
333 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
|
334 item["id"] = str(uuid.uuid4()) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
335 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
336 check_overwrite = True |
250 | 337 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
|
338 categories = self.parseCategories(item) |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
339 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
|
340 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
341 if persistItems: |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
342 if check_overwrite and affiliation != 'owner': |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
343 # 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
|
344 # of an other publisher |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
345 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
|
346 d.addCallback(lambda _: node.storeItems(items_data, requestor)) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
347 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
348 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
|
349 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
350 d = defer.succeed(None) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
351 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
352 d.addCallback(self._doNotify, node, items_data, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
353 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
|
354 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
355 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
356 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 item_data.item.children = [] |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
361 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
|
362 '//event/pubsub/notify') |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
363 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
364 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
365 def getNotifications(self, nodeDbId, items_data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
366 """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
|
367 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
368 subscribers will be associated with subscribed items, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
369 and subscription type. |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
370 """ |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
371 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
372 def toNotifications(subscriptions, items_data): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
373 subsBySubscriber = {} |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
374 for subscription in subscriptions: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
375 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
|
376 'items') == 'items': |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
377 subs = subsBySubscriber.setdefault(subscription.subscriber, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
378 set()) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
379 subs.add(subscription) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
380 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
381 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
|
382 for subscriber, subscriptions_ |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
383 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
|
384 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
385 return notifications |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
386 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
387 def rootNotFound(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
388 failure.trap(error.NodeNotFound) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
389 return [] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
390 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
391 d1 = self.storage.getNodeById(nodeDbId) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
392 d1.addCallback(lambda node: node.getSubscriptions('subscribed')) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
393 # FIXME: must add root node subscriptions ? |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
394 # d2 = self.storage.getNode('', False) # FIXME: to check |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
395 # d2.addCallback(lambda node: node.getSubscriptions('subscribed')) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
396 # d2.addErrback(rootNotFound) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
397 # d = defer.gatherResults([d1, d2]) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
398 # d.addCallback(lambda result: result[0] + result[1]) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
399 d1.addCallback(toNotifications, items_data) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
400 return d1 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
401 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
402 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
|
403 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
|
404 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
405 def registerRetractNotifier(self, observerfn, *args, **kwargs): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
406 self.addObserver('//event/pubsub/retract', observerfn, *args, **kwargs) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
407 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
408 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
|
409 subscriberEntity = subscriber.userhostJID() |
216
53d2c0019458
Fix subscription and unsubscription JID checks.
Ralph Meijer <ralphm@ik.nu>
parents:
211
diff
changeset
|
410 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
|
411 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
|
412 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
413 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
|
414 d.addCallback(_getAffiliation, subscriberEntity) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
415 d.addCallback(self._doSubscribe, subscriber) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
416 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
417 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
418 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
419 def _doSubscribe(self, result, subscriber): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
420 # TODO: implement other access models |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
421 node, affiliation = result |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
422 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
423 if affiliation == 'outcast': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
424 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
425 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
426 access_model = node.getAccessModel() |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
427 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
428 if access_model != const.VAL_AMODEL_OPEN: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
429 raise NotImplementedError |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
430 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
431 def trapExists(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
432 failure.trap(error.SubscriptionExists) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
433 return False |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
434 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
435 def cb(sendLast): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
436 d = node.getSubscription(subscriber) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
437 if sendLast: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
438 d.addCallback(self._sendLastPublished, node) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
439 return d |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
440 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
441 d = node.addSubscription(subscriber, 'subscribed', {}) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
442 d.addCallbacks(lambda _: True, trapExists) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
443 d.addCallback(cb) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
444 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
445 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
446 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
447 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
448 def _sendLastPublished(self, subscription, node): |
183
c21b986cff30
Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents:
181
diff
changeset
|
449 |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
201
diff
changeset
|
450 def notifyItem(items): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
451 if items: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
452 reactor.callLater(0, self.dispatch, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
453 {'items': items, |
261
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
454 'node': node, |
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
455 'subscription': subscription, |
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
456 }, |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
457 '//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
|
458 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
459 config = node.getConfiguration() |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
460 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
|
461 'never') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
462 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
|
463 entity = subscription.subscriber.userhostJID() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
464 d = self.getItems(node.nodeIdentifier, entity, 1) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
465 d.addCallback(notifyItem) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
466 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
|
467 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
468 return subscription |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
469 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
470 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
471 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
|
472 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
|
473 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
|
474 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
475 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
|
476 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
|
477 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
478 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
479 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
480 def getSubscriptions(self, entity): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
481 return self.storage.getSubscriptions(entity) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
482 |
228 | 483 def supportsAutoCreate(self): |
484 return True | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
485 |
237 | 486 def supportsCreatorCheck(self): |
487 return True | |
488 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
489 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
|
490 return True |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
491 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
492 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
493 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
|
494 if not nodeIdentifier: |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
495 nodeIdentifier = 'generic/%s' % uuid.uuid4() |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
496 |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
497 if not options: |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
498 options = {} |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
499 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
500 # if self.supportsCreatorCheck(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
501 # groupblog = nodeIdentifier.startswith(const.NS_GROUPBLOG_PREFIX) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
502 # try: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
503 # 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
|
504 # except InvalidFormat: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
505 # is_user_jid = False |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
506 # else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
507 # 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
|
508 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
509 # if is_user_jid and nodeIdentifierJID.userhostJID() != requestor.userhostJID(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
510 # #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
|
511 # print "Wrong creator" |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
512 # raise error.Forbidden() |
237 | 513 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
514 nodeType = 'leaf' |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
515 config = self.storage.getDefaultConfiguration(nodeType) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
516 config['pubsub#node_type'] = nodeType |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
517 config.update(options) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
518 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
519 d = self.storage.createNode(nodeIdentifier, requestor, config, pep, recipient) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
520 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
|
521 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
522 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
523 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
524 def getDefaultConfiguration(self, nodeType): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
525 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
|
526 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
527 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
528 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
529 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
|
530 if not nodeIdentifier: |
196
00a6dbfbee42
Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents:
183
diff
changeset
|
531 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
|
532 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
533 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
|
534 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
|
535 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
536 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
537 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
538 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
539 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
|
540 if not nodeIdentifier: |
196
00a6dbfbee42
Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents:
183
diff
changeset
|
541 return defer.fail(error.NoRootNode()) |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
542 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
543 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
|
544 d.addCallback(_getAffiliation, requestor) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
545 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
|
546 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
547 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
548 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
549 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
|
550 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
551 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
552 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
553 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
554 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
555 return node.setConfiguration(options) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
556 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
557 |
331 | 558 def getAffiliations(self, entity, nodeIdentifier, pep, recipient): |
559 return self.storage.getAffiliations(entity, nodeIdentifier, pep, recipient) | |
560 | |
561 | |
562 def getAffiliationsOwner(self, nodeIdentifier, requestor, pep, recipient): | |
563 d = self.storage.getNode(nodeIdentifier, pep, recipient) | |
564 d.addCallback(_getAffiliation, requestor) | |
565 d.addCallback(self._doGetAffiliationsOwner) | |
566 return d | |
567 | |
568 | |
569 def _doGetAffiliationsOwner(self, result): | |
570 node, affiliation = result | |
571 | |
572 if affiliation != 'owner': | |
573 raise error.Forbidden() | |
574 return node.getAffiliations() | |
575 | |
576 | |
577 def setAffiliationsOwner(self, nodeIdentifier, requestor, affiliations, pep, recipient): | |
578 d = self.storage.getNode(nodeIdentifier, pep, recipient) | |
579 d.addCallback(_getAffiliation, requestor) | |
580 d.addCallback(self._doSetAffiliationsOwner, requestor, affiliations) | |
581 return d | |
582 | |
583 | |
584 def _doSetAffiliationsOwner(self, result, requestor, affiliations): | |
585 # Check that requestor is allowed to set affiliations, and delete entities | |
586 # with "none" affiliation | |
587 | |
588 # TODO: return error with failed affiliations in case of failure | |
589 node, requestor_affiliation = result | |
590 | |
591 if requestor_affiliation != 'owner': | |
592 raise error.Forbidden() | |
593 | |
594 # we don't allow requestor to change its own affiliation | |
595 requestor_bare = requestor.userhostJID() | |
596 if requestor_bare in affiliations and affiliations[requestor_bare] != 'owner': | |
597 # FIXME: it may be interesting to allow the owner to ask for ownership removal | |
598 # if at least one other entity is owner for this node | |
599 raise error.Forbidden("You can't change your own affiliation") | |
600 | |
601 to_delete = [jid_ for jid_, affiliation in affiliations.iteritems() if affiliation == 'none'] | |
602 for jid_ in to_delete: | |
603 del affiliations[jid_] | |
604 | |
605 if to_delete: | |
606 d = node.deleteAffiliations(to_delete) | |
607 if affiliations: | |
608 d.addCallback(lambda dummy: node.setAffiliations(affiliations)) | |
609 else: | |
610 d = node.setAffiliations(affiliations) | |
611 | |
612 return d | |
167
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 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
615 def getItems(self, nodeIdentifier, requestor, recipient, maxItems=None, |
278 | 616 itemIdentifiers=None, ext_data=None): |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
617 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
|
618 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
|
619 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
|
620 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
621 @defer.inlineCallbacks |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
622 def getOwnerRoster(self, node, owners=None): |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
623 if owners is None: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
624 owners = yield node.getOwners() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
625 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
626 if len(owners) != 1: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
627 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
|
628 return |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
629 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
630 owner_jid = owners[0] |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
631 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
632 try: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
633 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
|
634 except Exception as e: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
635 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
|
636 owner_jid = owner_jid.full(), |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
637 msg = e)) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
638 return |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
639 defer.returnValue(roster) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
640 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
641 @defer.inlineCallbacks |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
642 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
|
643 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
|
644 """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
|
645 if maxItems == 0: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
646 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
|
647 defer.returnValue([]) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
648 |
278 | 649 if ext_data is None: |
650 ext_data = {} | |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
651 node = yield self.storage.getNode(nodeIdentifier, ext_data.get('pep', False), recipient) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
652 node, affiliation = yield _getAffiliation(node, requestor) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
653 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
654 if not iidavoll.ILeafNode.providedBy(node): |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
655 defer.returnValue([]) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
656 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
657 if affiliation == 'outcast': |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
658 raise error.Forbidden() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
659 |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
660 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
661 # node access check |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
662 owner = affiliation == 'owner' |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
663 access_model = node.getAccessModel() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
664 roster = None |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
665 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
666 if access_model == const.VAL_AMODEL_OPEN or owner: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
667 pass |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
668 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
|
669 roster = yield self.getOwnerRoster(node) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
670 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
671 if roster is None: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
672 raise error.Forbidden() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
673 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
674 if requestor not in roster: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
675 raise error.Forbidden() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
676 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
677 authorized_groups = yield node.getAuthorizedGroups() |
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
|
678 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
679 if not roster[requestor].groups.intersection(authorized_groups): |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
680 # requestor is in roster but not in one of the allowed groups |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
681 raise error.Forbidden() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
682 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
|
683 affiliations = yield node.getAffiliations() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
684 try: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
685 affiliation = affiliations[requestor.userhostJID()] |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
686 except KeyError: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
687 raise error.Forbidden() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
688 else: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
689 if affiliation not in ('owner', 'publisher', 'member'): |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
690 raise error.Forbidden() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
691 else: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
692 raise Exception(u"Unknown access_model") |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
693 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
694 # 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
|
695 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
696 if owner: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
697 # 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
|
698 requestor_groups = None |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
699 else: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
700 if roster is None: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
701 roster = yield self.getOwnerRoster(node) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
702 if roster is None: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
703 roster = {} |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
704 roster_item = roster.get(requestor.userhostJID()) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
705 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
|
706 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
707 if itemIdentifiers: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
708 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
|
709 else: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
710 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
|
711 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
712 if owner: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
713 # 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
|
714 for item_data in items_data: |
318 | 715 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
|
716 pass |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
717 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
|
718 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
|
719 access = data_form.Field(None, const.OPT_ACCESS_MODEL, value=const.VAL_AMODEL_PUBLISHER_ROSTER) |
318 | 720 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
|
721 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
|
722 form.addField(allowed) |
318 | 723 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
|
724 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
|
725 #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
|
726 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
|
727 else: |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
728 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
|
729 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
730 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
|
731 defer.returnValue(items_data) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
732 |
315
720d73e30bf7
backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents:
314
diff
changeset
|
733 def _setCount(self, value, response): |
720d73e30bf7
backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents:
314
diff
changeset
|
734 response.count = value |
720d73e30bf7
backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents:
314
diff
changeset
|
735 |
318 | 736 def _setIndex(self, value, response, adjust): |
737 """Set index in RSM response | |
738 | |
739 @param value(int): value of the reference index (i.e. before or after item) | |
740 @param response(RSMResponse): response instance to fill | |
741 @param adjust(int): adjustement term (i.e. difference between reference index and first item of the result) | |
742 """ | |
743 response.index = value + adjust | |
315
720d73e30bf7
backend (rsm): replaced setattr use by methods for better performances
Goffi <goffi@goffi.org>
parents:
314
diff
changeset
|
744 |
318 | 745 def _items_rsm(self, items_data, node, authorized_groups, owner, |
746 itemIdentifiers, ext_data): | |
747 # FIXME: move this to a separate module | |
748 # TODO: Index can be optimized by keeping a cache of the last RSM request | |
749 # An other optimisation would be to look for index first and use it as offset | |
750 try: | |
751 rsm_request = ext_data['rsm'] | |
752 except KeyError: | |
753 # No RSM in this request, nothing to do | |
754 return items_data | |
755 | |
756 if itemIdentifiers: | |
757 log.msg("WARNING, itemIdentifiers used with RSM, ignoring the RSM part") | |
758 return items_data | |
759 | |
278 | 760 response = rsm.RSMResponse() |
761 | |
318 | 762 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
|
763 d_count.addCallback(self._setCount, response) |
278 | 764 d_list = [d_count] |
765 | |
318 | 766 if items_data: |
767 response.first = items_data[0].item['id'] | |
768 response.last = items_data[-1].item['id'] | |
769 | |
770 # index handling | |
771 if rsm_request.index is not None: | |
772 response.index = rsm_request.index | |
773 elif rsm_request.before: | |
774 # The last page case (before == '') is managed in render method | |
775 d_index = node.getItemsIndex(rsm_request.before, authorized_groups, owner, ext_data) | |
776 d_index.addCallback(self._setIndex, response, -len(items_data)) | |
278 | 777 d_list.append(d_index) |
318 | 778 elif rsm_request.after is not None: |
779 d_index = node.getItemsIndex(rsm_request.after, authorized_groups, owner, ext_data) | |
780 d_index.addCallback(self._setIndex, response, 1) | |
781 d_list.append(d_index) | |
782 else: | |
783 # the first page was requested | |
784 response.index = 0 | |
278 | 785 |
786 def render(result): | |
318 | 787 if rsm_request.before == '': |
788 # the last page was requested | |
789 response.index = response.count - len(items_data) | |
790 items_data.append(container.ItemData(response.toElement())) | |
791 return items_data | |
278 | 792 |
793 return defer.DeferredList(d_list).addCallback(render) | |
794 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
795 def retractItem(self, nodeIdentifier, itemIdentifiers, requestor, notify, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
796 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
|
797 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
|
798 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
|
799 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
800 |
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
|
801 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
|
802 node, affiliation = result |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
803 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
|
804 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
805 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
|
806 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
807 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
808 # 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
|
809 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
810 def removeItems(items_data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
811 """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
|
812 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
|
813 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
|
814 return d |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
815 |
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
|
816 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
|
817 """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
|
818 |
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
|
819 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
|
820 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
|
821 """ |
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
|
822 # 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
|
823 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
|
824 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
|
825 |
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
|
826 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
|
827 # 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
|
828 # 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
|
829 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
|
830 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
|
831 # 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
|
832 # 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
|
833 # 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
|
834 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
|
835 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
|
836 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
|
837 d.addCallback(removeItems) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
838 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
839 if notify: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
840 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
|
841 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
842 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
843 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
844 def _doNotifyRetraction(self, items_data, node, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
845 self.dispatch({'items_data': items_data, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
846 'node': node, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
847 'pep': pep, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
848 'recipient': recipient}, |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
849 '//event/pubsub/retract') |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
850 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
851 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
852 def purgeNode(self, nodeIdentifier, requestor, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
853 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
|
854 d.addCallback(_getAffiliation, requestor) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
855 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
|
856 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
857 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
858 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
859 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
|
860 node, affiliation = result |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
861 persistItems = node.getConfiguration()[const.OPT_PERSIST_ITEMS] |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
862 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
863 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
864 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
865 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
866 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
|
867 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
868 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
869 d = node.purge() |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
870 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
|
871 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
872 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
873 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
874 def _doNotifyPurge(self, result, nodeIdentifier): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
875 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
|
876 |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
877 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
878 def registerPreDelete(self, preDeleteFn): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
879 self._callbackList.append(preDeleteFn) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
880 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
881 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
882 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
|
883 def cb(subscriptions): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
884 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
|
885 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
886 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
|
887 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
|
888 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
|
889 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
890 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
891 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
892 def deleteNode(self, nodeIdentifier, requestor, pep, recipient, redirectURI=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
893 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
|
894 d.addCallback(_getAffiliation, requestor) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
895 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
|
896 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
897 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
898 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
899 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
|
900 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
901 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
902 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
903 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
904 |
261
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
905 data = {'node': node, |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
906 'redirectURI': redirectURI} |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
907 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
908 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
|
909 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
|
910 consumeErrors=1) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
911 d.addCallback(self._doDelete, node.nodeDbId) |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
912 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
913 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
914 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
|
915 dl = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
916 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
|
917 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
|
918 dl.extend(r) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
919 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
920 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
|
921 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
|
922 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
923 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
924 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
925 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
926 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
|
927 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
|
928 d.callback(None) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
929 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
930 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
931 |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
932 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
|
933 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
934 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
|
935 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
936 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
937 features = [ |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
938 "config-node", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
939 "create-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
940 "delete-any", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
941 "delete-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
942 "item-ids", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
943 "meta-data", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
944 "publish", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
945 "purge-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
946 "retract-items", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
947 "retrieve-affiliations", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
948 "retrieve-default", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
949 "retrieve-items", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
950 "retrieve-subscriptions", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
951 "subscribe", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
952 ] |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
953 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
954 discoIdentity = disco.DiscoIdentity('pubsub', |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
955 'service', |
236
65bc75603539
renamed service to « Salut à Toi pubsub service »
Goffi <goffi@goffi.org>
parents:
235
diff
changeset
|
956 u'Salut à Toi pubsub service') |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
957 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
958 pubsubService = None |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
959 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
960 _errorMap = { |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
961 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
|
962 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
|
963 error.Forbidden: ('forbidden', None, None), |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
964 error.NotAuthorized: ('not-authorized', None, None), |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
965 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
|
966 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
|
967 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
|
968 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
|
969 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
970 'instant-nodes'), |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
971 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
|
972 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
|
973 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
|
974 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
|
975 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
976 'persistent-node'), |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
977 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
|
978 error.NoCollections: ('feature-not-implemented', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
979 'unsupported', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
980 'collections'), |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
981 error.NoPublishing: ('feature-not-implemented', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
982 'unsupported', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
983 'publish'), |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
984 } |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
985 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
986 def __init__(self, backend): |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
987 pubsub.PubSubResource.__init__(self) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
988 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
989 self.backend = backend |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
990 self.hideNodes = False |
153 | 991 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
992 self.backend.registerPublishNotifier(self._notifyPublish) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
993 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
|
994 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
|
995 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
996 # 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
|
997 # if self.backend.supportsCreatorCheck(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
998 # self.features.append("creator-jid-check") #SàT custom feature: Check that a node (which correspond to |
237 | 999 # 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
|
1000 |
228 | 1001 if self.backend.supportsAutoCreate(): |
1002 self.features.append("auto-create") | |
1003 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1004 if self.backend.supportsInstantNodes(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1005 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
|
1006 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1007 if self.backend.supportsOutcastAffiliation(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1008 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
|
1009 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1010 if self.backend.supportsPersistentItems(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1011 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
|
1012 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1013 if self.backend.supportsPublisherAffiliation(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1014 self.features.append("publisher-affiliation") |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1015 |
250 | 1016 if self.backend.supportsGroupBlog(): |
1017 self.features.append("groupblog") | |
1018 | |
260 | 1019 # if self.backend.supportsPublishModel(): #XXX: this feature is not really described in XEP-0060, we just can see it in examples |
1020 # self.features.append("publish_model") # but it's necessary for microblogging comments (see XEP-0277) | |
1021 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1022 def _notifyPublish(self, data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1023 items_data = data['items_data'] |
250 | 1024 node = data['node'] |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1025 pep = data['pep'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1026 recipient = data['recipient'] |
250 | 1027 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1028 def afterPrepare(result): |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1029 owners, notifications_filtered = result |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1030 #we notify the owners |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1031 #FIXME: check if this comply with XEP-0060 (option needed ?) |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1032 #TODO: item's access model have to be sent back to owner |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1033 #TODO: same thing for getItems |
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
|
1034 |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1035 def getFullItem(item_data): |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1036 """ Attach item configuration to this item |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1037 Used to give item configuration back to node's owner (and *only* to owner) |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1038 """ |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1039 #TODO: a test should check that only the owner get the item configuration back |
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
|
1040 |
301
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
300
diff
changeset
|
1041 item, item_config = item_data.item, item_data.config |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1042 new_item = deepcopy(item) |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1043 if item_config: |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1044 new_item.addChild(item_config.toElement()) |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1045 return new_item |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
1046 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1047 for owner_jid in owners: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1048 notifications_filtered.append( |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1049 (owner_jid, |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1050 set([pubsub.Subscription(node.nodeIdentifier, |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1051 owner_jid, |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1052 'subscribed')]), |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1053 [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
|
1054 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1055 if pep: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1056 return self.backend.privilege.notifyPublish( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1057 recipient, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1058 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1059 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1060 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1061 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1062 return self.pubsubService.notifyPublish( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1063 self.serviceJID, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1064 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1065 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1066 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1067 d = self._prepareNotify(items_data, node, data.get('subscription')) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1068 d.addCallback(afterPrepare) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1069 return d |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1070 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1071 def _notifyRetract(self, data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1072 items_data = data['items_data'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1073 node = data['node'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1074 pep = data['pep'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1075 recipient = data['recipient'] |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1076 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1077 def afterPrepare(result): |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1078 owners, notifications_filtered = result |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1079 #we add the owners |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1080 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1081 for owner_jid in owners: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1082 notifications_filtered.append( |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1083 (owner_jid, |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1084 set([pubsub.Subscription(node.nodeIdentifier, |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1085 owner_jid, |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1086 'subscribed')]), |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1087 [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
|
1088 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1089 if pep: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1090 return self.backend.privilege.notifyRetract( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1091 recipient, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1092 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1093 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1094 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1095 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1096 return self.pubsubService.notifyRetract( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1097 self.serviceJID, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1098 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1099 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1100 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1101 d = self._prepareNotify(items_data, node, data.get('subscription')) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1102 d.addCallback(afterPrepare) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1103 return d |
250 | 1104 |
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
|
1105 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1106 @defer.inlineCallbacks |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1107 def _prepareNotify(self, items_data, node, subscription=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1108 """Do a bunch of permissions check and filter notifications |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1109 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1110 The owner is not added to these notifications, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1111 it must be called by the calling method |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1112 @param items_data(tuple): must contain: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1113 - item (domish.Element) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1114 - access_model (unicode) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1115 - access_list (dict as returned getItemsById, or item_config) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1116 @param node(LeafNode): node hosting the items |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1117 @param subscription(pubsub.Subscription, None): TODO |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1118 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1119 @return (tuple): will contain: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1120 - notifications_filtered |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1121 - node_owner_jid |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1122 - items_data |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1123 """ |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1124 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1125 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1126 if subscription is None: |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1127 notifications = yield self.backend.getNotifications(node.nodeDbId, items_data) |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
1128 else: |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1129 notifications = [(subscription.subscriber, [subscription], items_data)] |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1130 |
333
0fcd0ea89c84
fixed getOwners call in _prepareNotify
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
1131 owners = yield node.getOwners() |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1132 owner_roster = None |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1133 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1134 # 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
|
1135 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1136 #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
|
1137 notifications_filtered = [] |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1138 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1139 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
|
1140 subscriber_bare = subscriber.userhostJID() |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1141 if subscriber_bare in owners: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1142 # 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
|
1143 # 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
|
1144 continue |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1145 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
|
1146 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1147 for item_data in items_data: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1148 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
|
1149 access_list = item_data.config |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1150 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
|
1151 allowed_items.append(item) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1152 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
|
1153 if owner_roster is None: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1154 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
|
1155 if owner_roster is None: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1156 owner_roster = {} |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1157 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
|
1158 continue |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1159 #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
|
1160 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
|
1161 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
|
1162 allowed_items.append(item) |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1163 else: #unknown access_model |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1164 # TODO: white list access |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1165 raise NotImplementedError |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1166 |
330
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1167 if allowed_items: |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1168 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
|
1169 |
82d1259b3e36
backend, pgsql storage: better items/notification handling, various fixes:
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
1170 defer.returnValue((owners, notifications_filtered)) |
250 | 1171 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1172 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
|
1173 nodeIdentifier = data['node'].nodeIdentifier |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
1174 redirectURI = data.get('redirectURI', None) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1175 d = self.backend.getSubscribers(nodeIdentifier, pep, recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1176 d.addCallback(lambda subscribers: self.pubsubService.notifyDelete( |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1177 self.serviceJID, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1178 nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1179 subscribers, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1180 redirectURI)) |
174
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
1181 return d |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
1182 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1183 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
|
1184 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
|
1185 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1186 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
|
1187 msg = failure.value.msg |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1188 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1189 if pubsubCondition: |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
1190 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
|
1191 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1192 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
|
1193 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1194 raise exc |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1195 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1196 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
|
1197 return [] # FIXME: disabled for now, need to manage PEP |
288
073161f6f143
namespace delegation: disco nesting management
Goffi <goffi@goffi.org>
parents:
285
diff
changeset
|
1198 if not requestor.resource: |
073161f6f143
namespace delegation: disco nesting management
Goffi <goffi@goffi.org>
parents:
285
diff
changeset
|
1199 # 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
|
1200 return [] |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1201 info = {} |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1202 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1203 def saveType(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1204 info['type'] = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1205 return nodeIdentifier |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1206 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1207 def saveMetaData(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1208 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
|
1209 return info |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1210 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1211 def trapNotFound(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1212 failure.trap(error.NodeNotFound) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1213 return info |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1214 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1215 d = defer.succeed(nodeIdentifier) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1216 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
|
1217 d.addCallback(saveType) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1218 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
|
1219 d.addCallback(saveMetaData) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1220 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
|
1221 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
|
1222 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1223 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1224 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1225 def getNodes(self, requestor, service, nodeIdentifier, pep=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1226 return defer.succeed([]) # FIXME: disabled for now, need to manage PEP |
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
|
1227 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
|
1228 return defer.succeed([]) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1229 d = self.backend.getNodes(pep) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1230 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
|
1231 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1232 |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
1233 def getConfigurationOptions(self): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1234 return self.backend.nodeOptions |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
1235 |
228 | 1236 def _publish_errb(self, failure, request): |
1237 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
|
1238 print "Auto-creating node %s" % (request.nodeIdentifier,) |
228 | 1239 d = self.backend.createNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1240 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1241 pep=self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1242 recipient=request.recipient) |
228 | 1243 d.addCallback(lambda ignore, |
1244 request: self.backend.publish(request.nodeIdentifier, | |
1245 request.items, | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1246 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1247 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1248 request.recipient, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1249 ), |
228 | 1250 request) |
1251 return d | |
1252 | |
240
70c8bb90d75f
added access_model to config, default to 'open'
Goffi <goffi@goffi.org>
parents:
237
diff
changeset
|
1253 return failure |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
1254 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1255 def _isPep(self, request): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1256 try: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1257 return request.delegated |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1258 except AttributeError: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1259 return False |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1260 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1261 def publish(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1262 d = self.backend.publish(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1263 request.items, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1264 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1265 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1266 request.recipient) |
228 | 1267 d.addErrback(self._publish_errb, request) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1268 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1269 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1270 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1271 def subscribe(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1272 d = self.backend.subscribe(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1273 request.subscriber, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1274 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1275 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1276 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1277 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1278 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1279 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1280 def unsubscribe(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1281 d = self.backend.unsubscribe(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1282 request.subscriber, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1283 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1284 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1285 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1286 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1287 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1288 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1289 def subscriptions(self, request): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1290 d = self.backend.getSubscriptions(self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1291 request.sender) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1292 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
|
1293 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1294 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1295 def affiliations(self, request): |
331 | 1296 """Retrieve affiliation for normal entity (cf. XEP-0060 §5.7) |
1297 | |
1298 retrieve all node where this jid is affiliated | |
1299 """ | |
1300 d = self.backend.getAffiliations(request.sender, | |
1301 request.nodeIdentifier, | |
1302 self._isPep(request), | |
1303 request.recipient) | |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1304 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1305 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1306 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1307 def create(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1308 d = self.backend.createNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1309 request.sender, request.options, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1310 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1311 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1312 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1313 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1314 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1315 def default(self, request): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1316 d = self.backend.getDefaultConfiguration(request.nodeType, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1317 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1318 request.sender) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1319 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1320 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1321 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1322 def configureGet(self, request): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1323 d = self.backend.getNodeConfiguration(request.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1324 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1325 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1326 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
|
1327 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1328 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1329 def configureSet(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1330 d = self.backend.setNodeConfiguration(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1331 request.options, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1332 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1333 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1334 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1335 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1336 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1337 |
331 | 1338 def affiliationsGet(self, request): |
1339 """Retrieve affiliations for owner (cf. XEP-0060 §8.9.1) | |
1340 | |
1341 retrieve all affiliations for a node | |
1342 """ | |
1343 d = self.backend.getAffiliationsOwner(request.nodeIdentifier, | |
1344 request.sender, | |
1345 self._isPep(request), | |
1346 request.recipient) | |
1347 return d.addErrback(self._mapErrors) | |
1348 | |
1349 def affiliationsSet(self, request): | |
1350 d = self.backend.setAffiliationsOwner(request.nodeIdentifier, | |
1351 request.sender, | |
1352 request.affiliations, | |
1353 self._isPep(request), | |
1354 request.recipient) | |
1355 return d.addErrback(self._mapErrors) | |
1356 | |
1357 | |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1358 def items(self, request): |
278 | 1359 ext_data = {} |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1360 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
|
1361 ext_data['rsm'] = request.rsm |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1362 try: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1363 ext_data['pep'] = request.delegated |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1364 except AttributeError: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1365 pass |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1366 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
|
1367 request.sender, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1368 request.recipient, |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1369 request.maxItems, |
278 | 1370 request.itemIdentifiers, |
1371 ext_data) | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1372 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1373 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1374 def retract(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1375 d = self.backend.retractItem(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1376 request.itemIdentifiers, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1377 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1378 request.notify, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1379 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1380 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1381 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
|
1382 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1383 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1384 def purge(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1385 d = self.backend.purgeNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1386 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1387 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1388 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1389 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
|
1390 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1391 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1392 def delete(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1393 d = self.backend.deleteNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1394 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1395 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1396 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1397 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1398 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1399 components.registerAdapter(PubSubResourceFromBackend, |
317
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
1400 iidavoll.IBackendService, |
34adc4a8aa64
new container module, with an ItemData container:
Goffi <goffi@goffi.org>
parents:
315
diff
changeset
|
1401 iwokkel.IPubSubResource) |