Mercurial > libervia-pubsub
diff sat_pubsub/pgsql_storage.py @ 250:eb14b8d30cba
fine tuning per-item permissions
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 24 Jun 2012 19:35:49 +0200 |
parents | aaf5e34ff765 |
children | 25a1dc7181cc |
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py Fri Jun 08 18:34:45 2012 +0200 +++ b/sat_pubsub/pgsql_storage.py Sun Jun 24 19:35:49 2012 +0200 @@ -61,16 +61,8 @@ from wokkel.generic import parseXml, stripNamespace from wokkel.pubsub import Subscription -from wokkel import data_form -from sat_pubsub import error, iidavoll - -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_OPEN = 'open' -VAL_ROSTER = 'roster' -VAL_DEFAULT = VAL_OPEN +from sat_pubsub import error, iidavoll, const class Storage: @@ -507,32 +499,18 @@ nodeType = 'leaf' - def storeItems(self, items, publisher): - return self.dbpool.runInteraction(self._storeItems, items, publisher) - - - def _storeItems(self, cursor, items, publisher): - self._checkNodeExists(cursor) - for item in items: - self._storeItem(cursor, item, publisher) + def storeItems(self, item_data, publisher): + return self.dbpool.runInteraction(self._storeItems, item_data, publisher) - def _storeItem(self, cursor, item, publisher): - item_config = None - access_model = VAL_DEFAULT - for i in range(len(item.children)): - elt = item.children[i] - if not (elt.uri,elt.name)==(data_form.NS_X_DATA,'x'): - continue - form = data_form.Form.fromElement(elt) - if (form.formNamespace == NS_ITEM_CONFIG): - item_config = form - del item.children[i] #we need to remove the config from item - break + def _storeItems(self, cursor, item_data, publisher): + self._checkNodeExists(cursor) + for item_datum in item_data: + self._storeItem(cursor, item_datum, publisher) - if item_config: - access_model = item_config.get(OPT_ACCESS_MODEL, VAL_DEFAULT) - + + def _storeItem(self, cursor, item_datum, publisher): + access_model, item_config, item = item_datum data = item.toXml() cursor.execute("""UPDATE items SET date=now(), publisher=%s, data=%s @@ -556,11 +534,11 @@ access_model, self.nodeIdentifier)) - if access_model == VAL_ROSTER: + if access_model == const.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] + if const.OPT_ROSTER_GROUPS_ALLOWED in item_config: + item_config.fields[const.OPT_ROSTER_GROUPS_ALLOWED].fieldType='list-multi' #XXX: needed to force list if there is only one value + allowed_groups = item_config[const.OPT_ROSTER_GROUPS_ALLOWED] else: allowed_groups = [] for group in allowed_groups: