annotate sat_pubsub/backend.py @ 255:d55620ceafed

copyright update
author Goffi <goffi@goffi.org>
date Mon, 08 Apr 2013 23:08:45 +0200
parents 25a1dc7181cc
children ea44c0986f47
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1 #!/usr/bin/python
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
2 #-*- coding: utf-8 -*-
237
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
3 #
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
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
d55620ceafed copyright update
Goffi <goffi@goffi.org>
parents: 252
diff changeset
6 Copyright (c) 2012, 2013 Jérôme Poisson
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
7
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
8
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
9 This program is free software: you can redistribute it and/or modify
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
10 it under the terms of the GNU Affero General Public License as published by
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
11 the Free Software Foundation, either version 3 of the License, or
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
12 (at your option) any later version.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
13
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
14 This program is distributed in the hope that it will be useful,
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
17 GNU Affero General Public License for more details.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
18
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
19 You should have received a copy of the GNU Affero General Public License
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
21 --
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
22
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
23 This program is based on Idavoll (http://idavoll.ik.nu/),
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
24 originaly written by Ralph Meijer (http://ralphm.net/blog/)
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
25 It is sublicensed under AGPL v3 (or any later version) as allowed by the original
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
26 license.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
27
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
28 --
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
29
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
30 Here is a copy of the original license:
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
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
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
33
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
34 Permission is hereby granted, free of charge, to any person obtaining
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
35 a copy of this software and associated documentation files (the
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
36 "Software"), to deal in the Software without restriction, including
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
37 without limitation the rights to use, copy, modify, merge, publish,
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
38 distribute, sublicense, and/or sell copies of the Software, and to
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
39 permit persons to whom the Software is furnished to do so, subject to
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
40 the following conditions:
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
41
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
42 The above copyright notice and this permission notice shall be
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
43 included in all copies or substantial portions of the Software.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
44
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
45 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
46 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
47 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
48 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
49 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
50 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
51 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
52
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
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
2189c663ba44 Epytext fixes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
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
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
75
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
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
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
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
46cd13c68ac0 Redone memory storage of nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 5
diff changeset
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
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
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 },
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
119 }
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
120
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
121 subscriptionOptions = {
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
122 "pubsub#subscription_type":
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
123 {"type": "list-single",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
124 "options": {
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
125 "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
126 "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
127 },
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
128 "pubsub#subscription_depth":
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
129 {"type": "list-single",
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
130 "options": {
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
131 "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
132 "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
133 },
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
134 }
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
135
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
136 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
137 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
138 self.storage = storage
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
139 self._callbackList = []
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
140
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
141
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
142 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
143 return True
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
144
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
145
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
146 def supportsGroupBlog(self):
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
147 return True
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
148
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
149
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
150 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
151 return True
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
152
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
153
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
154 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
155 return True
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
156
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
157
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
158 def getNodeType(self, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
159 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
160 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
161 return d
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 getNodes(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
165 return self.storage.getNodeIds()
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
166
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
167
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
168 def getNodeMetaData(self, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
169 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
170 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
171 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
172 return d
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
173
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
174
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
175 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
176 options = []
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
177 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
178 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
179 option = {"var": key}
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
180 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
181 option["value"] = value
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
182 options.append(option)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
183
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
184 return options
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
185
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
186
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
187 def _checkAuth(self, node, requestor):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
188 def check(affiliation, node):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
189 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
190 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
191 return node
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
192
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
193 d = node.getAffiliation(requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
194 d.addCallback(check, node)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
195 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
196
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
197 def parseItemConfig(self, item):
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
198 """Get and remove item configuration information
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
199 @param item:
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
200 """
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
201 item_config = None
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
202 access_model = const.VAL_DEFAULT
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
203 for i in range(len(item.children)):
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
204 elt = item.children[i]
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
205 if not (elt.uri,elt.name)==(data_form.NS_X_DATA,'x'):
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
206 continue
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
207 form = data_form.Form.fromElement(elt)
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
208 if (form.formNamespace == const.NS_ITEM_CONFIG):
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
209 item_config = form
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
210 del item.children[i] #we need to remove the config from item
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
211 break
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
212
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
213 if item_config:
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
214 access_model = item_config.get(const.OPT_ACCESS_MODEL, const.VAL_DEFAULT)
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
215
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
216 return (access_model, item_config)
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
217
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
218
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
219 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
220 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
221 d.addCallback(self._checkAuth, requestor)
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
222 #FIXME: owner and publisher are not necessarly the same. So far we use only owner to get roster.
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
223 #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
224 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
225 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
226
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
227
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
228 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
229 if node.nodeType == 'collection':
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
230 raise error.NoPublishing()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
231
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
232 configuration = node.getConfiguration()
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
233 persistItems = configuration["pubsub#persist_items"]
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
234 deliverPayloads = configuration["pubsub#deliver_payloads"]
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
235
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
236 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
237 raise error.ItemForbidden()
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
238 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
239 raise error.ItemRequired()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
240
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
241 parsed_items = []
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
242 for item in items:
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
243 if persistItems or deliverPayloads:
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
244 item.uri = None
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
245 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
246 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
247 item["id"] = str(uuid.uuid4())
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
248 access_model, item_config = self.parseItemConfig(item)
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
249 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
250
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
251 if persistItems:
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
252 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
253 else:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
254 d = defer.succeed(None)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
255
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
256 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
257 deliverPayloads)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
258 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
259
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
260
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
261 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
262 if items and not deliverPayloads:
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
263 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
264 item.children = []
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
265
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
266 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
267 '//event/pubsub/notify')
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
268
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
269
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
270 def getNotifications(self, nodeIdentifier, items):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
271
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
272 def toNotifications(subscriptions, nodeIdentifier, items):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
273 subsBySubscriber = {}
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
274 for subscription in subscriptions:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
275 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
276 'items') == 'items':
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
277 subs = subsBySubscriber.setdefault(subscription.subscriber,
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
278 set())
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
279 subs.add(subscription)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
280
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
281 notifications = [(subscriber, subscriptions, items)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
282 for subscriber, subscriptions
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
283 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
284
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
285 return notifications
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
286
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
287 def rootNotFound(failure):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
288 failure.trap(error.NodeNotFound)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
289 return []
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
290
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
291 d1 = self.storage.getNode(nodeIdentifier)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
292 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
293 d2 = self.storage.getNode('')
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
294 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
295 d2.addErrback(rootNotFound)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
296 d = defer.gatherResults([d1, d2])
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
297 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
298 d.addCallback(toNotifications, nodeIdentifier, items)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
299 return d
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
300
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
301
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
302 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
303 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
304
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
305
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
306 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
307 subscriberEntity = subscriber.userhostJID()
216
53d2c0019458 Fix subscription and unsubscription JID checks.
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
308 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
309 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
310
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
311 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
312 d.addCallback(_getAffiliation, subscriberEntity)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
313 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
314 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
315
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
316
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
317 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
318 node, affiliation = result
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
319 #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
320
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
321 if affiliation == 'outcast':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
322 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
323
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
324 def trapExists(failure):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
325 failure.trap(error.SubscriptionExists)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
326 return False
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
327
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
328 def cb(sendLast):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
329 d = node.getSubscription(subscriber)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
330 if sendLast:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
331 d.addCallback(self._sendLastPublished, node)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
332 return d
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
333
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
334 d = node.addSubscription(subscriber, 'subscribed', {})
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
335 d.addCallbacks(lambda _: True, trapExists)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
336 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
337 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
338
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
339
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
340 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
341
202
77c61e2b8c75 Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents: 201
diff changeset
342 def notifyItem(items):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
343 if items:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
344 reactor.callLater(0, self.dispatch,
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
345 {'items': items,
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
346 'nodeIdentifier': node.nodeIdentifier,
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
347 'subscription': subscription},
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
348 '//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
349
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
350 config = node.getConfiguration()
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
351 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
352 'never')
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
353 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
354 entity = subscription.subscriber.userhostJID()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
355 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
356 d.addCallback(notifyItem)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
357 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
358
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
359 return subscription
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
360
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
361
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
362 def unsubscribe(self, nodeIdentifier, subscriber, requestor):
216
53d2c0019458 Fix subscription and unsubscription JID checks.
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
363 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
364 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
365
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
366 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
367 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
368 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
369
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
370
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
371 def getSubscriptions(self, entity):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
372 return self.storage.getSubscriptions(entity)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
373
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
374 def supportsAutoCreate(self):
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
375 return True
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
376
237
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
377 def supportsCreatorCheck(self):
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
378 return True
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
379
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
380 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
381 return True
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
382
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
383
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
384 def createNode(self, nodeIdentifier, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
385 if not nodeIdentifier:
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
386 nodeIdentifier = 'generic/%s' % uuid.uuid4()
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
387
237
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
388 if self.supportsCreatorCheck():
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
389 groupblog = nodeIdentifier.startswith(const.NS_GROUPBLOG_PREFIX)
237
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
390 try:
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
391 nodeIdentifierJID = JID(nodeIdentifier[len(const.NS_GROUPBLOG_PREFIX):] if groupblog else nodeIdentifier)
237
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
392 except InvalidFormat:
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
393 is_user_jid = False
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
394 else:
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
395 is_user_jid = bool(nodeIdentifierJID.user)
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
396
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
397 if is_user_jid and nodeIdentifierJID.userhost() != requestor.userhost():
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
398 #we have an user jid node, but not created by the owner of this jid
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
399 print "Wrong creator"
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
400 raise error.Forbidden()
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
401
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
402 nodeType = 'leaf'
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
403 config = self.storage.getDefaultConfiguration(nodeType)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
404 config['pubsub#node_type'] = nodeType
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
405
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
406 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
407 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
408 return d
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
409
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
410
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
411 def getDefaultConfiguration(self, nodeType):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
412 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
413 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
414
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
415
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
416 def getNodeConfiguration(self, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
417 if not nodeIdentifier:
196
00a6dbfbee42 Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
418 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
419
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
420 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
421 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
422
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
423 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
424
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
425
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
426 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
427 if not nodeIdentifier:
196
00a6dbfbee42 Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
428 return defer.fail(error.NoRootNode())
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
429
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
430 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
431 d.addCallback(_getAffiliation, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
432 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
433 return d
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
434
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
435
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
436 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
437 node, affiliation = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
438
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
439 if affiliation != 'owner':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
440 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
441
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
442 return node.setConfiguration(options)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
443
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
444
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
445 def getAffiliations(self, entity):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
446 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
447
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
448
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
449 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
450 itemIdentifiers=None):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
451 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
452 d.addCallback(_getAffiliation, requestor)
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
453 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
454 return d
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
455
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
456 def checkGroup(self, roster_groups, entity):
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
457 """Check that requester is in roster
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
458 @param roster_group: tuple which 2 items:
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
459 - 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
460 - groups: list of authorized groups
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
461 @param entity: entity which must be in group
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
462 @return: True if requestor is in roster"""
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
463 roster, authorized_groups = roster_groups
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
464 _entity = entity.userhost()
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
465
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
466 if not _entity in roster:
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
467 raise error.NotInRoster
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
468 if roster[_entity].groups.intersection(authorized_groups):
248
50f6ee966da8 item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents: 243
diff changeset
469 return (True, roster)
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
470 raise error.NotInRoster
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
471
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
472 def _getNodeGroups(self, roster, nodeIdentifier):
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
473 d = self.storage.getNodeGroups(nodeIdentifier)
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
474 d.addCallback(lambda groups: (roster, groups))
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
475 return d
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
476
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
477 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
478 node, affiliation = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
479
252
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
480 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
481 ret = []
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
482 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
483 item, access_model, access_list = data
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
484 if access_model == const.VAL_OPEN:
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
485 pass
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
486 elif access_model == const.VAL_ROSTER:
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
487 form = data_form.Form('submit', formNamespace=const.NS_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
488 access = data_form.Field(None, const.OPT_ACCESS_MODEL, value=const.VAL_ROSTER)
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
489 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
490 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
491 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
492 item.addChild(form.toElement())
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
493 elif access_model == const.VAL_JID:
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
494 #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
495 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
496 else:
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
497 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
498
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
499 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
500 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
501
248
50f6ee966da8 item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents: 243
diff changeset
502 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
503 authorized, roster = access_data
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
504 if not authorized:
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
505 raise error.NotAuthorized()
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
506
248
50f6ee966da8 item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents: 243
diff changeset
507 roster_item = roster.get(requestor.userhost())
50f6ee966da8 item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents: 243
diff changeset
508 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
509
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
510 if itemIdentifiers:
248
50f6ee966da8 item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents: 243
diff changeset
511 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
512 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
513 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
514 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
515 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
516 else:
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
517 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
518
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
519
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
520 if not ILeafNode.providedBy(node):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
521 return []
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
522
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
523 if affiliation == 'outcast':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
524 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
525
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
526 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
527 d = node.getNodeOwner()
50f6ee966da8 item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents: 243
diff changeset
528 d.addCallback(self.roster.getRoster)
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
529
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
530 if access_model == 'open' or affiliation == 'owner':
248
50f6ee966da8 item are gotten according to item's access model in getItems
Goffi <goffi@goffi.org>
parents: 243
diff changeset
531 d.addCallback(lambda roster: (True,roster))
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
532 d.addCallback(access_checked)
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
533 elif access_model == 'roster':
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
534 d.addCallback(self._getNodeGroups,node.nodeIdentifier)
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
535 d.addCallback(self.checkGroup, requestor)
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
536 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
537
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
538 return d
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
539
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
540 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
541 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
542 d.addCallback(_getAffiliation, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
543 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
544 return d
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
545
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
546
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
547 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
548 node, affiliation = result
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
549 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
550
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
551 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
552 raise error.Forbidden()
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
553
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
554 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
555 raise error.NodeNotPersistent()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
556
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
557 d = node.removeItems(itemIdentifiers)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
558 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
559 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
560
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
561
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
562 def _doNotifyRetraction(self, itemIdentifiers, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
563 self.dispatch({'itemIdentifiers': itemIdentifiers,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
564 'nodeIdentifier': nodeIdentifier },
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
565 '//event/pubsub/retract')
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
566
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
567
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
568 def purgeNode(self, nodeIdentifier, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
569 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
570 d.addCallback(_getAffiliation, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
571 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
572 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
573
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
574
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
575 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
576 node, affiliation = result
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
577 persistItems = node.getConfiguration()["pubsub#persist_items"]
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
578
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
579 if affiliation != 'owner':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
580 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
581
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
582 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
583 raise error.NodeNotPersistent()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
584
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
585 d = node.purge()
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
586 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
587 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
588
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
589
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
590 def _doNotifyPurge(self, result, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
591 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
592
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
593
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
594 def registerPreDelete(self, preDeleteFn):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
595 self._callbackList.append(preDeleteFn)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
596
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
597
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
598 def getSubscribers(self, nodeIdentifier):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
599 def cb(subscriptions):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
600 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
601
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
602 d = self.storage.getNode(nodeIdentifier)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
603 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
604 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
605 return d
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
606
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
607
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
608 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
609 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
610 d.addCallback(_getAffiliation, requestor)
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
611 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
612 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
613
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
614
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
615 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
616 node, affiliation = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
617
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
618 if affiliation != 'owner':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
619 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
620
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
621 data = {'nodeIdentifier': node.nodeIdentifier,
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
622 'redirectURI': redirectURI}
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
623
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
624 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
625 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
626 consumeErrors=1)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
627 d.addCallback(self._doDelete, node.nodeIdentifier)
59
0fa161c00ed9 Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents: 53
diff changeset
628
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
629
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
630 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
631 dl = []
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
632 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
633 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
634 dl.extend(r)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
635
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
636 d = self.storage.deleteNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
637 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
638
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
639 return d
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
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 _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
643 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
644 d.callback(None)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
645
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
646
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
647
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
648 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
649 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
650 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
651 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
652
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
653 features = [
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
654 "config-node",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
655 "create-nodes",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
656 "delete-any",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
657 "delete-nodes",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
658 "item-ids",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
659 "meta-data",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
660 "publish",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
661 "purge-nodes",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
662 "retract-items",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
663 "retrieve-affiliations",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
664 "retrieve-default",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
665 "retrieve-items",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
666 "retrieve-subscriptions",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
667 "subscribe",
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
668 ]
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
669
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
670 discoIdentity = disco.DiscoIdentity('pubsub',
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
671 'service',
236
65bc75603539 renamed service to « Salut à Toi pubsub service »
Goffi <goffi@goffi.org>
parents: 235
diff changeset
672 u'Salut à Toi pubsub service')
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
673
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
674 pubsubService = None
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
675
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
676 _errorMap = {
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
677 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
678 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
679 error.Forbidden: ('forbidden', None, None),
243
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
680 error.NotAuthorized: ('not-authorized', None, None),
42048e37699e added experimental roster access_model (use remote_roster)
Goffi <goffi@goffi.org>
parents: 240
diff changeset
681 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
682 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
683 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
684 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
685 'unsupported',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
686 'instant-nodes'),
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
687 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
688 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
689 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
690 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
691 'unsupported',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
692 'persistent-node'),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
693 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
694 error.NoCollections: ('feature-not-implemented',
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
695 'unsupported',
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
696 'collections'),
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
697 error.NoPublishing: ('feature-not-implemented',
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
698 'unsupported',
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
699 'publish'),
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
700 }
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
701
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
702 def __init__(self, backend):
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
703 PubSubResource.__init__(self)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
704
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
705 self.backend = backend
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
706 self.hideNodes = False
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
707
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
708 self.backend.registerNotifier(self._notify)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
709 self.backend.registerPreDelete(self._preDelete)
240
70c8bb90d75f added access_model to config, default to 'open'
Goffi <goffi@goffi.org>
parents: 237
diff changeset
710
237
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
711 if self.backend.supportsCreatorCheck():
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
712 self.features.append("creator-jid-check") #SàT custom feature: Check that a node (which correspond to
6596730685e8 added creator check support
Goffi <goffi@goffi.org>
parents: 236
diff changeset
713 # 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
714
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
715 if self.backend.supportsAutoCreate():
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
716 self.features.append("auto-create")
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
717
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
718 if self.backend.supportsInstantNodes():
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
719 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
720
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
721 if self.backend.supportsOutcastAffiliation():
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
722 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
723
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
724 if self.backend.supportsPersistentItems():
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
725 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
726
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
727 if self.backend.supportsPublisherAffiliation():
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
728 self.features.append("publisher-affiliation")
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
729
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
730 if self.backend.supportsGroupBlog():
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
731 self.features.append("groupblog")
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
732
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
733 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
734 items = data['items']
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
735 node = data['node']
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
736
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
737 def _notifyAllowed(result):
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
738 """Check access of subscriber for each item,
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
739 and notify only allowed ones"""
251
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
740 notifications, (owner_jid,roster) = result
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
741
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
742 #we filter items not allowed for the subscribers
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
743 notifications_filtered = []
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
744
252
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
745 for subscriber, subscriptions, _items in notifications:
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
746 allowed_items = [] #we keep only item which subscriber can access
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
747
252
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
748 for access_model, item_config, item in _items:
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
749 if access_model == 'open':
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
750 allowed_items.append(item)
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
751 elif access_model == 'roster':
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
752 _subscriber = subscriber.userhost()
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
753 if not _subscriber in roster:
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
754 continue
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
755 #the subscriber is known, is he in the right group ?
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
756 authorized_groups = item_config[const.OPT_ROSTER_GROUPS_ALLOWED]
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
757 if roster[_subscriber].groups.intersection(authorized_groups):
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
758 allowed_items.append(item)
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
759
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
760 else: #unknown access_model
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
761 raise NotImplementedError
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
762
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
763 notifications_filtered.append((subscriber, subscriptions, allowed_items))
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
764
251
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
765 #we notify the owner
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
766 #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
767 #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
768 #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
769
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
770 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
771 """ 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
772 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
773 """
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
774 #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
775
25a1dc7181cc full items, with item-configuration, are returned if items are asked by the owner
Goffi <goffi@goffi.org>
parents: 251
diff changeset
776 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
777 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
778 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
779 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
780 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
781
251
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
782 notifications_filtered.append((owner_jid,
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
783 set([Subscription(node.nodeIdentifier,
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
784 owner_jid,
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
785 '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
786 [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
787
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
788 return self.pubsubService.notifyPublish(
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
789 self.serviceJID,
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
790 node.nodeIdentifier,
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
791 notifications_filtered)
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
792
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
793
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
794 if 'subscription' not in data:
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
795 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
796 else:
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
797 subscription = data['subscription']
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
798 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
799 items)])
251
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
800
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
801 def _got_owner(owner_jid):
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
802 #return a tuple with owner_jid and roster
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
803 d = self.backend.roster.getRoster(owner_jid)
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
804 return d.addCallback(lambda roster: (owner_jid,roster))
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
805
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
806 d2 = node.getNodeOwner()
251
0a7d43b3dad6 owner is now notified of items published
Goffi <goffi@goffi.org>
parents: 250
diff changeset
807 d2.addCallback(_got_owner)
250
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
808
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
809 d = defer.gatherResults([d1, d2])
eb14b8d30cba fine tuning per-item permissions
Goffi <goffi@goffi.org>
parents: 248
diff changeset
810 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
811
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
812
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
813 def _preDelete(self, data):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
814 nodeIdentifier = data['nodeIdentifier']
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
815 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
816 d = self.backend.getSubscribers(nodeIdentifier)
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
817 d.addCallback(lambda subscribers: self.pubsubService.notifyDelete(
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
818 self.serviceJID,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
819 nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
820 subscribers,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
821 redirectURI))
174
79d451d186b1 Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
822 return d
79d451d186b1 Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
823
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
824
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
825 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
826 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
827
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
828 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
829 msg = failure.value.msg
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
830
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
831 if pubsubCondition:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
832 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
833 else:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
834 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
835
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
836 raise exc
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
837
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
838 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
839 info = {}
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
840
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
841 def saveType(result):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
842 info['type'] = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
843 return nodeIdentifier
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
844
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
845 def saveMetaData(result):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
846 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
847 return info
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
848
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
849 def trapNotFound(failure):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
850 failure.trap(error.NodeNotFound)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
851 return info
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
852
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
853 d = defer.succeed(nodeIdentifier)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
854 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
855 d.addCallback(saveType)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
856 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
857 d.addCallback(saveMetaData)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
858 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
859 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
860 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
861
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
862
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
863 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
864 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
865 return defer.succeed([])
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
866 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
867 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
868
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
869
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
870 def getConfigurationOptions(self):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
871 return self.backend.nodeOptions
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
872
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
873 def _publish_errb(self, failure, request):
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
874 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
875 print "Auto-creating node %s" % (request.nodeIdentifier,)
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
876 d = self.backend.createNode(request.nodeIdentifier,
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
877 request.sender)
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
878 d.addCallback(lambda ignore,
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
879 request: self.backend.publish(request.nodeIdentifier,
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
880 request.items,
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
881 request.sender),
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
882 request)
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
883 return d
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
884
240
70c8bb90d75f added access_model to config, default to 'open'
Goffi <goffi@goffi.org>
parents: 237
diff changeset
885 return failure
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
886
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
887 def publish(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
888 d = self.backend.publish(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
889 request.items,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
890 request.sender)
228
77029ecf9817 added auto-create support
Goffi <goffi@goffi.org>
parents: 223
diff changeset
891 d.addErrback(self._publish_errb, request)
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
892 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
893
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
894
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
895 def subscribe(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
896 d = self.backend.subscribe(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
897 request.subscriber,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
898 request.sender)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
899 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
900
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
901
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
902 def unsubscribe(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
903 d = self.backend.unsubscribe(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
904 request.subscriber,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
905 request.sender)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
906 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
907
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
908
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
909 def subscriptions(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
910 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
911 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
912
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
913
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
914 def affiliations(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
915 d = self.backend.getAffiliations(request.sender)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
916 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
917
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
918
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
919 def create(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
920 d = self.backend.createNode(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
921 request.sender)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
922 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
923
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
924
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
925 def default(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
926 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
927 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
928
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
929
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
930 def configureGet(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
931 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
932 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
933
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
934
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
935 def configureSet(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
936 d = self.backend.setNodeConfiguration(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
937 request.options,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
938 request.sender)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
939 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
940
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
941
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
942 def items(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
943 d = self.backend.getItems(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
944 request.sender,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
945 request.maxItems,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
946 request.itemIdentifiers)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
947 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
948
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
949
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
950 def retract(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
951 d = self.backend.retractItem(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
952 request.itemIdentifiers,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
953 request.sender)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
954 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
955
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
956
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
957 def purge(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
958 d = self.backend.purgeNode(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
959 request.sender)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
960 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
961
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
962
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
963 def delete(self, request):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
964 d = self.backend.deleteNode(request.nodeIdentifier,
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
965 request.sender)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
966 return d.addErrback(self._mapErrors)
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
967
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
968 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
969 IBackendService,
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 216
diff changeset
970 IPubSubResource)