Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_groupblog.py @ 2807:0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
So far, and for historical reasons, blog items data where serialised using a unicode: unicode dict, which was causing trouble for many types of values (timestamps, booleans, lists).
This patch changes it by serialising the whole items before going to bridge, and deserialising it when going back. This way, complex data can be used easily in items.
This impact psEvent and serItemsData* methods which are renamed transItemsData* because there are not always serialising anymore (a new argument "serialise" allows to specify it).
When editing a blog post in jp, metadata are now more easy to manipulate, specially lists like tags.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 23 Feb 2019 18:59:00 +0100 |
parents | 003b8b4b56a7 |
children | ab2696e34d29 |
comparison
equal
deleted
inserted
replaced
2806:2400cad2dace | 2807:0b7ce5daee9b |
---|---|
24 log = getLogger(__name__) | 24 log = getLogger(__name__) |
25 from twisted.internet import defer | 25 from twisted.internet import defer |
26 from sat.core import exceptions | 26 from sat.core import exceptions |
27 from wokkel import disco, data_form, iwokkel | 27 from wokkel import disco, data_form, iwokkel |
28 from zope.interface import implements | 28 from zope.interface import implements |
29 from sat.tools.common import data_format | |
30 | 29 |
31 try: | 30 try: |
32 from twisted.words.protocols.xmlstream import XMPPHandler | 31 from twisted.words.protocols.xmlstream import XMPPHandler |
33 except ImportError: | 32 except ImportError: |
34 from wokkel.subprotocols import XMPPHandler | 33 from wokkel.subprotocols import XMPPHandler |
105 config_form = data_form.findForm(item_elt, NS_PUBSUB_ITEM_CONFIG) | 104 config_form = data_form.findForm(item_elt, NS_PUBSUB_ITEM_CONFIG) |
106 if config_form is None: | 105 if config_form is None: |
107 return | 106 return |
108 access_model = config_form.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) | 107 access_model = config_form.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) |
109 if access_model == self._p.ACCESS_PUBLISHER_ROSTER: | 108 if access_model == self._p.ACCESS_PUBLISHER_ROSTER: |
110 data_format.iter2dict( | 109 opt = self._p.OPT_ROSTER_GROUPS_ALLOWED |
111 "group", | 110 microblog_data['groups'] = config_form.fields[opt].values |
112 config_form.fields[self._p.OPT_ROSTER_GROUPS_ALLOWED].values, | |
113 microblog_data, | |
114 ) | |
115 | 111 |
116 def _data2entryTrigger(self, client, mb_data, entry_elt, item_elt): | 112 def _data2entryTrigger(self, client, mb_data, entry_elt, item_elt): |
117 """Build fine access permission if needed | 113 """Build fine access permission if needed |
118 | 114 |
119 This trigger check if "group*" key are present, | 115 This trigger check if "group*" key are present, |
120 and create a fine item config to restrict view to these groups | 116 and create a fine item config to restrict view to these groups |
121 """ | 117 """ |
122 groups = list(data_format.dict2iter("group", mb_data)) | 118 groups = mb_data.get('groups', []) |
123 if not groups: | 119 if not groups: |
124 return | 120 return |
125 if not client.server_groupblog_available: | 121 if not client.server_groupblog_available: |
126 raise exceptions.CancelError(u"GroupBlog is not available") | 122 raise exceptions.CancelError(u"GroupBlog is not available") |
127 log.debug(u"This entry use group blog") | 123 log.debug(u"This entry use group blog") |
139 | 135 |
140 It changes the access mode to roster if needed, and give the authorized groups | 136 It changes the access mode to roster if needed, and give the authorized groups |
141 """ | 137 """ |
142 if "group" in mb_data: | 138 if "group" in mb_data: |
143 options[self._p.OPT_ACCESS_MODEL] = self._p.ACCESS_PUBLISHER_ROSTER | 139 options[self._p.OPT_ACCESS_MODEL] = self._p.ACCESS_PUBLISHER_ROSTER |
144 options[self._p.OPT_ROSTER_GROUPS_ALLOWED] = list( | 140 options[self._p.OPT_ROSTER_GROUPS_ALLOWED] = mb_data['groups'] |
145 data_format.dict2iter("group", mb_data) | |
146 ) | |
147 | |
148 | 141 |
149 class GroupBlog_handler(XMPPHandler): | 142 class GroupBlog_handler(XMPPHandler): |
150 implements(iwokkel.IDisco) | 143 implements(iwokkel.IDisco) |
151 | 144 |
152 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): | 145 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |