Mercurial > libervia-pubsub
changeset 245:e11e99246be5
allowed groups from item_config are now stored
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 30 May 2012 22:33:10 +0200 (2012-05-30) |
parents | 3ecc94407e36 |
children | 2a948abb77ed |
files | sat_pubsub/pgsql_storage.py |
diffstat | 1 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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)