Mercurial > libervia-backend
changeset 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 | 44a9438d6608 |
children | 7ebda4b54170 |
files | sat/plugins/plugin_exp_invitation.py sat/plugins/plugin_exp_invitation_file.py |
diffstat | 2 files changed, 32 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_invitation.py Sat Aug 01 16:19:50 2020 +0200 +++ b/sat/plugins/plugin_exp_invitation.py Sat Aug 01 16:24:03 2020 +0200 @@ -35,8 +35,8 @@ C.PI_IMPORT_NAME: "INVITATION", C.PI_TYPE: "EXP", C.PI_PROTOCOLS: [], - C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0329"], - C.PI_RECOMMENDATIONS: [], + C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0106", "XEP-0329"], + C.PI_RECOMMENDATIONS: ["EMAIL_INVITATION"], C.PI_MAIN: "Invitation", C.PI_HANDLER: "yes", C.PI_DESCRIPTION: _("Experimental handling of invitations"), @@ -145,8 +145,10 @@ pubsub_elt["item"] = item_id return client.send(mess_data["xml"]) - def sendFileSharingInvitation(self, client, invitee_jid, service, repos_type=None, - namespace=None, path=None, name=None, extra=None): + async def sendFileSharingInvitation( + self, client, invitee_jid, service, repos_type=None, namespace=None, path=None, + name=None, extra=None + ): """Send a file sharing invitation in a <message> stanza @param invitee_jid(jid.JID): entitee to send invitation to @@ -161,6 +163,22 @@ """ if extra is None: extra = {} + # FIXME: Q&D fix as the bare file sharing service JID will lead to user own + # repository, which thus would not be the same for the host and the guest. + # By specifying the user part, we for the use of the host repository. + # A cleaner way should be implemented + if service.user is None: + service.user = self.host.plugins['XEP-0106'].escape(client.jid.user) + + # FIXME: not the best place to adapt permission, but it's necessary to check them + # for UX + try: + await self.host.plugins['XEP-0329'].affiliationsSet( + client, service, namespace, path, {invitee_jid: "member"} + ) + except Exception as e: + log.warning(f"Can't set affiliation: {e}") + mess_data, invitation_elt = self._generateBaseInvitation( client, invitee_jid, name, extra) file_sharing_elt = invitation_elt.addElement("file_sharing") @@ -176,7 +194,7 @@ file_sharing_elt["namespace"] = namespace if path is not None: file_sharing_elt["path"] = path - return client.send(mess_data["xml"]) + client.send(mess_data["xml"]) @defer.inlineCallbacks def _parsePubsubElt(self, client, pubsub_elt):
--- a/sat/plugins/plugin_exp_invitation_file.py Sat Aug 01 16:19:50 2020 +0200 +++ b/sat/plugins/plugin_exp_invitation_file.py Sat Aug 01 16:24:03 2020 +0200 @@ -1,7 +1,6 @@ #!/usr/bin/env python3 - -# SAT plugin to detect language (experimental) +# SàT plugin to send invitations for file sharing # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) # This program is free software: you can redistribute it and/or modify @@ -40,7 +39,7 @@ } -class FileSharingInvitation(object): +class FileSharingInvitation: def __init__(self, host): log.info(_("File Sharing Invitation plugin initialization")) @@ -53,6 +52,7 @@ in_sign="ssssssss", out_sign="", method=self._sendFileSharingInvitation, + async_=True ) def _sendFileSharingInvitation( @@ -62,10 +62,12 @@ invitee_jid = jid.JID(invitee_jid_s) service = jid.JID(service_s) extra = data_format.deserialise(extra_s) - return self.host.plugins["INVITATION"].sendFileSharingInvitation( - client, invitee_jid, service, repos_type=repos_type or None, - namespace=namespace or None, path=path or None, name=name or None, - extra=extra) + return defer.ensureDeferred( + self.host.plugins["INVITATION"].sendFileSharingInvitation( + client, invitee_jid, service, repos_type=repos_type or None, + namespace=namespace or None, path=path or None, name=name or None, + extra=extra) + ) def onInvitation(self, client, name, extra, service, repos_type, namespace, path): if repos_type == "files":