comparison sat_pubsub/backend.py @ 260:f0cd02c032b3

publish model management
author Goffi <goffi@goffi.org>
date Mon, 06 May 2013 00:26:37 +0200
parents 6fe7da6b4b32
children 65d4fed44edf
comparison
equal deleted inserted replaced
259:6fe7da6b4b32 260:f0cd02c032b3
127 }, 127 },
128 const.OPT_ROSTER_GROUPS_ALLOWED: 128 const.OPT_ROSTER_GROUPS_ALLOWED:
129 {"type": "list-multi", 129 {"type": "list-multi",
130 "label": "Groups of the roster allowed to access the node", 130 "label": "Groups of the roster allowed to access the node",
131 }, 131 },
132 const.OPT_PUBLISH_MODEL:
133 {"type": "list-single",
134 "label": "Who can publish to this node",
135 "options": {
136 const.VAL_PMODEL_OPEN: "Everybody can publish",
137 const.VAL_PMODEL_PUBLISHERS: "Only owner and publishers can publish",
138 const.VAL_PMODEL_SUBSCRIBERS: "Everybody which subscribed to the node",
139 }
140 },
132 } 141 }
133 142
134 subscriptionOptions = { 143 subscriptionOptions = {
135 "pubsub#subscription_type": 144 "pubsub#subscription_type":
136 {"type": "list-single", 145 {"type": "list-single",
166 175
167 def supportsPersistentItems(self): 176 def supportsPersistentItems(self):
168 return True 177 return True
169 178
170 179
180 def supportsPublishModel(self):
181 return True
182
183
171 def getNodeType(self, nodeIdentifier): 184 def getNodeType(self, nodeIdentifier):
172 d = self.storage.getNode(nodeIdentifier) 185 d = self.storage.getNode(nodeIdentifier)
173 d.addCallback(lambda node: node.getType()) 186 d.addCallback(lambda node: node.getType())
174 return d 187 return d
175 188
196 209
197 return options 210 return options
198 211
199 212
200 def _checkAuth(self, node, requestor): 213 def _checkAuth(self, node, requestor):
201 def check(affiliation, node): 214 """ Check authorisation of publishing in node for requestor """
202 if affiliation not in ['owner', 'publisher']: 215
203 raise error.Forbidden() 216 def check(affiliation):
204 return node 217 d = defer.succeed(node)
218 configuration = node.getConfiguration()
219 publish_model = configuration[const.OPT_PUBLISH_MODEL]
220
221 if (publish_model == const.VAL_PMODEL_PUBLISHERS):
222 if affiliation not in ['owner', 'publisher']:
223 raise error.Forbidden()
224 elif (publish_model == const.VAL_PMODEL_SUBSCRIBERS):
225 if affiliation not in ['owner', 'publisher']:
226 # we are in subscribers publish model, we must check that
227 # the requestor is a subscriber to allow him to publish
228
229 def checkSubscription(subscribed):
230 if not subscribed:
231 raise error.Forbidden()
232 return node
233
234 d.addCallback(lambda ignore: node.isSubscribed(requestor))
235 d.addCallback(checkSubscription)
236 elif publish_model != const.VAL_PMODEL_OPEN:
237 raise Exception('Unexpected value') # publish_model must be publishers (default), subscribers or open.
238
239 return d
205 240
206 d = node.getAffiliation(requestor) 241 d = node.getAffiliation(requestor)
207 d.addCallback(check, node) 242 d.addCallback(check)
208 return d 243 return d
209 244
210 def parseItemConfig(self, item): 245 def parseItemConfig(self, item):
211 """Get and remove item configuration information 246 """Get and remove item configuration information
212 @param item: 247 @param item:
745 self.features.append("publisher-affiliation") 780 self.features.append("publisher-affiliation")
746 781
747 if self.backend.supportsGroupBlog(): 782 if self.backend.supportsGroupBlog():
748 self.features.append("groupblog") 783 self.features.append("groupblog")
749 784
785 # if self.backend.supportsPublishModel(): #XXX: this feature is not really described in XEP-0060, we just can see it in examples
786 # self.features.append("publish_model") # but it's necessary for microblogging comments (see XEP-0277)
787
750 def _notify(self, data): 788 def _notify(self, data):
751 items = data['items'] 789 items = data['items']
752 node = data['node'] 790 node = data['node']
753 791
754 def _notifyAllowed(result): 792 def _notifyAllowed(result):