Mercurial > libervia-pubsub
annotate idavoll/backend.py @ 180:fc687620599b
Properly add send_last_published_item configuration item.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Thu, 10 Apr 2008 14:33:50 +0000 |
parents | 42e23a62b57f |
children | 0d4474051eeb |
rev | line source |
---|---|
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
1 # -*- test-case-name: idavoll.test.test_backend -*- |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
2 # |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
3 # Copyright (c) 2003-2008 Ralph Meijer |
155
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
153
diff
changeset
|
4 # See LICENSE for details. |
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
153
diff
changeset
|
5 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
6 import uuid |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
7 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
8 from zope.interface import implements |
2 | 9 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
10 from twisted.application import service |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
11 from twisted.python import components |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
12 from twisted.internet import defer |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
13 from twisted.words.protocols.jabber.error import StanzaError |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
14 from twisted.words.xish import utility |
1 | 15 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
16 from wokkel.iwokkel import IDisco, IPubSubService |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
17 from wokkel.pubsub import PubSubService, PubSubError |
20
eddea65d1032
Added two exceptions: NoInstantNodes and NodeExists.
Ralph Meijer <ralphm@ik.nu>
parents:
18
diff
changeset
|
18 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
19 from idavoll import error, iidavoll |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
20 from idavoll.iidavoll import IBackendService |
15 | 21 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
22 def _get_affiliation(node, entity): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
23 d = node.get_affiliation(entity) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
24 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
|
25 return d |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
20
diff
changeset
|
26 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
27 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
28 class BackendService(service.Service, utility.EventDispatcher): |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
29 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
30 implements(iidavoll.IBackendService) |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
31 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
32 options = {"pubsub#persist_items": |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
33 {"type": "boolean", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
34 "label": "Persist items to storage"}, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
35 "pubsub#deliver_payloads": |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
36 {"type": "boolean", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
37 "label": "Deliver payloads with event notifications"}, |
180
fc687620599b
Properly add send_last_published_item configuration item.
Ralph Meijer <ralphm@ik.nu>
parents:
179
diff
changeset
|
38 "pubsub#send_last_published_item": |
fc687620599b
Properly add send_last_published_item configuration item.
Ralph Meijer <ralphm@ik.nu>
parents:
179
diff
changeset
|
39 {"type": "list-single", |
fc687620599b
Properly add send_last_published_item configuration item.
Ralph Meijer <ralphm@ik.nu>
parents:
179
diff
changeset
|
40 "label": "When to send the last published item', |
fc687620599b
Properly add send_last_published_item configuration item.
Ralph Meijer <ralphm@ik.nu>
parents:
179
diff
changeset
|
41 "options": {'never', 'on_sub'}, |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
42 } |
159
6fe78048baf9
Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents:
155
diff
changeset
|
43 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
44 default_config = {"pubsub#persist_items": True, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
45 "pubsub#deliver_payloads": True, |
180
fc687620599b
Properly add send_last_published_item configuration item.
Ralph Meijer <ralphm@ik.nu>
parents:
179
diff
changeset
|
46 "pubsub#send_last_published_item": 'on_sub', |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
47 } |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
48 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
49 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
|
50 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
|
51 self.storage = storage |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
52 self._callback_list = [] |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
53 |
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
54 def supports_publisher_affiliation(self): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
55 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
56 |
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
57 def supports_outcast_affiliation(self): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
58 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
59 |
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
60 def supports_persistent_items(self): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
61 return True |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
62 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
63 def get_node_type(self, node_id): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
64 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
65 d.addCallback(lambda node: node.get_type()) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
66 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
67 |
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
68 def get_nodes(self): |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
69 return self.storage.get_node_ids() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
70 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
71 def get_node_meta_data(self, node_id): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
72 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
73 d.addCallback(lambda node: node.get_meta_data()) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
74 d.addCallback(self._make_meta_data) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
75 return d |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
76 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
77 def _make_meta_data(self, meta_data): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
78 options = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
79 for key, value in meta_data.iteritems(): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
80 if self.options.has_key(key): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
81 option = {"var": key} |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
82 option.update(self.options[key]) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
83 option["value"] = value |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
84 options.append(option) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
85 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
86 return options |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
87 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
88 def _check_auth(self, node, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
89 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
|
90 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
|
91 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
92 return node |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
93 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
94 d = node.get_affiliation(requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
95 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
|
96 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
97 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
98 def publish(self, node_id, items, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
99 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
100 d.addCallback(self._check_auth, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
101 d.addCallback(self._do_publish, items, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
102 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
103 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
104 def _do_publish(self, node, items, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
105 configuration = node.get_configuration() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
106 persist_items = configuration["pubsub#persist_items"] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
107 deliver_payloads = configuration["pubsub#deliver_payloads"] |
108
1c18759d2afb
Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents:
106
diff
changeset
|
108 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
109 if items and not persist_items and not deliver_payloads: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
110 raise error.ItemForbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
111 elif not items and (persist_items or deliver_payloads): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
112 raise error.ItemRequired() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
113 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
114 if persist_items or deliver_payloads: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
115 for item in items: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
116 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
|
117 item["id"] = str(uuid.uuid4()) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
118 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
119 if persist_items: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
120 d = node.store_items(items, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
121 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
122 d = defer.succeed(None) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
123 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
124 d.addCallback(self._do_notify, node.id, items, deliver_payloads) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
125 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
126 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
127 def _do_notify(self, result, node_id, items, deliver_payloads): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
128 if items and not deliver_payloads: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
129 for item in items: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
130 item.children = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
131 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
132 self.dispatch({'items': items, 'node_id': node_id}, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
133 '//event/pubsub/notify') |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
134 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
135 def get_notification_list(self, node_id, items): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
136 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
137 d.addCallback(lambda node: node.get_subscribers()) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
138 d.addCallback(self._magic_filter, node_id, items) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
139 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
140 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
141 def _magic_filter(self, subscribers, node_id, items): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
142 list = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
143 for subscriber in subscribers: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
144 list.append((subscriber, items)) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
145 return list |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
146 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
147 def register_notifier(self, observerfn, *args, **kwargs): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
148 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
|
149 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
150 def subscribe(self, node_id, subscriber, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
151 subscriber_entity = subscriber.userhostJID() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
152 if subscriber_entity != requestor: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
153 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
|
154 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
155 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
156 d.addCallback(_get_affiliation, subscriber_entity) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
157 d.addCallback(self._do_subscribe, subscriber) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
158 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
159 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
160 def _do_subscribe(self, result, subscriber): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
161 node, affiliation = result |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
162 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
163 if affiliation == 'outcast': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
164 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
165 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
166 d = node.add_subscription(subscriber, 'subscribed') |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
167 d.addCallback(lambda _: self._send_last_published(node, subscriber)) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
168 d.addCallback(lambda _: 'subscribed') |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
169 d.addErrback(self._get_subscription, node, subscriber) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
170 d.addCallback(self._return_subscription, node.id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
171 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
172 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
173 def _get_subscription(self, failure, node, subscriber): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
174 failure.trap(error.SubscriptionExists) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
175 return node.get_subscription(subscriber) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
176 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
177 def _return_subscription(self, result, node_id): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
178 return node_id, result |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
179 |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
180 def _send_last_published(self, node, subscriber): |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
181 def notify_item(items): |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
182 if not items: |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
183 return |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
184 |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
185 self.dispatch({'items': items, |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
186 'node_id': node.id, |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
187 'subscriber': subscriber}, |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
188 '//event/pubsub/notify') |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
189 |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
190 config = node.get_configuration() |
179
42e23a62b57f
Guard against missing config for sending last published item on subscription.
Ralph Meijer <ralphm@ik.nu>
parents:
178
diff
changeset
|
191 if config.get("pubsub#send_last_published_item", 'never') != 'on_sub': |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
192 return |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
193 |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
194 d = self.get_items(node.id, subscriber.userhostJID(), 1) |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
195 d.addCallback(notify_item) |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
196 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
197 def unsubscribe(self, node_id, subscriber, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
198 if subscriber.userhostJID() != requestor: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
199 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
|
200 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
201 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
202 d.addCallback(lambda node: node.remove_subscription(subscriber)) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
203 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
204 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
205 def get_subscriptions(self, entity): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
206 return self.storage.get_subscriptions(entity) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
207 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
208 def supports_instant_nodes(self): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
209 return True |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
210 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
211 def create_node(self, node_id, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
212 if not node_id: |
168
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
213 node_id = 'generic/%s' % uuid.uuid4() |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
214 d = self.storage.create_node(node_id, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
215 d.addCallback(lambda _: node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
216 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
217 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
218 def get_default_configuration(self): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
219 d = defer.succeed(self.default_config) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
220 d.addCallback(self._make_config) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
221 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
222 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
223 def get_node_configuration(self, node_id): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
224 if not node_id: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
225 raise error.NoRootNode() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
226 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
227 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
228 d.addCallback(lambda node: node.get_configuration()) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
229 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
230 d.addCallback(self._make_config) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
231 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
232 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
233 def _make_config(self, config): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
234 options = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
235 for key, value in self.options.iteritems(): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
236 option = {"var": key} |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
237 option.update(value) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
238 if config.has_key(key): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
239 option["value"] = config[key] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
240 options.append(option) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
241 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
242 return options |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
243 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
244 def set_node_configuration(self, node_id, options, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
245 if not node_id: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
246 raise error.NoRootNode() |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
247 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
248 for key, value in options.iteritems(): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
249 if not self.options.has_key(key): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
250 raise error.InvalidConfigurationOption() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
251 if self.options[key]["type"] == 'boolean': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
252 try: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
253 options[key] = bool(int(value)) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
254 except ValueError: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
255 raise error.InvalidConfigurationValue() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
256 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
257 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
258 d.addCallback(_get_affiliation, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
259 d.addCallback(self._do_set_node_configuration, options) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
260 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
261 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
262 def _do_set_node_configuration(self, result, options): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
263 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
264 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
265 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
266 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
267 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
268 return node.set_configuration(options) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
269 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
270 def get_affiliations(self, entity): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
271 return self.storage.get_affiliations(entity) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
272 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
273 def get_items(self, node_id, requestor, max_items=None, item_ids=[]): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
274 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
275 d.addCallback(_get_affiliation, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
276 d.addCallback(self._do_get_items, max_items, item_ids) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
277 return d |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
278 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
279 def _do_get_items(self, result, max_items, item_ids): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
280 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
281 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
282 if affiliation == 'outcast': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
283 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
284 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
285 if item_ids: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
286 return node.get_items_by_id(item_ids) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
287 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
288 return node.get_items(max_items) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
289 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
290 def retract_item(self, node_id, item_ids, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
291 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
292 d.addCallback(_get_affiliation, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
293 d.addCallback(self._do_retract, item_ids) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
294 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
295 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
296 def _do_retract(self, result, item_ids): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
297 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
298 persist_items = node.get_configuration()["pubsub#persist_items"] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
299 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
300 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
|
301 raise error.Forbidden() |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
302 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
303 if not persist_items: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
304 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
305 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
306 d = node.remove_items(item_ids) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
307 d.addCallback(self._do_notify_retraction, node.id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
308 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
309 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
310 def _do_notify_retraction(self, item_ids, node_id): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
311 self.dispatch({ 'item_ids': item_ids, 'node_id': node_id }, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
312 '//event/pubsub/retract') |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
313 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
314 def purge_node(self, node_id, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
315 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
316 d.addCallback(_get_affiliation, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
317 d.addCallback(self._do_purge) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
318 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
319 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
320 def _do_purge(self, result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
321 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
322 persist_items = node.get_configuration()["pubsub#persist_items"] |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
323 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
324 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
325 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
326 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
327 if not persist_items: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
328 raise error.NodeNotPersistent() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
329 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
330 d = node.purge() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
331 d.addCallback(self._do_notify_purge, node.id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
332 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
333 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
334 def _do_notify_purge(self, result, node_id): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
335 self.dispatch(node_id, '//event/pubsub/purge') |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
336 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
337 def register_pre_delete(self, pre_delete_fn): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
338 self._callback_list.append(pre_delete_fn) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
339 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
340 def get_subscribers(self, node_id): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
341 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
342 d.addCallback(lambda node: node.get_subscribers()) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
343 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
344 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
345 def delete_node(self, node_id, requestor): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
346 d = self.storage.get_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
347 d.addCallback(_get_affiliation, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
348 d.addCallback(self._do_pre_delete) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
349 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
350 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
351 def _do_pre_delete(self, result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
352 node, affiliation = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
353 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
354 if affiliation != 'owner': |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
355 raise error.Forbidden() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
356 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
357 d = defer.DeferredList([cb(node.id) for cb in self._callback_list], |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
358 consumeErrors=1) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
359 d.addCallback(self._do_delete, node.id) |
59
0fa161c00ed9
Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents:
53
diff
changeset
|
360 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
361 def _do_delete(self, result, node_id): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
362 dl = [] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
363 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
|
364 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
|
365 dl.extend(r) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
366 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
367 d = self.storage.delete_node(node_id) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
368 d.addCallback(self._do_notify_delete, dl) |
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 return d |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
371 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
372 def _do_notify_delete(self, result, dl): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
373 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
|
374 d.callback(None) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
375 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
376 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
377 class PubSubServiceFromBackend(PubSubService): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
378 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
379 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
|
380 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
381 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
382 implements(IDisco) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
383 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
384 _errorMap = { |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
385 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
|
386 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
|
387 error.Forbidden: ('forbidden', None, None), |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
392 'instant-nodes'), |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
169
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 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
|
397 'unsupported', |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
398 'persistent-node'), |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
399 error.NoRootNode: ('bad-request', None, None), |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
400 } |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
401 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
402 def __init__(self, backend): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
403 PubSubService.__init__(self) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
404 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
405 self.backend = backend |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
406 self.hideNodes = False |
153 | 407 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
408 self.pubSubFeatures = self._getPubSubFeatures() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
409 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
410 self.backend.register_notifier(self._notify) |
174
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
411 self.backend.register_pre_delete(self._pre_delete) |
153 | 412 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
413 def _getPubSubFeatures(self): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
414 features = [ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
415 "config-node", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
416 "create-nodes", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
417 "delete-any", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
418 "delete-nodes", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
419 "item-ids", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
420 "meta-data", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
421 "publish", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
422 "purge-nodes", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
423 "retract-items", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
424 "retrieve-affiliations", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
425 "retrieve-default", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
426 "retrieve-items", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
427 "retrieve-subscriptions", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
428 "subscribe", |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
429 ] |
153 | 430 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
431 if self.backend.supports_instant_nodes(): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
432 features.append("instant-nodes") |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
433 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
434 if self.backend.supports_outcast_affiliation(): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
435 features.append("outcast-affiliation") |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
436 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
437 if self.backend.supports_persistent_items(): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
438 features.append("persistent-items") |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
439 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
440 if self.backend.supports_publisher_affiliation(): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
441 features.append("publisher-affiliation") |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
442 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
443 return features |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
444 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
445 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
|
446 items = data['items'] |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
447 nodeIdentifier = data['node_id'] |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
448 if 'subscriber' not in data: |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
449 d = self.backend.get_notification_list(nodeIdentifier, items) |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
450 else: |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
174
diff
changeset
|
451 d = defer.succeed([(data['subscriber'], items)]) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
452 d.addCallback(lambda notifications: self.notifyPublish(self.serviceJID, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
453 nodeIdentifier, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
454 notifications)) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
455 |
174
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
456 def _pre_delete(self, nodeIdentifier): |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
457 d = self.backend.get_subscribers(nodeIdentifier) |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
458 d.addCallback(lambda subscribers: self.notifyDelete(self.serviceJID, |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
459 nodeIdentifier, |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
460 subscribers)) |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
461 return d |
79d451d186b1
Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
462 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
463 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
|
464 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
|
465 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
466 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
|
467 msg = failure.value.msg |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
468 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
469 if pubsubCondition: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
470 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
|
471 else: |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
472 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
|
473 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
474 raise exc |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
475 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
476 def getNodeInfo(self, requestor, service, nodeIdentifier): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
477 info = {} |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
478 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
479 def saveType(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
480 info['type'] = result |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
481 return nodeIdentifier |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
482 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
483 def saveMetaData(result): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
484 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
|
485 return info |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
486 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
487 d = defer.succeed(nodeIdentifier) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
488 d.addCallback(self.backend.get_node_type) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
489 d.addCallback(saveType) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
490 d.addCallback(self.backend.get_node_meta_data) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
491 d.addCallback(saveMetaData) |
172
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
492 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
|
493 return d |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
494 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
495 def getNodes(self, requestor, service): |
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
|
496 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
|
497 return defer.succeed([]) |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
498 d = self.backend.get_nodes() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
499 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
|
500 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
501 def publish(self, requestor, service, nodeIdentifier, items): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
502 d = self.backend.publish(nodeIdentifier, items, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
503 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
504 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
505 def subscribe(self, requestor, service, nodeIdentifier, subscriber): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
506 d = self.backend.subscribe(nodeIdentifier, subscriber, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
507 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
|
508 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
509 def unsubscribe(self, requestor, service, nodeIdentifier, subscriber): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
510 d = self.backend.unsubscribe(nodeIdentifier, subscriber, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
511 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
512 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
513 def subscriptions(self, requestor, service): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
514 d = self.backend.get_subscriptions(requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
515 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
|
516 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
517 def affiliations(self, requestor, service): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
518 d = self.backend.get_affiliations(requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
519 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
520 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
521 def create(self, requestor, service, nodeIdentifier): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
522 d = self.backend.create_node(nodeIdentifier, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
523 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
|
524 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
525 def getDefaultConfiguration(self, requestor, service): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
526 d = self.backend.get_default_configuration() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
527 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
528 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
529 def getConfiguration(self, requestor, service, nodeIdentifier): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
530 d = self.backend.get_node_configuration(nodeIdentifier) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
531 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
|
532 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
533 def setConfiguration(self, requestor, service, nodeIdentifier, options): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
534 d = self.backend.set_node_configuration(nodeIdentifier, options, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
535 requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
536 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
537 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
538 def items(self, requestor, service, nodeIdentifier, maxItems, itemIdentifiers): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
539 d = self.backend.get_items(nodeIdentifier, requestor, maxItems, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
540 itemIdentifiers) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
541 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
|
542 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
543 def retract(self, requestor, service, nodeIdentifier, itemIdentifiers): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
544 d = self.backend.retract_item(nodeIdentifier, itemIdentifiers, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
545 requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
546 return d.addErrback(self._mapErrors) |
29
d4fc29bb5381
Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents:
24
diff
changeset
|
547 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
548 def purge(self, requestor, service, nodeIdentifier): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
549 d = self.backend.purge_node(nodeIdentifier, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
550 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
|
551 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
552 def delete(self, requestor, service, nodeIdentifier): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
553 d = self.backend.delete_node(nodeIdentifier, requestor) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
554 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
|
555 |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
556 components.registerAdapter(PubSubServiceFromBackend, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
557 IBackendService, |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
159
diff
changeset
|
558 IPubSubService) |