comparison src/plugins/plugin_misc_groupblog.py @ 706:80e9d3ecb272

plugin XEP-0277, group blog: rich text management for sending microblogs
author Goffi <goffi@goffi.org>
date Thu, 14 Nov 2013 18:35:51 +0100
parents 3c304929af74
children 890fbf2d7fdd
comparison
equal deleted inserted replaced
705:6c8a119dcc94 706:80e9d3ecb272
248 @param access_type: one of "PUBLIC", "GROUP", "JID" 248 @param access_type: one of "PUBLIC", "GROUP", "JID"
249 @param access_list: set of entities (empty list for all, groups or jids) allowed to see the item 249 @param access_list: set of entities (empty list for all, groups or jids) allowed to see the item
250 @param message: message to publish 250 @param message: message to publish
251 @param extra: dict which option name as key, which can be: 251 @param extra: dict which option name as key, which can be:
252 - allow_comments: True to accept comments, False else (default: False) 252 - allow_comments: True to accept comments, False else (default: False)
253 - rich: if present, contain rich text in currently selected syntax
253 """ 254 """
254 node_name = self.getNodeName(client.jid) 255 node_name = self.getNodeName(client.jid)
255 mblog_data = {'content': message} 256 mblog_data = {'content': message}
257 if 'rich' in extra:
258 mblog_data['rich'] = extra['rich']
256 P = self.host.plugins["XEP-0060"] 259 P = self.host.plugins["XEP-0060"]
257 access_model_value = ACCESS_TYPE_MAP[access_type] 260 access_model_value = ACCESS_TYPE_MAP[access_type]
258 261
259 if extra.get('allow_comments', 'False').lower() == 'true': 262 if extra.get('allow_comments', 'False').lower() == 'true':
260 comments_node = "%s_%s__%s" % (NS_COMMENT_PREFIX, str(uuid.uuid4()), node_name) 263 comments_node = "%s_%s__%s" % (NS_COMMENT_PREFIX, str(uuid.uuid4()), node_name)
273 # FIXME: check comments node creation success, at the moment this is a potential security risk (if the node 276 # FIXME: check comments node creation success, at the moment this is a potential security risk (if the node
274 # already exists, the creation will silently fail, but the comments link will stay the same, linking to a 277 # already exists, the creation will silently fail, but the comments link will stay the same, linking to a
275 # node owned by somebody else) 278 # node owned by somebody else)
276 defer_blog = self.host.plugins["XEP-0060"].createNode(service, comments_node, _options, profile_key=client.profile) 279 defer_blog = self.host.plugins["XEP-0060"].createNode(service, comments_node, _options, profile_key=client.profile)
277 280
278 mblog_item = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile) 281 def itemCreated(mblog_item):
279 form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG) 282 form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG)
280 283
281 if access_type == "PUBLIC": 284 if access_type == "PUBLIC":
282 if access_list: 285 if access_list:
283 raise BadAccessListError("access_list must be empty for PUBLIC access") 286 raise BadAccessListError("access_list must be empty for PUBLIC access")
284 access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value) 287 access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value)
285 form.addField(access) 288 form.addField(access)
286 elif access_type == "GROUP": 289 elif access_type == "GROUP":
287 access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value) 290 access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value)
288 allowed = data_form.Field(None, P.OPT_ROSTER_GROUPS_ALLOWED, values=access_list) 291 allowed = data_form.Field(None, P.OPT_ROSTER_GROUPS_ALLOWED, values=access_list)
289 form.addField(access) 292 form.addField(access)
290 form.addField(allowed) 293 form.addField(allowed)
291 mblog_item.addChild(form.toElement()) 294 mblog_item.addChild(form.toElement())
292 elif access_type == "JID": 295 elif access_type == "JID":
293 raise NotImplementedError 296 raise NotImplementedError
294 else: 297 else:
295 error(_("Unknown access_type")) 298 error(_("Unknown access_type"))
296 raise BadAccessTypeError 299 raise BadAccessTypeError
297 300
298 defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile) 301 defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile)
299 defer_blog.addErrback(self._mblogPublicationFailed) 302 defer_blog.addErrback(self._mblogPublicationFailed)
300 return defer_blog 303 return defer_blog
304
305 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile)
306 entry_d.addCallback(itemCreated)
307 return entry_d
301 308
302 def _mblogPublicationFailed(self, failure): 309 def _mblogPublicationFailed(self, failure):
303 #TODO 310 #TODO
304 return failure 311 return failure
305 312
309 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS, 316 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS,
310 list of groups or list of jids) for this item 317 list of groups or list of jids) for this item
311 @param message: microblog 318 @param message: microblog
312 @param extra: dict which option name as key, which can be: 319 @param extra: dict which option name as key, which can be:
313 - allow_comments: True to accept comments, False else (default: False) 320 - allow_comments: True to accept comments, False else (default: False)
321 - rich: if present, contain rich text in currently selected syntax
314 @profile_key: %(doc_profile)s 322 @profile_key: %(doc_profile)s
315 """ 323 """
316 324
317 def initialised(result): 325 def initialised(result):
318 profile, client = result 326 profile, client = result
345 raise Exception("Unknown profile") 353 raise Exception("Unknown profile")
346 354
347 service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url) 355 service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url)
348 356
349 mblog_data = {'content': message} 357 mblog_data = {'content': message}
350 mblog_item = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile) 358 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)
351 359 entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile))
352 return self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile) 360 return entry_d
353 361
354 def _itemsConstruction(self, items, pub_jid, client): 362 def _itemsConstruction(self, items, pub_jid, client):
355 """ Transforms items to group blog data and manage comments node 363 """ Transforms items to group blog data and manage comments node
356 @param items: iterable of items 364 @param items: iterable of items
357 @param pub_jid: jid of the publisher or None to use items data 365 @param pub_jid: jid of the publisher or None to use items data