comparison sat_pubsub/pgsql_storage.py @ 245:e11e99246be5

allowed groups from item_config are now stored
author Goffi <goffi@goffi.org>
date Wed, 30 May 2012 22:33:10 +0200
parents 3ecc94407e36
children 70fae534b83a
comparison
equal deleted inserted replaced
244:3ecc94407e36 245:e11e99246be5
65 65
66 from sat_pubsub import error, iidavoll 66 from sat_pubsub import error, iidavoll
67 67
68 NS_ITEM_CONFIG = "http://jabber.org/protocol/pubsub#item-config" 68 NS_ITEM_CONFIG = "http://jabber.org/protocol/pubsub#item-config"
69 OPT_ACCESS_MODEL = 'pubsub#access_model' 69 OPT_ACCESS_MODEL = 'pubsub#access_model'
70 OPT_ROSTER_GROUPS_ALLOWED = 'pubsub#roster_groups_allowed'
70 VAL_DEFAULT = 'default' 71 VAL_DEFAULT = 'default'
72 VAL_OPEN = 'open'
73 VAL_ROSTER = 'roster'
71 74
72 class Storage: 75 class Storage:
73 76
74 implements(iidavoll.IStorage) 77 implements(iidavoll.IStorage)
75 78
526 item_config = form 529 item_config = form
527 del item.children[i] #we need to remove the config from item 530 del item.children[i] #we need to remove the config from item
528 break 531 break
529 532
530 if item_config: 533 if item_config:
531 access_model = item_config.get("pubsub#access_model", VAL_DEFAULT) 534 access_model = item_config.get(OPT_ACCESS_MODEL, VAL_DEFAULT)
532 535
533 data = item.toXml() 536 data = item.toXml()
534 537
535 cursor.execute("""UPDATE items SET date=now(), publisher=%s, data=%s 538 cursor.execute("""UPDATE items SET date=now(), publisher=%s, data=%s
536 FROM nodes 539 FROM nodes
543 if cursor.rowcount == 1: 546 if cursor.rowcount == 1:
544 return 547 return
545 548
546 cursor.execute("""INSERT INTO items (node_id, item, publisher, data, access_model) 549 cursor.execute("""INSERT INTO items (node_id, item, publisher, data, access_model)
547 SELECT node_id, %s, %s, %s, %s FROM nodes 550 SELECT node_id, %s, %s, %s, %s FROM nodes
548 WHERE node=%s""", 551 WHERE node=%s
552 RETURNING item_id""",
549 (item["id"], 553 (item["id"],
550 publisher.full(), 554 publisher.full(),
551 data, 555 data,
552 access_model, 556 access_model,
553 self.nodeIdentifier)) 557 self.nodeIdentifier))
558
559 if access_model == VAL_ROSTER:
560 item_id = cursor.fetchone()[0];
561 if OPT_ROSTER_GROUPS_ALLOWED in item_config:
562 item_config.fields[OPT_ROSTER_GROUPS_ALLOWED].fieldType='list-multi' #XXX: needed to have a list if there is only one value
563 allowed_groups = item_config[OPT_ROSTER_GROUPS_ALLOWED]
564 else:
565 allowed_groups = []
566 for group in allowed_groups:
567 #TODO: check that group are actually in roster
568 cursor.execute("""INSERT INTO item_groups_authorized (item_id, groupname)
569 VALUES (%s,%s)""" , (item_id, group))
554 570
555 571
556 def removeItems(self, itemIdentifiers): 572 def removeItems(self, itemIdentifiers):
557 return self.dbpool.runInteraction(self._removeItems, itemIdentifiers) 573 return self.dbpool.runInteraction(self._removeItems, itemIdentifiers)
558 574