Mercurial > libervia-pubsub
annotate sat_pubsub/backend.py @ 260:f0cd02c032b3
publish model management
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 06 May 2013 00:26:37 +0200 |
parents | 6fe7da6b4b32 |
children | 65d4fed44edf |
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 |
255 | 6 Copyright (c) 2012, 2013 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 |
240
70c8bb90d75f
added access_model to config, default to 'open'
Goffi <goffi@goffi.org>
parents:
237
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 |
250 | 76 from wokkel import disco, data_form |
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 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
85 def _getAffiliation(node, entity): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
86 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
|
87 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
|
88 return d |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
20
diff
changeset
|
89 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
90 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
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 = { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
106 "pubsub#persist_items": |
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"}, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
109 "pubsub#deliver_payloads": |
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"}, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
112 "pubsub#send_last_published_item": |
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 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
184 def getNodeType(self, nodeIdentifier): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
185 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
186 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
|
187 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
188 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
189 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
190 def getNodes(self): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
191 return self.storage.getNodeIds() |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
192 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
193 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
194 def getNodeMetaData(self, nodeIdentifier): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
195 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
196 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
|
197 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
|
198 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
199 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
200 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
201 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
|
202 options = [] |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
203 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
|
204 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
|
205 option = {"var": key} |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
206 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
|
207 option["value"] = value |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
208 options.append(option) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
209 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
210 return options |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
211 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
212 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
213 def _checkAuth(self, node, requestor): |
260 | 214 """ Check authorisation of publishing in node for requestor """ |
215 | |
216 def check(affiliation): | |
217 d = defer.succeed(node) | |
218 configuration = node.getConfiguration() | |
219 publish_model = configuration[const.OPT_PUBLISH_MODEL] | |
220 | |
221 if (publish_model == const.VAL_PMODEL_PUBLISHERS): | |
222 if affiliation not in ['owner', 'publisher']: | |
223 raise error.Forbidden() | |
224 elif (publish_model == const.VAL_PMODEL_SUBSCRIBERS): | |
225 if affiliation not in ['owner', 'publisher']: | |
226 # we are in subscribers publish model, we must check that | |
227 # the requestor is a subscriber to allow him to publish | |
228 | |
229 def checkSubscription(subscribed): | |
230 if not subscribed: | |
231 raise error.Forbidden() | |
232 return node | |
233 | |
234 d.addCallback(lambda ignore: node.isSubscribed(requestor)) | |
235 d.addCallback(checkSubscription) | |
236 elif publish_model != const.VAL_PMODEL_OPEN: | |
237 raise Exception('Unexpected value') # publish_model must be publishers (default), subscribers or open. | |
238 | |
239 return d | |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
240 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
241 d = node.getAffiliation(requestor) |
260 | 242 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
|
243 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
244 |
250 | 245 def parseItemConfig(self, item): |
246 """Get and remove item configuration information | |
247 @param item: | |
248 """ | |
249 item_config = None | |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
250 access_model = const.VAL_AMODEL_DEFAULT |
250 | 251 for i in range(len(item.children)): |
252 elt = item.children[i] | |
253 if not (elt.uri,elt.name)==(data_form.NS_X_DATA,'x'): | |
254 continue | |
255 form = data_form.Form.fromElement(elt) | |
256 if (form.formNamespace == const.NS_ITEM_CONFIG): | |
257 item_config = form | |
258 del item.children[i] #we need to remove the config from item | |
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 |
264 return (access_model, item_config) | |
265 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
266 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
267 def publish(self, nodeIdentifier, items, requestor): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
268 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
269 d.addCallback(self._checkAuth, requestor) |
250 | 270 #FIXME: owner and publisher are not necessarly the same. So far we use only owner to get roster. |
271 #FIXME: in addition, there can be several owners: that is not managed yet | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
272 d.addCallback(self._doPublish, items, requestor) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
273 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
274 |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
275 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
276 def _doPublish(self, node, items, requestor): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
277 if node.nodeType == 'collection': |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
278 raise error.NoPublishing() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
279 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
280 configuration = node.getConfiguration() |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
281 persistItems = configuration["pubsub#persist_items"] |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
282 deliverPayloads = configuration["pubsub#deliver_payloads"] |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
283 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
284 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
|
285 raise error.ItemForbidden() |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
286 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
|
287 raise error.ItemRequired() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
288 |
250 | 289 parsed_items = [] |
290 for item in items: | |
291 if persistItems or deliverPayloads: | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
292 item.uri = None |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
293 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
|
294 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
|
295 item["id"] = str(uuid.uuid4()) |
250 | 296 access_model, item_config = self.parseItemConfig(item) |
297 parsed_items.append((access_model, item_config, item)) | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
298 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
299 if persistItems: |
250 | 300 d = node.storeItems(parsed_items, requestor) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
301 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
302 d = defer.succeed(None) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
303 |
250 | 304 d.addCallback(self._doNotify, node, parsed_items, |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
305 deliverPayloads) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
306 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
307 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
308 |
250 | 309 def _doNotify(self, result, node, items, deliverPayloads): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
310 if items and not deliverPayloads: |
250 | 311 for access_model, item_config, item in items: |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
312 item.children = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
313 |
250 | 314 self.dispatch({'items': items, 'node': node}, |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
315 '//event/pubsub/notify') |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
316 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
317 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
318 def getNotifications(self, nodeIdentifier, items): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
319 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
320 def toNotifications(subscriptions, nodeIdentifier, items): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
321 subsBySubscriber = {} |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
322 for subscription in subscriptions: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
323 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
|
324 'items') == 'items': |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
325 subs = subsBySubscriber.setdefault(subscription.subscriber, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
326 set()) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
327 subs.add(subscription) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
328 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
329 notifications = [(subscriber, subscriptions, items) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
330 for subscriber, subscriptions |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
331 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
|
332 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
333 return notifications |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
334 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
335 def rootNotFound(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
336 failure.trap(error.NodeNotFound) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
337 return [] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
338 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
339 d1 = self.storage.getNode(nodeIdentifier) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
340 d1.addCallback(lambda node: node.getSubscriptions('subscribed')) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
341 d2 = self.storage.getNode('') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
342 d2.addCallback(lambda node: node.getSubscriptions('subscribed')) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
343 d2.addErrback(rootNotFound) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
344 d = defer.gatherResults([d1, d2]) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
345 d.addCallback(lambda result: result[0] + result[1]) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
346 d.addCallback(toNotifications, nodeIdentifier, items) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
347 return d |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
348 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
349 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
350 def registerNotifier(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
|
351 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
|
352 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
353 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
354 def subscribe(self, nodeIdentifier, subscriber, requestor): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
355 subscriberEntity = subscriber.userhostJID() |
216
53d2c0019458
Fix subscription and unsubscription JID checks.
Ralph Meijer <ralphm@ik.nu>
parents:
211
diff
changeset
|
356 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
|
357 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
|
358 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
359 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
360 d.addCallback(_getAffiliation, subscriberEntity) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
361 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
|
362 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
363 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
364 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
365 def _doSubscribe(self, result, subscriber): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
366 node, affiliation = result |
250 | 367 #FIXME: must check node's access_model before subscribing |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
368 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
369 if affiliation == 'outcast': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
370 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
371 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
372 def trapExists(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
373 failure.trap(error.SubscriptionExists) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
374 return False |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
375 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
376 def cb(sendLast): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
377 d = node.getSubscription(subscriber) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
378 if sendLast: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
379 d.addCallback(self._sendLastPublished, node) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
380 return d |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
381 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
382 d = node.addSubscription(subscriber, 'subscribed', {}) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
383 d.addCallbacks(lambda _: True, trapExists) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
384 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
|
385 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
386 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
387 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
388 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
|
389 |
202
77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents:
201
diff
changeset
|
390 def notifyItem(items): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
391 if items: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
392 reactor.callLater(0, self.dispatch, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
393 {'items': items, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
394 'nodeIdentifier': node.nodeIdentifier, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
395 'subscription': subscription}, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
396 '//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
|
397 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
398 config = node.getConfiguration() |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
399 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
|
400 'never') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
401 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
|
402 entity = subscription.subscriber.userhostJID() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
403 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
|
404 d.addCallback(notifyItem) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
405 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
|
406 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
407 return subscription |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
408 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
409 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
410 def unsubscribe(self, nodeIdentifier, subscriber, requestor): |
216
53d2c0019458
Fix subscription and unsubscription JID checks.
Ralph Meijer <ralphm@ik.nu>
parents:
211
diff
changeset
|
411 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
|
412 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
|
413 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
414 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
415 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
|
416 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
417 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
418 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
419 def getSubscriptions(self, entity): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
420 return self.storage.getSubscriptions(entity) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
421 |
228 | 422 def supportsAutoCreate(self): |
423 return True | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
424 |
237 | 425 def supportsCreatorCheck(self): |
426 return True | |
427 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
428 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
|
429 return True |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
430 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
431 |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
432 def createNode(self, nodeIdentifier, requestor, options = None): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
433 if not nodeIdentifier: |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
434 nodeIdentifier = 'generic/%s' % uuid.uuid4() |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
435 |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
436 if not options: |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
437 options = {} |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
438 |
237 | 439 if self.supportsCreatorCheck(): |
250 | 440 groupblog = nodeIdentifier.startswith(const.NS_GROUPBLOG_PREFIX) |
237 | 441 try: |
250 | 442 nodeIdentifierJID = JID(nodeIdentifier[len(const.NS_GROUPBLOG_PREFIX):] if groupblog else nodeIdentifier) |
237 | 443 except InvalidFormat: |
444 is_user_jid = False | |
445 else: | |
446 is_user_jid = bool(nodeIdentifierJID.user) | |
447 | |
257
30988781f30d
fixed access check (getItems/notifications)
Goffi <goffi@goffi.org>
parents:
256
diff
changeset
|
448 if is_user_jid and nodeIdentifierJID.userhostJID() != requestor.userhostJID(): |
237 | 449 #we have an user jid node, but not created by the owner of this jid |
450 print "Wrong creator" | |
451 raise error.Forbidden() | |
452 | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
453 nodeType = 'leaf' |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
454 config = self.storage.getDefaultConfiguration(nodeType) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
455 config['pubsub#node_type'] = nodeType |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
456 config.update(options) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
457 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
458 d = self.storage.createNode(nodeIdentifier, requestor, config) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
459 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
|
460 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
461 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
462 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
463 def getDefaultConfiguration(self, nodeType): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
464 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
|
465 return d |
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 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
468 def getNodeConfiguration(self, nodeIdentifier): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
469 if not nodeIdentifier: |
196
00a6dbfbee42
Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents:
183
diff
changeset
|
470 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
|
471 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
472 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
473 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
|
474 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
475 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
476 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
477 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
478 def setNodeConfiguration(self, nodeIdentifier, options, requestor): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
479 if not nodeIdentifier: |
196
00a6dbfbee42
Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents:
183
diff
changeset
|
480 return defer.fail(error.NoRootNode()) |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
481 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
482 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
483 d.addCallback(_getAffiliation, requestor) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
484 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
|
485 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
486 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
487 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
488 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
|
489 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
490 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
491 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
492 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
493 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
494 return node.setConfiguration(options) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
495 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
496 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
497 def getAffiliations(self, entity): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
498 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
|
499 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
500 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
501 def getItems(self, nodeIdentifier, requestor, maxItems=None, |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
502 itemIdentifiers=None): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
503 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
504 d.addCallback(_getAffiliation, requestor) |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
505 d.addCallback(self._doGetItems, requestor, maxItems, itemIdentifiers) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
506 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
507 |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
508 def checkGroup(self, roster_groups, entity): |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
509 """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
|
510 @param roster_group: tuple which 2 items: |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
511 - roster: mapping of jid to RosterItem as given by self.roster.getRoster |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
512 - groups: list of authorized groups |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
513 @param entity: entity which must be in group |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
514 @return: (True, roster) if entity is in roster and authorized |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
515 (False, roster) if entity is in roster but not authorized |
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
516 @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
|
517 roster, authorized_groups = roster_groups |
257
30988781f30d
fixed access check (getItems/notifications)
Goffi <goffi@goffi.org>
parents:
256
diff
changeset
|
518 _entity = entity.userhostJID() |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
519 |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
520 if not _entity in roster: |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
521 raise error.NotInRoster |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
522 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
|
523 |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
524 def _getNodeGroups(self, roster, nodeIdentifier): |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
525 d = self.storage.getNodeGroups(nodeIdentifier) |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
526 d.addCallback(lambda groups: (roster, groups)) |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
527 return d |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
528 |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
529 def _doGetItems(self, result, requestor, maxItems, itemIdentifiers): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
530 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
531 |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
532 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
|
533 ret = [] |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
534 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
|
535 item, access_model, access_list = data |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
536 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
|
537 pass |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
538 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
|
539 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
|
540 access = data_form.Field(None, const.OPT_ACCESS_MODEL, value=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
|
541 allowed = data_form.Field(None, const.OPT_ROSTER_GROUPS_ALLOWED, values=access_list) |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
542 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
|
543 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
|
544 item.addChild(form.toElement()) |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
545 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
|
546 #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
|
547 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
|
548 else: |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
549 raise error.BadAccessTypeError(access_model) |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
550 |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
551 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
|
552 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
|
553 |
248
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
554 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
|
555 authorized, roster = access_data |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
556 if not authorized: |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
557 raise error.NotAuthorized() |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
558 |
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
|
559 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
|
560 authorized_groups = tuple(roster_item.groups) if roster_item else tuple() |
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
561 |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
562 if itemIdentifiers: |
248
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
563 return node.getItemsById(authorized_groups, affiliation == 'owner', itemIdentifiers) |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
564 else: |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
565 if affiliation == 'owner': |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
566 d = node.getItems(authorized_groups, True, maxItems) |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
567 return d.addCallback(append_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
|
568 else: |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
569 return node.getItems(authorized_groups, False, maxItems) |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
570 |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
571 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
572 if not ILeafNode.providedBy(node): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
573 return [] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
574 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
575 if affiliation == 'outcast': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
576 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
577 |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
578 access_model = node.getConfiguration()["pubsub#access_model"] |
248
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
579 d = node.getNodeOwner() |
50f6ee966da8
item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents:
243
diff
changeset
|
580 d.addCallback(self.roster.getRoster) |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
581 |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
582 if access_model == 'open' or affiliation == 'owner': |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
583 d.addCallback(lambda roster: (True, roster)) |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
584 d.addCallback(access_checked) |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
585 elif access_model == 'roster': |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
586 d.addCallback(self._getNodeGroups,node.nodeIdentifier) |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
587 d.addCallback(self.checkGroup, requestor) |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
588 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
|
589 |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
590 return d |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
591 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
592 def retractItem(self, nodeIdentifier, itemIdentifiers, requestor): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
593 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
594 d.addCallback(_getAffiliation, requestor) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
595 d.addCallback(self._doRetract, itemIdentifiers) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
596 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
597 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
598 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
599 def _doRetract(self, result, itemIdentifiers): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
600 node, affiliation = result |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
601 persistItems = node.getConfiguration()["pubsub#persist_items"] |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
602 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
603 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
|
604 raise error.Forbidden() |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
605 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
606 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
|
607 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
608 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
609 d = node.removeItems(itemIdentifiers) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
610 d.addCallback(self._doNotifyRetraction, node.nodeIdentifier) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
611 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
612 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
613 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
614 def _doNotifyRetraction(self, itemIdentifiers, nodeIdentifier): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
615 self.dispatch({'itemIdentifiers': itemIdentifiers, |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
616 'nodeIdentifier': nodeIdentifier }, |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
617 '//event/pubsub/retract') |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
618 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
619 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
620 def purgeNode(self, nodeIdentifier, requestor): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
621 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
622 d.addCallback(_getAffiliation, requestor) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
623 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
|
624 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
625 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
626 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
627 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
|
628 node, affiliation = result |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
629 persistItems = node.getConfiguration()["pubsub#persist_items"] |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
630 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
631 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
632 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
633 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
634 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
|
635 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
636 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
637 d = node.purge() |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
638 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
|
639 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
640 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
641 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
642 def _doNotifyPurge(self, result, nodeIdentifier): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
643 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
|
644 |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
645 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
646 def registerPreDelete(self, preDeleteFn): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
647 self._callbackList.append(preDeleteFn) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
648 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
649 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
650 def getSubscribers(self, nodeIdentifier): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
651 def cb(subscriptions): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
652 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
|
653 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
654 d = self.storage.getNode(nodeIdentifier) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
655 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
|
656 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
|
657 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
658 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
659 |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
660 def deleteNode(self, nodeIdentifier, requestor, redirectURI=None): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
661 d = self.storage.getNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
662 d.addCallback(_getAffiliation, requestor) |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
663 d.addCallback(self._doPreDelete, redirectURI) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
664 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
665 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
666 |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
667 def _doPreDelete(self, result, redirectURI): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
668 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
669 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
670 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
671 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
672 |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
673 data = {'nodeIdentifier': node.nodeIdentifier, |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
674 'redirectURI': redirectURI} |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
675 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
676 d = defer.DeferredList([cb(data) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
677 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
|
678 consumeErrors=1) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
679 d.addCallback(self._doDelete, node.nodeIdentifier) |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
680 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
681 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
682 def _doDelete(self, result, nodeIdentifier): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
683 dl = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
684 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
|
685 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
|
686 dl.extend(r) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
687 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
688 d = self.storage.deleteNode(nodeIdentifier) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
689 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
|
690 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
691 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
692 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
693 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
694 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
|
695 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
|
696 d.callback(None) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
697 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
698 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
699 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
700 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
|
701 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
702 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
|
703 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
704 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
705 features = [ |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
706 "config-node", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
707 "create-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
708 "delete-any", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
709 "delete-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
710 "item-ids", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
711 "meta-data", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
712 "publish", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
713 "purge-nodes", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
714 "retract-items", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
715 "retrieve-affiliations", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
716 "retrieve-default", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
717 "retrieve-items", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
718 "retrieve-subscriptions", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
719 "subscribe", |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
720 ] |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
721 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
722 discoIdentity = disco.DiscoIdentity('pubsub', |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
723 'service', |
236
65bc75603539
renamed service to « Salut à Toi pubsub service »
Goffi <goffi@goffi.org>
parents:
235
diff
changeset
|
724 u'Salut à Toi pubsub service') |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
725 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
726 pubsubService = None |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
727 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
728 _errorMap = { |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
729 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
|
730 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
|
731 error.Forbidden: ('forbidden', None, None), |
243
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
732 error.NotAuthorized: ('not-authorized', None, None), |
42048e37699e
added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
733 error.NotInRoster: ('not-authorized', 'not-in-roster-group', None), |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
734 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
|
735 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
|
736 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
|
737 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
738 'instant-nodes'), |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 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
|
743 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
744 'persistent-node'), |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
745 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
|
746 error.NoCollections: ('feature-not-implemented', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
747 'unsupported', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
748 'collections'), |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
749 error.NoPublishing: ('feature-not-implemented', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
750 'unsupported', |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
751 'publish'), |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
752 } |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
753 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
754 def __init__(self, backend): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
755 PubSubResource.__init__(self) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
756 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
757 self.backend = backend |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
758 self.hideNodes = False |
153 | 759 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
760 self.backend.registerNotifier(self._notify) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
761 self.backend.registerPreDelete(self._preDelete) |
240
70c8bb90d75f
added access_model to config, default to 'open'
Goffi <goffi@goffi.org>
parents:
237
diff
changeset
|
762 |
237 | 763 if self.backend.supportsCreatorCheck(): |
764 self.features.append("creator-jid-check") #SàT custom feature: Check that a node (which correspond to | |
765 # 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
|
766 |
228 | 767 if self.backend.supportsAutoCreate(): |
768 self.features.append("auto-create") | |
769 | |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
770 if self.backend.supportsInstantNodes(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
771 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
|
772 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
773 if self.backend.supportsOutcastAffiliation(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
774 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
|
775 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
776 if self.backend.supportsPersistentItems(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
777 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
|
778 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
779 if self.backend.supportsPublisherAffiliation(): |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
780 self.features.append("publisher-affiliation") |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
781 |
250 | 782 if self.backend.supportsGroupBlog(): |
783 self.features.append("groupblog") | |
784 | |
260 | 785 # if self.backend.supportsPublishModel(): #XXX: this feature is not really described in XEP-0060, we just can see it in examples |
786 # self.features.append("publish_model") # but it's necessary for microblogging comments (see XEP-0277) | |
787 | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
788 def _notify(self, data): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
789 items = data['items'] |
250 | 790 node = data['node'] |
791 | |
792 def _notifyAllowed(result): | |
793 """Check access of subscriber for each item, | |
794 and notify only allowed ones""" | |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
795 notifications, (owner_jid,roster) = result |
250 | 796 |
797 #we filter items not allowed for the subscribers | |
798 notifications_filtered = [] | |
799 | |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
800 for subscriber, subscriptions, _items in notifications: |
250 | 801 allowed_items = [] #we keep only item which subscriber can access |
802 | |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
803 for access_model, item_config, item in _items: |
250 | 804 if access_model == 'open': |
805 allowed_items.append(item) | |
806 elif access_model == 'roster': | |
257
30988781f30d
fixed access check (getItems/notifications)
Goffi <goffi@goffi.org>
parents:
256
diff
changeset
|
807 _subscriber = subscriber.userhostJID() |
250 | 808 if not _subscriber in roster: |
809 continue | |
810 #the subscriber is known, is he in the right group ? | |
811 authorized_groups = item_config[const.OPT_ROSTER_GROUPS_ALLOWED] | |
812 if roster[_subscriber].groups.intersection(authorized_groups): | |
813 allowed_items.append(item) | |
814 | |
815 else: #unknown access_model | |
816 raise NotImplementedError | |
817 | |
258
e5b83fbb0219
removed notifications when no items are allowed for an entity
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
818 if allowed_items: |
e5b83fbb0219
removed notifications when no items are allowed for an entity
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
819 notifications_filtered.append((subscriber, subscriptions, allowed_items)) |
250 | 820 |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
821 #we notify the owner |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
822 #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
|
823 #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
|
824 #TODO: same thing for getItems |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
825 |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
826 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
|
827 """ 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
|
828 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
|
829 """ |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
830 #TODO: a test should check that only the owner get the item configuration back |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
831 |
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
832 access_model, item_config, item = 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
|
833 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
|
834 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
|
835 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
|
836 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
|
837 |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
838 notifications_filtered.append((owner_jid, |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
839 set([Subscription(node.nodeIdentifier, |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
840 owner_jid, |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
841 'subscribed')]), |
252
25a1dc7181cc
full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents:
251
diff
changeset
|
842 [getFullItem(item_data) for item_data in items])) |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
843 |
250 | 844 return self.pubsubService.notifyPublish( |
845 self.serviceJID, | |
846 node.nodeIdentifier, | |
847 notifications_filtered) | |
848 | |
849 | |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
850 if 'subscription' not in data: |
250 | 851 d1 = self.backend.getNotifications(node.nodeIdentifier, items) |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
852 else: |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
853 subscription = data['subscription'] |
250 | 854 d1 = defer.succeed([(subscription.subscriber, [subscription], |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
855 items)]) |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
856 |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
857 def _got_owner(owner_jid): |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
858 #return a tuple with owner_jid and roster |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
859 d = self.backend.roster.getRoster(owner_jid) |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
860 return d.addCallback(lambda roster: (owner_jid,roster)) |
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
861 |
250 | 862 d2 = node.getNodeOwner() |
251
0a7d43b3dad6
owner is now notified of items published
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
863 d2.addCallback(_got_owner) |
250 | 864 |
865 d = defer.gatherResults([d1, d2]) | |
866 d.addCallback(_notifyAllowed) | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
867 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
868 |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
869 def _preDelete(self, data): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
870 nodeIdentifier = data['nodeIdentifier'] |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
871 redirectURI = data.get('redirectURI', None) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
872 d = self.backend.getSubscribers(nodeIdentifier) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
873 d.addCallback(lambda subscribers: self.pubsubService.notifyDelete( |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
874 self.serviceJID, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
875 nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
876 subscribers, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
877 redirectURI)) |
174
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
878 return d |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
879 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
880 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
881 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
|
882 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
|
883 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
884 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
|
885 msg = failure.value.msg |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
886 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
887 if pubsubCondition: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
888 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
|
889 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
890 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
|
891 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
892 raise exc |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
893 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
894 def getInfo(self, requestor, service, nodeIdentifier): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
895 info = {} |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
896 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
897 def saveType(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
898 info['type'] = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
899 return nodeIdentifier |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
900 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
901 def saveMetaData(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
902 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
|
903 return info |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
904 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
905 def trapNotFound(failure): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
906 failure.trap(error.NodeNotFound) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
907 return info |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
908 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
909 d = defer.succeed(nodeIdentifier) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
910 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
|
911 d.addCallback(saveType) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
912 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
|
913 d.addCallback(saveMetaData) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
914 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
|
915 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
|
916 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
917 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
918 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
919 def getNodes(self, requestor, service, nodeIdentifier): |
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
|
920 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
|
921 return defer.succeed([]) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
922 d = self.backend.getNodes() |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
923 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
|
924 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
925 |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
926 def getConfigurationOptions(self): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
927 return self.backend.nodeOptions |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
928 |
228 | 929 def _publish_errb(self, failure, request): |
930 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
|
931 print "Auto-creating node %s" % (request.nodeIdentifier,) |
228 | 932 d = self.backend.createNode(request.nodeIdentifier, |
933 request.sender) | |
934 d.addCallback(lambda ignore, | |
935 request: self.backend.publish(request.nodeIdentifier, | |
936 request.items, | |
937 request.sender), | |
938 request) | |
939 return d | |
940 | |
240
70c8bb90d75f
added access_model to config, default to 'open'
Goffi <goffi@goffi.org>
parents:
237
diff
changeset
|
941 return failure |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
202
diff
changeset
|
942 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
943 def publish(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
944 d = self.backend.publish(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
945 request.items, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
946 request.sender) |
228 | 947 d.addErrback(self._publish_errb, request) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
948 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
949 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
950 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
951 def subscribe(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
952 d = self.backend.subscribe(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
953 request.subscriber, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
954 request.sender) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
955 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
956 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
957 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
958 def unsubscribe(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
959 d = self.backend.unsubscribe(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
960 request.subscriber, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
961 request.sender) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
962 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
963 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
964 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
965 def subscriptions(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
966 d = self.backend.getSubscriptions(request.sender) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
967 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
|
968 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
969 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
970 def affiliations(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
971 d = self.backend.getAffiliations(request.sender) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
972 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
973 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
974 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
975 def create(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
976 d = self.backend.createNode(request.nodeIdentifier, |
259
6fe7da6b4b32
node "roster" access model management
Goffi <goffi@goffi.org>
parents:
258
diff
changeset
|
977 request.sender, request.options) |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
978 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
979 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
980 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
981 def default(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
982 d = self.backend.getDefaultConfiguration(request.nodeType) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
983 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
984 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
985 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
986 def configureGet(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
987 d = self.backend.getNodeConfiguration(request.nodeIdentifier) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
988 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
|
989 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
990 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
991 def configureSet(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
992 d = self.backend.setNodeConfiguration(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
993 request.options, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
994 request.sender) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
995 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
996 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
997 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
998 def items(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
999 d = self.backend.getItems(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1000 request.sender, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1001 request.maxItems, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1002 request.itemIdentifiers) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1003 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
1004 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1005 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1006 def retract(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1007 d = self.backend.retractItem(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1008 request.itemIdentifiers, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1009 request.sender) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1010 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
|
1011 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
196
diff
changeset
|
1012 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1013 def purge(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1014 d = self.backend.purgeNode(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1015 request.sender) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1016 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
|
1017 |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1018 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1019 def delete(self, request): |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1020 d = self.backend.deleteNode(request.nodeIdentifier, |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1021 request.sender) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1022 return d.addErrback(self._mapErrors) |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1023 |
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1024 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
|
1025 IBackendService, |
222
698af5d720ad
Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents:
216
diff
changeset
|
1026 IPubSubResource) |