Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_groupblog.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 003b8b4b56a7 |
comparison
equal
deleted
inserted
replaced
2623:49533de4540b | 2624:56f94936df1e |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 | |
23 log = getLogger(__name__) | 24 log = getLogger(__name__) |
24 from twisted.internet import defer | 25 from twisted.internet import defer |
25 from sat.core import exceptions | 26 from sat.core import exceptions |
26 from wokkel import disco, data_form, iwokkel | 27 from wokkel import disco, data_form, iwokkel |
27 from zope.interface import implements | 28 from zope.interface import implements |
30 try: | 31 try: |
31 from twisted.words.protocols.xmlstream import XMPPHandler | 32 from twisted.words.protocols.xmlstream import XMPPHandler |
32 except ImportError: | 33 except ImportError: |
33 from wokkel.subprotocols import XMPPHandler | 34 from wokkel.subprotocols import XMPPHandler |
34 | 35 |
35 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' | 36 NS_PUBSUB = "http://jabber.org/protocol/pubsub" |
36 NS_GROUPBLOG = 'http://salut-a-toi.org/protocol/groupblog' | 37 NS_GROUPBLOG = "http://salut-a-toi.org/protocol/groupblog" |
37 #NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features | 38 # NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features |
38 NS_PUBSUB_EXP = NS_PUBSUB # XXX: we can't use custom namespace as Wokkel's PubSubService use official NS | 39 NS_PUBSUB_EXP = ( |
40 NS_PUBSUB | |
41 ) # XXX: we can't use custom namespace as Wokkel's PubSubService use official NS | |
39 NS_PUBSUB_GROUPBLOG = NS_PUBSUB_EXP + "#groupblog" | 42 NS_PUBSUB_GROUPBLOG = NS_PUBSUB_EXP + "#groupblog" |
40 NS_PUBSUB_ITEM_CONFIG = NS_PUBSUB_EXP + "#item-config" | 43 NS_PUBSUB_ITEM_CONFIG = NS_PUBSUB_EXP + "#item-config" |
41 | 44 |
42 | 45 |
43 PLUGIN_INFO = { | 46 PLUGIN_INFO = { |
46 C.PI_TYPE: "MISC", | 49 C.PI_TYPE: "MISC", |
47 C.PI_PROTOCOLS: [], | 50 C.PI_PROTOCOLS: [], |
48 C.PI_DEPENDENCIES: ["XEP-0277"], | 51 C.PI_DEPENDENCIES: ["XEP-0277"], |
49 C.PI_MAIN: "GroupBlog", | 52 C.PI_MAIN: "GroupBlog", |
50 C.PI_HANDLER: "yes", | 53 C.PI_HANDLER: "yes", |
51 C.PI_DESCRIPTION: _("""Implementation of microblogging fine permissions""") | 54 C.PI_DESCRIPTION: _("""Implementation of microblogging fine permissions"""), |
52 } | 55 } |
53 | 56 |
54 | 57 |
55 class GroupBlog(object): | 58 class GroupBlog(object): |
56 """This class use a SàT PubSub Service to manage access on microblog""" | 59 """This class use a SàT PubSub Service to manage access on microblog""" |
72 def profileConnected(self, client): | 75 def profileConnected(self, client): |
73 try: | 76 try: |
74 yield self.host.checkFeatures(client, (NS_PUBSUB_GROUPBLOG,)) | 77 yield self.host.checkFeatures(client, (NS_PUBSUB_GROUPBLOG,)) |
75 except exceptions.FeatureNotFound: | 78 except exceptions.FeatureNotFound: |
76 client.server_groupblog_available = False | 79 client.server_groupblog_available = False |
77 log.warning(_(u"Server is not able to manage item-access pubsub, we can't use group blog")) | 80 log.warning( |
81 _( | |
82 u"Server is not able to manage item-access pubsub, we can't use group blog" | |
83 ) | |
84 ) | |
78 else: | 85 else: |
79 client.server_groupblog_available = True | 86 client.server_groupblog_available = True |
80 log.info(_(u"Server can manage group blogs")) | 87 log.info(_(u"Server can manage group blogs")) |
81 | 88 |
82 def getFeatures(self, profile): | 89 def getFeatures(self, profile): |
83 try: | 90 try: |
84 client = self.host.getClient(profile) | 91 client = self.host.getClient(profile) |
85 except exceptions.ProfileNotSetError: | 92 except exceptions.ProfileNotSetError: |
86 return {} | 93 return {} |
87 try: | 94 try: |
88 return {'available': C.boolConst(client.server_groupblog_available)} | 95 return {"available": C.boolConst(client.server_groupblog_available)} |
89 except AttributeError: | 96 except AttributeError: |
90 if self.host.isConnected(profile): | 97 if self.host.isConnected(profile): |
91 log.debug("Profile is not connected, service is not checked yet") | 98 log.debug("Profile is not connected, service is not checked yet") |
92 else: | 99 else: |
93 log.error("client.server_groupblog_available should be available !") | 100 log.error("client.server_groupblog_available should be available !") |
98 config_form = data_form.findForm(item_elt, NS_PUBSUB_ITEM_CONFIG) | 105 config_form = data_form.findForm(item_elt, NS_PUBSUB_ITEM_CONFIG) |
99 if config_form is None: | 106 if config_form is None: |
100 return | 107 return |
101 access_model = config_form.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) | 108 access_model = config_form.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) |
102 if access_model == self._p.ACCESS_PUBLISHER_ROSTER: | 109 if access_model == self._p.ACCESS_PUBLISHER_ROSTER: |
103 data_format.iter2dict('group', config_form.fields[self._p.OPT_ROSTER_GROUPS_ALLOWED].values, microblog_data) | 110 data_format.iter2dict( |
111 "group", | |
112 config_form.fields[self._p.OPT_ROSTER_GROUPS_ALLOWED].values, | |
113 microblog_data, | |
114 ) | |
104 | 115 |
105 def _data2entryTrigger(self, client, mb_data, entry_elt, item_elt): | 116 def _data2entryTrigger(self, client, mb_data, entry_elt, item_elt): |
106 """Build fine access permission if needed | 117 """Build fine access permission if needed |
107 | 118 |
108 This trigger check if "group*" key are present, | 119 This trigger check if "group*" key are present, |
109 and create a fine item config to restrict view to these groups | 120 and create a fine item config to restrict view to these groups |
110 """ | 121 """ |
111 groups = list(data_format.dict2iter('group', mb_data)) | 122 groups = list(data_format.dict2iter("group", mb_data)) |
112 if not groups: | 123 if not groups: |
113 return | 124 return |
114 if not client.server_groupblog_available: | 125 if not client.server_groupblog_available: |
115 raise exceptions.CancelError(u"GroupBlog is not available") | 126 raise exceptions.CancelError(u"GroupBlog is not available") |
116 log.debug(u"This entry use group blog") | 127 log.debug(u"This entry use group blog") |
117 form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG) | 128 form = data_form.Form("submit", formNamespace=NS_PUBSUB_ITEM_CONFIG) |
118 access = data_form.Field(None, self._p.OPT_ACCESS_MODEL, value=self._p.ACCESS_PUBLISHER_ROSTER) | 129 access = data_form.Field( |
130 None, self._p.OPT_ACCESS_MODEL, value=self._p.ACCESS_PUBLISHER_ROSTER | |
131 ) | |
119 allowed = data_form.Field(None, self._p.OPT_ROSTER_GROUPS_ALLOWED, values=groups) | 132 allowed = data_form.Field(None, self._p.OPT_ROSTER_GROUPS_ALLOWED, values=groups) |
120 form.addField(access) | 133 form.addField(access) |
121 form.addField(allowed) | 134 form.addField(allowed) |
122 item_elt.addChild(form.toElement()) | 135 item_elt.addChild(form.toElement()) |
123 | 136 |
126 | 139 |
127 It changes the access mode to roster if needed, and give the authorized groups | 140 It changes the access mode to roster if needed, and give the authorized groups |
128 """ | 141 """ |
129 if "group" in mb_data: | 142 if "group" in mb_data: |
130 options[self._p.OPT_ACCESS_MODEL] = self._p.ACCESS_PUBLISHER_ROSTER | 143 options[self._p.OPT_ACCESS_MODEL] = self._p.ACCESS_PUBLISHER_ROSTER |
131 options[self._p.OPT_ROSTER_GROUPS_ALLOWED] = list(data_format.dict2iter('group', mb_data)) | 144 options[self._p.OPT_ROSTER_GROUPS_ALLOWED] = list( |
145 data_format.dict2iter("group", mb_data) | |
146 ) | |
132 | 147 |
133 | 148 |
134 class GroupBlog_handler(XMPPHandler): | 149 class GroupBlog_handler(XMPPHandler): |
135 implements(iwokkel.IDisco) | 150 implements(iwokkel.IDisco) |
136 | 151 |
137 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): | 152 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
138 return [disco.DiscoFeature(NS_GROUPBLOG)] | 153 return [disco.DiscoFeature(NS_GROUPBLOG)] |
139 | 154 |
140 def getDiscoItems(self, requestor, target, nodeIdentifier=''): | 155 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
141 return [] | 156 return [] |