# HG changeset patch # User Goffi # Date 1338409990 -7200 # Node ID e11e99246be5157b8f253ada994d12c797710229 # Parent 3ecc94407e36601cd46ace12bef45e973e068912 allowed groups from item_config are now stored diff -r 3ecc94407e36 -r e11e99246be5 sat_pubsub/pgsql_storage.py --- a/sat_pubsub/pgsql_storage.py Wed May 30 01:04:15 2012 +0200 +++ b/sat_pubsub/pgsql_storage.py Wed May 30 22:33:10 2012 +0200 @@ -67,7 +67,10 @@ NS_ITEM_CONFIG = "http://jabber.org/protocol/pubsub#item-config" OPT_ACCESS_MODEL = 'pubsub#access_model' +OPT_ROSTER_GROUPS_ALLOWED = 'pubsub#roster_groups_allowed' VAL_DEFAULT = 'default' +VAL_OPEN = 'open' +VAL_ROSTER = 'roster' class Storage: @@ -528,7 +531,7 @@ break if item_config: - access_model = item_config.get("pubsub#access_model", VAL_DEFAULT) + access_model = item_config.get(OPT_ACCESS_MODEL, VAL_DEFAULT) data = item.toXml() @@ -545,13 +548,26 @@ cursor.execute("""INSERT INTO items (node_id, item, publisher, data, access_model) SELECT node_id, %s, %s, %s, %s FROM nodes - WHERE node=%s""", + WHERE node=%s + RETURNING item_id""", (item["id"], publisher.full(), data, access_model, self.nodeIdentifier)) + if access_model == VAL_ROSTER: + item_id = cursor.fetchone()[0]; + if OPT_ROSTER_GROUPS_ALLOWED in item_config: + item_config.fields[OPT_ROSTER_GROUPS_ALLOWED].fieldType='list-multi' #XXX: needed to have a list if there is only one value + allowed_groups = item_config[OPT_ROSTER_GROUPS_ALLOWED] + else: + allowed_groups = [] + for group in allowed_groups: + #TODO: check that group are actually in roster + cursor.execute("""INSERT INTO item_groups_authorized (item_id, groupname) + VALUES (%s,%s)""" , (item_id, group)) + def removeItems(self, itemIdentifiers): return self.dbpool.runInteraction(self._removeItems, itemIdentifiers)