Mercurial > libervia-backend
comparison sat/plugins/plugin_exp_invitation.py @ 3324:b57b5e42e894
plugins invitation, invitation-file: adapt service JID and affiliation:
if the user part of the service is missing while creating and invitation, it's added
because using only the domain will lead to a different repository depending on the
requester. In addition, the invitee is added to the repostiroy path as a member, to be
sure he/she can access it.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 Aug 2020 16:24:03 +0200 |
parents | 559a625a236b |
children | cc6164a4973b |
comparison
equal
deleted
inserted
replaced
3323:44a9438d6608 | 3324:b57b5e42e894 |
---|---|
33 PLUGIN_INFO = { | 33 PLUGIN_INFO = { |
34 C.PI_NAME: "Invitation", | 34 C.PI_NAME: "Invitation", |
35 C.PI_IMPORT_NAME: "INVITATION", | 35 C.PI_IMPORT_NAME: "INVITATION", |
36 C.PI_TYPE: "EXP", | 36 C.PI_TYPE: "EXP", |
37 C.PI_PROTOCOLS: [], | 37 C.PI_PROTOCOLS: [], |
38 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0329"], | 38 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0106", "XEP-0329"], |
39 C.PI_RECOMMENDATIONS: [], | 39 C.PI_RECOMMENDATIONS: ["EMAIL_INVITATION"], |
40 C.PI_MAIN: "Invitation", | 40 C.PI_MAIN: "Invitation", |
41 C.PI_HANDLER: "yes", | 41 C.PI_HANDLER: "yes", |
42 C.PI_DESCRIPTION: _("Experimental handling of invitations"), | 42 C.PI_DESCRIPTION: _("Experimental handling of invitations"), |
43 } | 43 } |
44 | 44 |
143 pubsub_elt["service"] = service.full() | 143 pubsub_elt["service"] = service.full() |
144 pubsub_elt["node"] = node | 144 pubsub_elt["node"] = node |
145 pubsub_elt["item"] = item_id | 145 pubsub_elt["item"] = item_id |
146 return client.send(mess_data["xml"]) | 146 return client.send(mess_data["xml"]) |
147 | 147 |
148 def sendFileSharingInvitation(self, client, invitee_jid, service, repos_type=None, | 148 async def sendFileSharingInvitation( |
149 namespace=None, path=None, name=None, extra=None): | 149 self, client, invitee_jid, service, repos_type=None, namespace=None, path=None, |
150 name=None, extra=None | |
151 ): | |
150 """Send a file sharing invitation in a <message> stanza | 152 """Send a file sharing invitation in a <message> stanza |
151 | 153 |
152 @param invitee_jid(jid.JID): entitee to send invitation to | 154 @param invitee_jid(jid.JID): entitee to send invitation to |
153 @param service(jid.JID): file sharing service | 155 @param service(jid.JID): file sharing service |
154 @param repos_type(unicode, None): type of files repository, can be: | 156 @param repos_type(unicode, None): type of files repository, can be: |
159 @param name(unicode, None): see [_generateBaseInvitation] | 161 @param name(unicode, None): see [_generateBaseInvitation] |
160 @param extra(dict, None): see [_generateBaseInvitation] | 162 @param extra(dict, None): see [_generateBaseInvitation] |
161 """ | 163 """ |
162 if extra is None: | 164 if extra is None: |
163 extra = {} | 165 extra = {} |
166 # FIXME: Q&D fix as the bare file sharing service JID will lead to user own | |
167 # repository, which thus would not be the same for the host and the guest. | |
168 # By specifying the user part, we for the use of the host repository. | |
169 # A cleaner way should be implemented | |
170 if service.user is None: | |
171 service.user = self.host.plugins['XEP-0106'].escape(client.jid.user) | |
172 | |
173 # FIXME: not the best place to adapt permission, but it's necessary to check them | |
174 # for UX | |
175 try: | |
176 await self.host.plugins['XEP-0329'].affiliationsSet( | |
177 client, service, namespace, path, {invitee_jid: "member"} | |
178 ) | |
179 except Exception as e: | |
180 log.warning(f"Can't set affiliation: {e}") | |
181 | |
164 mess_data, invitation_elt = self._generateBaseInvitation( | 182 mess_data, invitation_elt = self._generateBaseInvitation( |
165 client, invitee_jid, name, extra) | 183 client, invitee_jid, name, extra) |
166 file_sharing_elt = invitation_elt.addElement("file_sharing") | 184 file_sharing_elt = invitation_elt.addElement("file_sharing") |
167 file_sharing_elt["service"] = service.full() | 185 file_sharing_elt["service"] = service.full() |
168 if repos_type is not None: | 186 if repos_type is not None: |
174 file_sharing_elt["type"] = repos_type | 192 file_sharing_elt["type"] = repos_type |
175 if namespace is not None: | 193 if namespace is not None: |
176 file_sharing_elt["namespace"] = namespace | 194 file_sharing_elt["namespace"] = namespace |
177 if path is not None: | 195 if path is not None: |
178 file_sharing_elt["path"] = path | 196 file_sharing_elt["path"] = path |
179 return client.send(mess_data["xml"]) | 197 client.send(mess_data["xml"]) |
180 | 198 |
181 @defer.inlineCallbacks | 199 @defer.inlineCallbacks |
182 def _parsePubsubElt(self, client, pubsub_elt): | 200 def _parsePubsubElt(self, client, pubsub_elt): |
183 try: | 201 try: |
184 service = jid.JID(pubsub_elt["service"]) | 202 service = jid.JID(pubsub_elt["service"]) |