Mercurial > libervia-pubsub
annotate sat_pubsub/backend.py @ 300:c5acb4995fde
cleaner parseItemConfig
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 25 Nov 2015 16:00:08 +0100 |
parents | 07ad8d8fde77 |
children | 05c875a13a62 |
rev | line source |
---|---|
233 | 1 #!/usr/bin/python |
2 #-*- coding: utf-8 -*- | |
237 | 3 # |
233 | 4 """ |
235
64f780413b82
fixed Ralph Meijer copyright years (last commit was in 2011, not in 2009)
Goffi <goffi@goffi.org>
parents:
234
diff
changeset
|
5 Copyright (c) 2003-2011 Ralph Meijer |
283 | 6 Copyright (c) 2012, 2013, 2014, 2015 Jérôme Poisson |
233 | 7 |
8 | |
9 This program is free software: you can redistribute it and/or modify | |
10 it under the terms of the GNU Affero General Public License as published by | |
11 the Free Software Foundation, either version 3 of the License, or | |
12 (at your option) any later version. | |
13 | |
14 This program is distributed in the hope that it will be useful, | |
15 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 GNU Affero General Public License for more details. | |
18 | |
19 You should have received a copy of the GNU Affero General Public License | |
20 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 -- | |
22 | |
23 This program is based on Idavoll (http://idavoll.ik.nu/), | |
24 originaly written by Ralph Meijer (http://ralphm.net/blog/) | |
25 It is sublicensed under AGPL v3 (or any later version) as allowed by the original | |
26 license. | |
27 | |
28 -- | |
29 | |
30 Here is a copy of the original license: | |
31 | |
235
64f780413b82
fixed Ralph Meijer copyright years (last commit was in 2011, not in 2009)
Goffi <goffi@goffi.org>
parents:
234
diff
changeset
|
32 Copyright (c) 2003-2011 Ralph Meijer |
233 | 33 |
34 Permission is hereby granted, free of charge, to any person obtaining | |
35 a copy of this software and associated documentation files (the | |
36 "Software"), to deal in the Software without restriction, including | |
37 without limitation the rights to use, copy, modify, merge, publish, | |
38 distribute, sublicense, and/or sell copies of the Software, and to | |
39 permit persons to whom the Software is furnished to do so, subject to | |
40 the following conditions: | |
41 | |
42 The above copyright notice and this permission notice shall be | |
43 included in all copies or substantial portions of the Software. | |
44 | |
45 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
46 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
47 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
48 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
49 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
50 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
51 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
52 | |
53 """ | |
155
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
153
diff
changeset
|
54 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
55 """ |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
56 Generic publish-subscribe backend. |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
57 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
58 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
|
59 business logic as per |
200 | 60 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
|
61 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
|
62 publish-subscribe protocol. |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
63 """ |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
64 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
65 import uuid |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
66 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
67 from zope.interface import implements |
2 | 68 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
69 from twisted.application import service |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
70 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
|
71 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
|
72 from twisted.words.protocols.jabber.error import StanzaError |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
73 # 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
|
74 from twisted.words.xish import utility |
1 | 75 |
278 | 76 from wokkel import disco, data_form, rsm |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
77 from wokkel.iwokkel import IPubSubResource |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
78 from wokkel.pubsub import PubSubResource, PubSubError, Subscription |
20
eddea65d1032
Added two exceptions: NoInstantNodes and NodeExists.
Ralph Meijer <ralphm@ik.nu>
parents:
18
diff
changeset
|
79 |
250 | 80 from sat_pubsub import error, iidavoll, const |
234
51af2ed8bd50
replaced idavoll imports by sat_pubsub imports
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
81 from sat_pubsub.iidavoll import IBackendService, ILeafNode |
15 | 82 |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
83 from copy import deepcopy |
250 | 84 |
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
|
85 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
86 def _getAffiliation(node, entity): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
87 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
|
88 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
|
89 return d |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
20
diff
changeset
|
90 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
91 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
92 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
|
93 """ |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
94 Generic publish-subscribe backend service. |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
95 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
96 @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
|
97 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
|
98 and possible options to choose from. |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
99 @type nodeOptions: C{dict}. |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
100 @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
|
101 """ |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
102 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
103 implements(iidavoll.IBackendService) |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
104 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
105 nodeOptions = { |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
106 const.OPT_PERSIST_ITEMS: |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
107 {"type": "boolean", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
108 "label": "Persist items to storage"}, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
109 const.OPT_DELIVER_PAYLOADS: |
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": "Deliver payloads with event notifications"}, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
112 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
|
113 {"type": "list-single", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
114 "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
|
115 "options": { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
116 "never": "Never", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
117 "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
|
118 }, |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
119 const.OPT_ACCESS_MODEL: |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
120 {"type": "list-single", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
121 "label": "Who can subscribe to this node", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
122 "options": { |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
123 const.VAL_AMODEL_OPEN: "Public node", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
124 const.VAL_AMODEL_ROSTER: "Node restricted to some roster groups", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
125 const.VAL_AMODEL_JID: "Node restricted to some jids", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
126 } |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
127 }, |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
128 const.OPT_ROSTER_GROUPS_ALLOWED: |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
129 {"type": "list-multi", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
130 "label": "Groups of the roster allowed to access the node", |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
131 }, |
260 | 132 const.OPT_PUBLISH_MODEL: |
133 {"type": "list-single", | |
134 "label": "Who can publish to this node", | |
135 "options": { | |
136 const.VAL_PMODEL_OPEN: "Everybody can publish", | |
137 const.VAL_PMODEL_PUBLISHERS: "Only owner and publishers can publish", | |
138 const.VAL_PMODEL_SUBSCRIBERS: "Everybody which subscribed to the node", | |
139 } | |
140 }, | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
141 } |
159
6fe78048baf9
Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents:
155
diff
changeset
|
142 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
143 subscriptionOptions = { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
144 "pubsub#subscription_type": |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
145 {"type": "list-single", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
146 "options": { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
147 "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
|
148 "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
|
149 }, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
150 "pubsub#subscription_depth": |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
151 {"type": "list-single", |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
152 "options": { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
153 "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
|
154 "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
|
155 }, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
156 } |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
157 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
158 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
|
159 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
|
160 self.storage = storage |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
161 self._callbackList = [] |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
162 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
163 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
164 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
|
165 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
166 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
167 |
250 | 168 def supportsGroupBlog(self): |
169 return True | |
170 | |
171 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
172 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
|
173 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
174 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
175 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
176 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
|
177 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
178 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
179 |
260 | 180 def supportsPublishModel(self): |
181 return True | |
182 | |
183 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
184 def getNodeType(self, nodeIdentifier, pep, recipient=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
185 # FIXME: manage pep and recipient |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
186 d = self.storage.getNode(nodeIdentifier, pep, recipient) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
187 d.addCallback(lambda node: node.getType()) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
188 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
189 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
190 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
191 def getNodes(self, pep): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
192 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
|
193 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
194 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
195 def getNodeMetaData(self, nodeIdentifier, pep, recipient=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
196 # FIXME: manage pep and recipient |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
201 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
202 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
203 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
|
204 options = [] |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
205 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
|
206 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
|
207 option = {"var": key} |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
208 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
|
209 option["value"] = value |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
210 options.append(option) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
211 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
212 return options |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
213 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
214 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
215 def _checkAuth(self, node, requestor): |
260 | 216 """ Check authorisation of publishing in node for requestor """ |
217 | |
218 def check(affiliation): | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
219 d = defer.succeed((affiliation, node)) |
260 | 220 configuration = node.getConfiguration() |
221 publish_model = configuration[const.OPT_PUBLISH_MODEL] | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
222 if publish_model == const.VAL_PMODEL_PUBLISHERS: |
260 | 223 if affiliation not in ['owner', 'publisher']: |
224 raise error.Forbidden() | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
225 elif publish_model == const.VAL_PMODEL_SUBSCRIBERS: |
260 | 226 if affiliation not in ['owner', 'publisher']: |
227 # we are in subscribers publish model, we must check that | |
228 # the requestor is a subscriber to allow him to publish | |
229 | |
230 def checkSubscription(subscribed): | |
231 if not subscribed: | |
232 raise error.Forbidden() | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
233 return (affiliation, node) |
260 | 234 |
235 d.addCallback(lambda ignore: node.isSubscribed(requestor)) | |
236 d.addCallback(checkSubscription) | |
237 elif publish_model != const.VAL_PMODEL_OPEN: | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
238 raise ValueError('Unexpected value') # publish_model must be publishers (default), subscribers or open. |
260 | 239 |
240 return d | |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
241 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
242 d = node.getAffiliation(requestor) |
260 | 243 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
|
244 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
245 |
250 | 246 def parseItemConfig(self, item): |
247 """Get and remove item configuration information | |
248 @param item: | |
249 """ | |
250 item_config = None | |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
251 access_model = const.VAL_AMODEL_DEFAULT |
300 | 252 for idx, elt in enumerate(item.children): |
253 if elt.uri != 'data_form.NS_X_DATA' or elt.name != 'x': | |
250 | 254 continue |
255 form = data_form.Form.fromElement(elt) | |
300 | 256 if form.formNamespace == const.NS_ITEM_CONFIG: |
250 | 257 item_config = form |
300 | 258 del item.children[idx] #we need to remove the config from item |
250 | 259 break |
260 | |
261 if item_config: | |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
262 access_model = item_config.get(const.OPT_ACCESS_MODEL, const.VAL_AMODEL_DEFAULT) |
250 | 263 return (access_model, item_config) |
264 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
265 def _checkOverwrite(self, node, itemIdentifiers, publisher): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
266 """Check that the itemIdentifiers correspond to items published |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
267 by the current publisher""" |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
268 def doCheck(item_pub_map): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
269 for item_publisher in item_pub_map.iterValues(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
270 if item_publisher.userhost() != publisher.userhost(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
271 raise error.ItemForbidden() |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
272 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
273 d = node.getItemsPublishers(itemIdentifiers) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
274 d.addCallback(doCheck) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
275 return d |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
276 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
277 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
278 def publish(self, nodeIdentifier, items, requestor, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
279 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
|
280 d.addCallback(self._checkAuth, requestor) |
250 | 281 #FIXME: owner and publisher are not necessarly the same. So far we use only owner to get roster. |
282 #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
|
283 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
|
284 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
285 |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
286 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
287 def _doPublish(self, result, items, requestor, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
288 affiliation, node = result |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
289 if node.nodeType == 'collection': |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
290 raise error.NoPublishing() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
291 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
292 configuration = node.getConfiguration() |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
293 persistItems = configuration[const.OPT_PERSIST_ITEMS] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
294 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
|
295 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
296 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
|
297 raise error.ItemForbidden() |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
298 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
|
299 raise error.ItemRequired() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
300 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
301 items_data = [] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
302 check_overwrite = False |
250 | 303 for item in items: |
299 | 304 # we enforce publisher (cf XEP-0060 §7.1.2.3) |
305 item['publisher'] = requestor.full() | |
250 | 306 if persistItems or deliverPayloads: |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
307 item.uri = None |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
308 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
|
309 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
|
310 item["id"] = str(uuid.uuid4()) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
311 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
312 check_overwrite = True |
250 | 313 access_model, item_config = self.parseItemConfig(item) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
314 items_data.append((item, access_model, item_config)) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
315 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
316 if persistItems: |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
317 if check_overwrite and affiliation != 'owner': |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
318 # 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
|
319 # of an other publisher |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
320 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
|
321 d.addCallback(lambda _: node.storeItems(items_data, requestor)) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
322 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
323 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
|
324 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
325 d = defer.succeed(None) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
326 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
327 d.addCallback(self._doNotify, node, items_data, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
328 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
|
329 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
330 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
331 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
332 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
|
333 if items_data and not deliverPayloads: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
334 for access_model, item_config, item in items_data: |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
335 item.children = [] |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
336 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
|
337 '//event/pubsub/notify') |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
338 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
339 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
340 def getNotifications(self, nodeDbId, items_data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
341 """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
|
342 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
343 subscribers will be associated with subscribed items, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
344 and subscription type. |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
345 """ |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
346 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
347 def toNotifications(subscriptions, items_data): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
348 subsBySubscriber = {} |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
349 for subscription in subscriptions: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
350 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
|
351 'items') == 'items': |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
352 subs = subsBySubscriber.setdefault(subscription.subscriber, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
353 set()) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
354 subs.add(subscription) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
355 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
356 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
|
357 for subscriber, subscriptions_ |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
358 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
|
359 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
360 return notifications |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
361 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
362 def rootNotFound(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
363 failure.trap(error.NodeNotFound) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
364 return [] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
365 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
366 d1 = self.storage.getNodeById(nodeDbId) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
367 d1.addCallback(lambda node: node.getSubscriptions('subscribed')) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
368 # FIXME: must add root node subscriptions ? |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
369 # d2 = self.storage.getNode('', False) # FIXME: to check |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
370 # d2.addCallback(lambda node: node.getSubscriptions('subscribed')) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
371 # d2.addErrback(rootNotFound) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
372 # d = defer.gatherResults([d1, d2]) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
373 # d.addCallback(lambda result: result[0] + result[1]) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
374 d1.addCallback(toNotifications, items_data) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
375 return d1 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
376 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
377 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
|
378 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
|
379 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
380 def registerRetractNotifier(self, observerfn, *args, **kwargs): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
381 self.addObserver('//event/pubsub/retract', observerfn, *args, **kwargs) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
382 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
383 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
|
384 subscriberEntity = subscriber.userhostJID() |
216
53d2c0019458
Fix subscription and unsubscription JID checks.
Ralph Meijer <ralphm@ik.nu>
parents:
211
diff
changeset
|
385 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
|
386 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
|
387 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
388 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
|
389 d.addCallback(_getAffiliation, subscriberEntity) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
390 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
|
391 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
392 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
393 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
394 def _doSubscribe(self, result, subscriber): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
395 # 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
|
396 node, affiliation = result |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
397 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
398 if affiliation == 'outcast': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
399 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
400 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
401 access_model = node.getAccessModel() |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
402 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
403 if access_model != const.VAL_AMODEL_OPEN: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
404 raise NotImplementedError |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
405 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
406 def trapExists(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
407 failure.trap(error.SubscriptionExists) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
408 return False |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
409 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
410 def cb(sendLast): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
411 d = node.getSubscription(subscriber) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
412 if sendLast: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
413 d.addCallback(self._sendLastPublished, node) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
414 return d |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
415 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
416 d = node.addSubscription(subscriber, 'subscribed', {}) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
417 d.addCallbacks(lambda _: True, trapExists) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
418 d.addCallback(cb) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
419 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
420 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
421 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
422 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
423 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
|
424 |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
201
diff
changeset
|
425 def notifyItem(items): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
426 if items: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
427 reactor.callLater(0, self.dispatch, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
428 {'items': items, |
261
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
429 'node': node, |
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
430 'subscription': subscription, |
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
431 }, |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
432 '//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
|
433 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
434 config = node.getConfiguration() |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
435 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
|
436 'never') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
437 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
|
438 entity = subscription.subscriber.userhostJID() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
439 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
|
440 d.addCallback(notifyItem) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
441 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
|
442 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
443 return subscription |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
444 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
445 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
450 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
|
451 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
|
452 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
453 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
454 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
455 def getSubscriptions(self, entity): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
456 return self.storage.getSubscriptions(entity) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
457 |
228 | 458 def supportsAutoCreate(self): |
459 return True | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
460 |
237 | 461 def supportsCreatorCheck(self): |
462 return True | |
463 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
464 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
|
465 return True |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
466 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
467 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
468 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
|
469 if not nodeIdentifier: |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
470 nodeIdentifier = 'generic/%s' % uuid.uuid4() |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
471 |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
472 if not options: |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
473 options = {} |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
474 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
475 # if self.supportsCreatorCheck(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
476 # groupblog = nodeIdentifier.startswith(const.NS_GROUPBLOG_PREFIX) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
477 # try: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
478 # 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
|
479 # except InvalidFormat: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
480 # is_user_jid = False |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
481 # else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
482 # 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
|
483 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
484 # if is_user_jid and nodeIdentifierJID.userhostJID() != requestor.userhostJID(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
485 # #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
|
486 # print "Wrong creator" |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
487 # raise error.Forbidden() |
237 | 488 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
489 nodeType = 'leaf' |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
490 config = self.storage.getDefaultConfiguration(nodeType) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
491 config['pubsub#node_type'] = nodeType |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
492 config.update(options) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
493 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
494 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
|
495 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
|
496 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
497 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
498 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
499 def getDefaultConfiguration(self, nodeType): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
500 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
|
501 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
502 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
503 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
504 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
|
505 if not nodeIdentifier: |
196
00a6dbfbee42
Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents:
183
diff
changeset
|
506 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
|
507 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
508 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
|
509 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
|
510 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
511 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
512 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
513 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
514 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
|
515 if not nodeIdentifier: |
196
00a6dbfbee42
Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents:
183
diff
changeset
|
516 return defer.fail(error.NoRootNode()) |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
517 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
518 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
|
519 d.addCallback(_getAffiliation, requestor) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
520 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
|
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 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
524 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
|
525 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
526 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
527 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
528 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
529 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
530 return node.setConfiguration(options) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
531 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
532 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
533 def getAffiliations(self, entity): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
534 return self.storage.getAffiliations(entity) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
535 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
536 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
537 def getItems(self, nodeIdentifier, recipient, maxItems=None, |
278 | 538 itemIdentifiers=None, ext_data=None): |
539 if ext_data is None: | |
540 ext_data = {} | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
541 d = self.storage.getNode(nodeIdentifier, ext_data.get('pep', False), recipient) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
542 d.addCallback(_getAffiliation, recipient) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
543 d.addCallback(self._doGetItems, recipient, maxItems, itemIdentifiers, |
278 | 544 ext_data) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
545 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
546 |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
547 def checkGroup(self, roster_groups, entity): |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
548 """Check that entity is authorized and in roster |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
549 @param roster_group: tuple which 2 items: |
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
|
550 - roster: mapping of jid to RosterItem as given by self.privilege.getRoster |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
551 - groups: list of authorized groups |
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
|
552 @param entity: entity which must be in group |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
553 @return: (True, roster) if entity is in roster and authorized |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
554 (False, roster) if entity is in roster but not authorized |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
555 @raise: error.NotInRoster if entity is not in roster""" |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
556 roster, authorized_groups = roster_groups |
257
30988781f30d
fixed access check (getItems/notifications)
Goffi <goffi@goffi.org>
parents:
256
diff
changeset
|
557 _entity = entity.userhostJID() |
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
|
558 |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
559 if not _entity in roster: |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
560 raise error.NotInRoster |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
561 return (roster[_entity].groups.intersection(authorized_groups), roster) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
562 |
298 | 563 def _getNodeGroups(self, roster, nodeIdentifier, pep): |
564 d = self.storage.getNodeGroups(nodeIdentifier, pep) | |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
565 d.addCallback(lambda groups: (roster, groups)) |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
566 return d |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
567 |
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
|
568 def _rosterEb(self, failure): |
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
|
569 log.msg("Error while getting roster: {}".format(failure.value)) |
a87c155d0fd5
replaced former roster dirty hack by a XEP-0356 first draft implementation, only roster get is implemented so far
Goffi <goffi@goffi.org>
parents:
283
diff
changeset
|
570 return {} |
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
|
571 |
278 | 572 def _doGetItems(self, result, requestor, maxItems, itemIdentifiers, |
573 ext_data): | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
574 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
575 |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
576 def append_item_config(items_data): |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
577 ret = [] |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
578 for data in items_data: |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
579 item, access_model, access_list = data |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
580 if 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
|
581 pass |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
582 elif access_model == const.VAL_AMODEL_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
|
583 form = data_form.Form('submit', formNamespace=const.NS_ITEM_CONFIG) |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
584 access = data_form.Field(None, const.OPT_ACCESS_MODEL, value=const.VAL_AMODEL_ROSTER) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
585 allowed = data_form.Field(None, const.OPT_ROSTER_GROUPS_ALLOWED, values=access_list[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
|
586 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
|
587 form.addField(allowed) |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
588 item.addChild(form.toElement()) |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
589 elif access_model == const.VAL_AMODEL_JID: |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
590 #FIXME: manage jid |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
591 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
|
592 else: |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
593 raise error.BadAccessTypeError(access_model) |
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
|
594 |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
595 ret.append(item) |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
596 return ret |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
597 |
248
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
598 def access_checked(access_data): |
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
599 authorized, roster = access_data |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
600 if not authorized: |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
601 raise error.NotAuthorized() |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
602 |
256
ea44c0986f47
Fixed getItems for roster access items when the subscriber is not owner of the node.
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
603 roster_item = roster.get(requestor.userhostJID()) |
248
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
604 authorized_groups = tuple(roster_item.groups) if roster_item else tuple() |
278 | 605 unrestricted = affiliation == 'owner' |
248
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
606 |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
607 if itemIdentifiers: |
278 | 608 d = node.getItemsById(authorized_groups, unrestricted, itemIdentifiers) |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
609 else: |
278 | 610 d = node.getItems(authorized_groups, unrestricted, maxItems, |
611 ext_data) | |
612 if unrestricted: | |
613 d.addCallback(append_item_config) | |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
614 |
278 | 615 for extension in ext_data: |
616 if ext_data[extension] is not None: | |
617 if hasattr(self, '_items_%s' % extension): | |
618 method = getattr(self, '_items_%s' % extension) | |
619 d.addCallback(method, node, authorized_groups, | |
620 unrestricted, maxItems, itemIdentifiers, | |
621 ext_data[extension]) | |
622 return d | |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
623 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
624 if not ILeafNode.providedBy(node): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
625 return [] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
626 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
627 if affiliation == 'outcast': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
628 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
629 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
630 access_model = node.getAccessModel() |
248
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
631 d = node.getNodeOwner() |
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
|
632 d.addCallback(self.privilege.getRoster) |
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
|
633 d.addErrback(self._rosterEb) |
278 | 634 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
635 if access_model == const.VAL_AMODEL_OPEN or affiliation == 'owner': |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
636 d.addCallback(lambda roster: (True, roster)) |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
637 d.addCallback(access_checked) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
638 elif access_model == const.VAL_AMODEL_ROSTER: |
298 | 639 d.addCallback(self._getNodeGroups, node.nodeIdentifier, ext_data.get('pep', False)) |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
640 d.addCallback(self.checkGroup, requestor) |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
641 d.addCallback(access_checked) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
642 |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
643 return d |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
644 |
278 | 645 def _items_rsm(self, elts, node, authorized_groups, unrestricted, maxItems, |
646 itemIdentifiers, request): | |
647 response = rsm.RSMResponse() | |
648 | |
649 d_count = node.countItems(authorized_groups, unrestricted) | |
650 d_count.addCallback(lambda count: setattr(response, 'count', count)) | |
651 d_list = [d_count] | |
652 | |
653 if request.index is not None: | |
654 response.index = request.index | |
655 elif request.before is not None: | |
656 if request.before != '': | |
657 # XXX: getIndex starts with index 1, RSM starts with 0 | |
658 d_index = node.getIndex(authorized_groups, unrestricted, request.before) | |
659 d_index.addCallback(lambda index: setattr(response, 'index', max(index - request.max - 1, 0))) | |
660 d_list.append(d_index) | |
661 elif request.after is not None: | |
662 d_index = node.getIndex(authorized_groups, unrestricted, request.after) | |
663 d_index.addCallback(lambda index: setattr(response, 'index', index)) | |
664 d_list.append(d_index) | |
665 elif itemIdentifiers: | |
666 d_index = node.getIndex(authorized_groups, unrestricted, itemIdentifiers[0]) | |
667 d_index.addCallback(lambda index: setattr(response, 'index', index - 1)) | |
668 d_list.append(d_index) | |
669 | |
670 | |
671 def render(result): | |
296
6ce33757d21e
backend: fixes RSM for "unrestricted" mode
souliane <souliane@mailoo.org>
parents:
294
diff
changeset
|
672 try: |
6ce33757d21e
backend: fixes RSM for "unrestricted" mode
souliane <souliane@mailoo.org>
parents:
294
diff
changeset
|
673 items = [elt for elt in elts if elt.name == 'item'] |
6ce33757d21e
backend: fixes RSM for "unrestricted" mode
souliane <souliane@mailoo.org>
parents:
294
diff
changeset
|
674 except AttributeError: |
6ce33757d21e
backend: fixes RSM for "unrestricted" mode
souliane <souliane@mailoo.org>
parents:
294
diff
changeset
|
675 # XXX: see sat_pubsub.pgsql_storage.LeafNode.getItemsById return value |
6ce33757d21e
backend: fixes RSM for "unrestricted" mode
souliane <souliane@mailoo.org>
parents:
294
diff
changeset
|
676 items = [elt[0] for elt in elts if elt[0].name == 'item'] |
278 | 677 if len(items) > 0: |
678 if response.index is None: | |
679 if request.before == '': # last page | |
680 response.index = response.count - request.max | |
681 else: # first page | |
682 response.index = 0 | |
683 response.first = items[0]['id'] | |
684 response.last = items[len(items) - 1]['id'] | |
685 if request.before is not None: | |
686 response.first, response.last = response.last, response.first | |
687 else: | |
688 response.index = None | |
279
7c820a8e4b00
fix RSM support regarding last tmp.wokkel changes
souliane <souliane@mailoo.org>
parents:
278
diff
changeset
|
689 elts.append(response.toElement()) |
278 | 690 return elts |
691 | |
692 return defer.DeferredList(d_list).addCallback(render) | |
693 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
694 def retractItem(self, nodeIdentifier, itemIdentifiers, requestor, notify, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
695 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
|
696 d.addCallback(_getAffiliation, requestor) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
697 # FIXME: to be checked |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
698 # if const.FLAG_RETRACT_ALLOW_PUBLISHER: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
699 # d.addCallback(self._doRetractAllowPublisher, itemIdentifiers, requestor) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
700 # else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
701 # d.addCallback(self._doRetract, itemIdentifiers) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
702 d.addCallback(self._doRetract, itemIdentifiers, 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
|
703 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
704 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
705 # FIXME: to be checked |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
706 # def _doRetractAllowPublisher(self, result, itemIdentifiers, requestor): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
707 # """This method has been added to allow the publisher |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
708 # of an item to retract it, even if he has no affiliation |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
709 # to that item. For instance, this allows you to delete |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
710 # an item you posted in a node of "open" publish model. |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
711 # """ |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
712 # node, affiliation = result |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
713 # if affiliation in ['owner', 'publisher']: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
714 # return self._doRetract(result, itemIdentifiers) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
715 # d = node.filterItemsWithPublisher(itemIdentifiers, requestor) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
716 # def filterCb(filteredItems): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
717 # if not filteredItems: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
718 # return self._doRetract(result, itemIdentifiers) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
719 # # XXX: fake an affiliation that does NOT exist |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
720 # return self._doRetract((node, 'publisher'), filteredItems) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
721 # d.addCallback(filterCb) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
722 # return d |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
723 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
724 def _doRetract(self, result, itemIdentifiers, 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
|
725 node, affiliation = result |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
726 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
|
727 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
728 if affiliation not in ['owner', 'publisher']: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
729 raise error.Forbidden() |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
730 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
731 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
|
732 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
733 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
734 # 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
|
735 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
736 def removeItems(items_data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
737 """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
|
738 d = node.removeItems(itemIdentifiers) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
739 d.addCallback(lambda removed: [item_data for item_data in items_data if item_data[0]["id"] in removed]) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
740 return d |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
741 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
742 d = node.getItemsById(None, True, itemIdentifiers) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
743 d.addCallback(removeItems) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
744 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
745 if notify: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
746 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
|
747 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
748 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
749 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
750 def _doNotifyRetraction(self, items_data, node, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
751 self.dispatch({'items_data': items_data, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
752 'node': node, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
753 'pep': pep, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
754 'recipient': recipient}, |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
755 '//event/pubsub/retract') |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
756 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
757 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
758 def purgeNode(self, nodeIdentifier, requestor, pep, recipient): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
759 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
|
760 d.addCallback(_getAffiliation, requestor) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
761 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
|
762 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
763 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
764 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
765 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
|
766 node, affiliation = result |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
767 persistItems = node.getConfiguration()[const.OPT_PERSIST_ITEMS] |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
768 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
769 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
770 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
771 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
772 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
|
773 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
774 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
775 d = node.purge() |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
776 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
|
777 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
778 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
779 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
780 def _doNotifyPurge(self, result, nodeIdentifier): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
781 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
|
782 |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
783 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
784 def registerPreDelete(self, preDeleteFn): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
785 self._callbackList.append(preDeleteFn) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
786 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
787 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
788 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
|
789 def cb(subscriptions): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
790 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
|
791 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
792 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
|
793 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
|
794 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
|
795 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
796 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
797 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
798 def deleteNode(self, nodeIdentifier, requestor, pep, recipient, redirectURI=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
799 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
|
800 d.addCallback(_getAffiliation, requestor) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
801 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
|
802 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
803 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
804 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
805 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
|
806 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
807 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
808 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
809 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
810 |
261
65d4fed44edf
fixed notifications (a key was missing in data in some cases)
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
811 data = {'node': node, |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
812 'redirectURI': redirectURI} |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
813 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
814 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
|
815 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
|
816 consumeErrors=1) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
817 d.addCallback(self._doDelete, node.nodeDbId) |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
818 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
819 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
820 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
|
821 dl = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
822 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
|
823 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
|
824 dl.extend(r) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
825 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
826 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
|
827 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
|
828 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
829 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
830 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
831 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
832 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
|
833 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
|
834 d.callback(None) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
835 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
836 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
837 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
838 class PubSubResourceFromBackend(PubSubResource): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
839 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
840 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
|
841 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
842 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
843 features = [ |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
844 "config-node", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
845 "create-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
846 "delete-any", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
847 "delete-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
848 "item-ids", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
849 "meta-data", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
850 "publish", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
851 "purge-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
852 "retract-items", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
853 "retrieve-affiliations", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
854 "retrieve-default", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
855 "retrieve-items", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
856 "retrieve-subscriptions", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
857 "subscribe", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
858 ] |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
859 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
860 discoIdentity = disco.DiscoIdentity('pubsub', |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
861 'service', |
236
65bc75603539
renamed service to « Salut à Toi pubsub service »
Goffi <goffi@goffi.org>
parents:
235
diff
changeset
|
862 u'Salut à Toi pubsub service') |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
863 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
864 pubsubService = None |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
865 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
866 _errorMap = { |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
867 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
|
868 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
|
869 error.Forbidden: ('forbidden', None, None), |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
870 error.NotAuthorized: ('not-authorized', None, None), |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
871 error.NotInRoster: ('not-authorized', 'not-in-roster-group', None), |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
872 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
|
873 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
|
874 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
|
875 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
|
876 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
877 'instant-nodes'), |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
878 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
|
879 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
|
880 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
|
881 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
|
882 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
883 'persistent-node'), |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
884 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
|
885 error.NoCollections: ('feature-not-implemented', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
886 'unsupported', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
887 'collections'), |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
888 error.NoPublishing: ('feature-not-implemented', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
889 'unsupported', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
890 'publish'), |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
891 } |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
892 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
893 def __init__(self, backend): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
894 PubSubResource.__init__(self) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
895 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
896 self.backend = backend |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
897 self.hideNodes = False |
153 | 898 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
899 self.backend.registerPublishNotifier(self._notifyPublish) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
900 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
|
901 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
|
902 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
903 # 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
|
904 # if self.backend.supportsCreatorCheck(): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
905 # self.features.append("creator-jid-check") #SàT custom feature: Check that a node (which correspond to |
237 | 906 # 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
|
907 |
228 | 908 if self.backend.supportsAutoCreate(): |
909 self.features.append("auto-create") | |
910 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
911 if self.backend.supportsInstantNodes(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
912 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
|
913 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
914 if self.backend.supportsOutcastAffiliation(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
915 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
|
916 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
917 if self.backend.supportsPersistentItems(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
918 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
|
919 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
920 if self.backend.supportsPublisherAffiliation(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
921 self.features.append("publisher-affiliation") |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
922 |
250 | 923 if self.backend.supportsGroupBlog(): |
924 self.features.append("groupblog") | |
925 | |
260 | 926 # if self.backend.supportsPublishModel(): #XXX: this feature is not really described in XEP-0060, we just can see it in examples |
927 # self.features.append("publish_model") # but it's necessary for microblogging comments (see XEP-0277) | |
928 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
929 def _notifyPublish(self, data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
930 items_data = data['items_data'] |
250 | 931 node = data['node'] |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
932 pep = data['pep'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
933 recipient = data['recipient'] |
250 | 934 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
935 def afterPrepare(result): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
936 owner_jid, notifications_filtered = result |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
937 #we notify the owner |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
938 #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
|
939 #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
|
940 #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
|
941 |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
942 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
|
943 """ 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
|
944 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
|
945 """ |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
946 #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
|
947 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
948 item, access_model, item_config = item_data |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
949 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
|
950 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
|
951 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
|
952 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
|
953 |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
954 notifications_filtered.append((owner_jid, |
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
|
955 set([Subscription(node.nodeIdentifier, |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
956 owner_jid, |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
957 'subscribed')]), |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
958 [getFullItem(item_data) for item_data in items_data])) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
959 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
960 if pep: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
961 return self.backend.privilege.notifyPublish( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
962 recipient, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
963 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
964 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
965 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
966 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
967 return self.pubsubService.notifyPublish( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
968 self.serviceJID, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
969 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
970 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
971 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
972 d = self._prepareNotify(items_data, node, data.get('subscription')) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
973 d.addCallback(afterPrepare) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
974 return d |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
975 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
976 def _notifyRetract(self, data): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
977 items_data = data['items_data'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
978 node = data['node'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
979 pep = data['pep'] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
980 recipient = data['recipient'] |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
981 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
982 def afterPrepare(result): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
983 owner_jid, notifications_filtered = result |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
984 #we add the owner |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
985 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
986 notifications_filtered.append((owner_jid, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
987 set([Subscription(node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
988 owner_jid, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
989 'subscribed')]), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
990 [item for item, _, _ in items_data])) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
991 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
992 if pep: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
993 return self.backend.privilege.notifyRetract( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
994 recipient, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
995 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
996 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
997 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
998 else: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
999 return self.pubsubService.notifyRetract( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1000 self.serviceJID, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1001 node.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1002 notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1003 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1004 d = self._prepareNotify(items_data, node, data.get('subscription')) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1005 d.addCallback(afterPrepare) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1006 return d |
250 | 1007 |
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
|
1008 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1009 def _prepareNotify(self, items_data, node, subscription=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1010 """Do a bunch of permissions check and filter notifications |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1011 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1012 The owner is not added to these notifications, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1013 it must be called by the calling method |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1014 @param items_data(tuple): must contain: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1015 - item (domish.Element) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1016 - access_model (unicode) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1017 - access_list (dict as returned getItemsById, or item_config) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1018 @param node(LeafNode): node hosting the items |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1019 @param subscription(pubsub.Subscription, None): TODO |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1020 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1021 @return (tuple): will contain: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1022 - notifications_filtered |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1023 - node_owner_jid |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1024 - items_data |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1025 """ |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1026 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1027 def filterNotifications(result): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1028 """Check access of subscriber for each item, and keep only allowed ones""" |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1029 notifications, (owner_jid,roster) = result |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1030 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1031 #we filter items not allowed for the subscribers |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1032 notifications_filtered = [] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1033 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1034 for subscriber, subscriptions, _items_data in notifications: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1035 if subscriber == owner_jid: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1036 # as notification is always sent to owner, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1037 # we ignore owner if he is here |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1038 continue |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1039 allowed_items = [] #we keep only item which subscriber can access |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1040 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1041 for item, access_model, access_list in _items_data: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1042 if access_model == const.VAL_AMODEL_OPEN: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1043 allowed_items.append(item) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1044 elif access_model == const.VAL_AMODEL_ROSTER: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1045 _subscriber = subscriber.userhostJID() |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1046 if not _subscriber in roster: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1047 continue |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1048 #the subscriber is known, is he in the right group ? |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1049 authorized_groups = access_list[const.OPT_ROSTER_GROUPS_ALLOWED] |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1050 if roster[_subscriber].groups.intersection(authorized_groups): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1051 allowed_items.append(item) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1052 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1053 else: #unknown access_model |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1054 raise NotImplementedError |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1055 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1056 if allowed_items: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1057 notifications_filtered.append((subscriber, subscriptions, allowed_items)) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1058 return (owner_jid, notifications_filtered) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1059 |
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 if subscription is None: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1062 d1 = 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
|
1063 else: |
250 | 1064 d1 = defer.succeed([(subscription.subscriber, [subscription], |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1065 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
|
1066 |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1067 def _got_owner(owner_jid): |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1068 #return a tuple with owner_jid and roster |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1069 def rosterEb(failure): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1070 log.msg("Error while getting roster: {}".format(failure.value)) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1071 return (owner_jid, {}) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1072 |
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
|
1073 d = self.backend.privilege.getRoster(owner_jid) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1074 d.addErrback(rosterEb) |
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
|
1075 d.addCallback(lambda roster: (owner_jid,roster)) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1076 return d |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1077 |
250 | 1078 d2 = node.getNodeOwner() |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
1079 d2.addCallback(_got_owner) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1080 d = defer.gatherResults([d1, d2]) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1081 d.addCallback(filterNotifications) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1082 return d |
250 | 1083 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1084 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
|
1085 nodeIdentifier = data['node'].nodeIdentifier |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
1086 redirectURI = data.get('redirectURI', None) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1087 d = self.backend.getSubscribers(nodeIdentifier, pep, recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1088 d.addCallback(lambda subscribers: self.pubsubService.notifyDelete( |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1089 self.serviceJID, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1090 nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1091 subscribers, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1092 redirectURI)) |
174
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
1093 return d |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
1094 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1095 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1096 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
|
1097 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
|
1098 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1099 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
|
1100 msg = failure.value.msg |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1101 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1102 if pubsubCondition: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1103 exc = PubSubError(condition, pubsubCondition, feature, msg) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1104 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1105 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
|
1106 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1107 raise exc |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1108 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1109 def getInfo(self, requestor, service, nodeIdentifier, pep=None, recipient=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1110 return [] # FIXME: disabled for now, need to manage PEP |
288
073161f6f143
namespace delegation: disco nesting management
Goffi <goffi@goffi.org>
parents:
285
diff
changeset
|
1111 if not requestor.resource: |
073161f6f143
namespace delegation: disco nesting management
Goffi <goffi@goffi.org>
parents:
285
diff
changeset
|
1112 # 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
|
1113 return [] |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1114 info = {} |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1115 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1116 def saveType(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1117 info['type'] = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1118 return nodeIdentifier |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1119 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1120 def saveMetaData(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1121 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
|
1122 return info |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1123 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1124 def trapNotFound(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1125 failure.trap(error.NodeNotFound) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1126 return info |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1127 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1128 d = defer.succeed(nodeIdentifier) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1129 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
|
1130 d.addCallback(saveType) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1131 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
|
1132 d.addCallback(saveMetaData) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1133 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
|
1134 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
|
1135 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1136 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1137 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1138 def getNodes(self, requestor, service, nodeIdentifier, pep=None): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1139 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
|
1140 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
|
1141 return defer.succeed([]) |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1142 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
|
1143 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
|
1144 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1145 |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
1146 def getConfigurationOptions(self): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
1147 return self.backend.nodeOptions |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
1148 |
228 | 1149 def _publish_errb(self, failure, request): |
1150 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
|
1151 print "Auto-creating node %s" % (request.nodeIdentifier,) |
228 | 1152 d = self.backend.createNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1153 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1154 pep=self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1155 recipient=request.recipient) |
228 | 1156 d.addCallback(lambda ignore, |
1157 request: self.backend.publish(request.nodeIdentifier, | |
1158 request.items, | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1159 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1160 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1161 request.recipient, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1162 ), |
228 | 1163 request) |
1164 return d | |
1165 | |
240
70c8bb90d75f
added access_model to config, default to 'open'
Goffi <goffi@goffi.org>
parents:
237
diff
changeset
|
1166 return failure |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
1167 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1168 def _isPep(self, request): |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1169 try: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1170 return request.delegated |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1171 except AttributeError: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1172 return False |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1173 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1174 def publish(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1175 d = self.backend.publish(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1176 request.items, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1177 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1178 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1179 request.recipient) |
228 | 1180 d.addErrback(self._publish_errb, request) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1181 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1182 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1183 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1184 def subscribe(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1185 d = self.backend.subscribe(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1186 request.subscriber, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1187 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1188 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1189 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1190 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1191 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1192 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1193 def unsubscribe(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1194 d = self.backend.unsubscribe(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1195 request.subscriber, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1196 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1197 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1198 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1199 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1200 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1201 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1202 def subscriptions(self, request): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1203 d = self.backend.getSubscriptions(self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1204 request.sender) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1205 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
|
1206 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1207 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1208 def affiliations(self, request): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1209 d = self.backend.getAffiliations(self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1210 request.sender) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1211 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1212 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1213 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1214 def create(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1215 d = self.backend.createNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1216 request.sender, request.options, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1217 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1218 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1219 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1220 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1221 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1222 def default(self, request): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1223 d = self.backend.getDefaultConfiguration(request.nodeType, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1224 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1225 request.sender) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1226 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1227 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1228 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1229 def configureGet(self, request): |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1230 d = self.backend.getNodeConfiguration(request.nodeIdentifier, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1231 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1232 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1233 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
|
1234 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1235 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1236 def configureSet(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1237 d = self.backend.setNodeConfiguration(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1238 request.options, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1239 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1240 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1241 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1242 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1243 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1244 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1245 def items(self, request): |
278 | 1246 ext_data = {} |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1247 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
|
1248 ext_data['rsm'] = request.rsm |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1249 try: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1250 ext_data['pep'] = request.delegated |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1251 except AttributeError: |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1252 pass |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1253 d = self.backend.getItems(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1254 request.recipient, |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1255 request.maxItems, |
278 | 1256 request.itemIdentifiers, |
1257 ext_data) | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1258 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1259 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1260 def retract(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1261 d = self.backend.retractItem(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1262 request.itemIdentifiers, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1263 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1264 request.notify, |
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) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1267 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
|
1268 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1269 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1270 def purge(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1271 d = self.backend.purgeNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1272 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1273 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1274 request.recipient) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1275 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
|
1276 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1277 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1278 def delete(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1279 d = self.backend.deleteNode(request.nodeIdentifier, |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1280 request.sender, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1281 self._isPep(request), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
290
diff
changeset
|
1282 request.recipient) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1283 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1284 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1285 components.registerAdapter(PubSubResourceFromBackend, |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1286 IBackendService, |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1287 IPubSubResource) |