Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_exp_invitation_file.py @ 4309:b56b1eae7994
component email gateway: add multicasting:
XEP-0033 multicasting is now supported both for incoming and outgoing messages. XEP-0033
metadata are converted to suitable Email headers and vice versa.
Email address and JID are both supported, and delivery is done by the gateway when
suitable on incoming messages.
rel 450
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Sep 2024 16:12:01 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3324
b57b5e42e894
plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
3 # SàT plugin to send invitations for file sharing |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
19 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
20 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
21 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
22 from libervia.backend.core.xmpp import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.tools.common import data_format |
3299
83795ff8a633
plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
24 from twisted.internet import defer |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from twisted.words.protocols.jabber import jid |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 log = getLogger(__name__) |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 PLUGIN_INFO = { |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 C.PI_NAME: "File Sharing Invitation", |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 C.PI_IMPORT_NAME: "FILE_SHARING_INVITATION", |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 C.PI_TYPE: "EXP", |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 C.PI_PROTOCOLS: [], |
3028 | 35 C.PI_DEPENDENCIES: ["XEP-0329", "INVITATION"], |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 C.PI_RECOMMENDATIONS: [], |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 C.PI_MAIN: "FileSharingInvitation", |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 C.PI_HANDLER: "no", |
3028 | 39 C.PI_DESCRIPTION: _("Experimental handling of invitations for file sharing"), |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 } |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
3324
b57b5e42e894
plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
43 class FileSharingInvitation: |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 def __init__(self, host): |
3028 | 46 log.info(_("File Sharing Invitation plugin initialization")) |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
48 ns_fis = host.get_namespace("fis") |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
49 host.plugins["INVITATION"].register_namespace(ns_fis, self.on_invitation) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
50 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
51 "fis_invite", |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 ".plugin", |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2917
diff
changeset
|
53 in_sign="ssssssss", |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
55 method=self._send_file_sharing_invitation, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
56 async_=True, |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 ) |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
59 def _send_file_sharing_invitation( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
60 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
61 invitee_jid_s, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
62 service_s, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
63 repos_type=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
64 namespace=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
65 path=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
66 name=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
67 extra_s="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
68 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
69 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
70 client = self.host.get_client(profile_key) |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 invitee_jid = jid.JID(invitee_jid_s) |
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 service = jid.JID(service_s) |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2917
diff
changeset
|
73 extra = data_format.deserialise(extra_s) |
3324
b57b5e42e894
plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
74 return defer.ensureDeferred( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
75 self.host.plugins["INVITATION"].send_file_sharing_invitation( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
76 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
77 invitee_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
78 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
79 repos_type=repos_type or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
80 namespace=namespace or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
81 path=path or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
82 name=name or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
83 extra=extra, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
84 ) |
3324
b57b5e42e894
plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents:
3314
diff
changeset
|
85 ) |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
87 def on_invitation( |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
88 self, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
89 client: SatXMPPEntity, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
90 namespace: str, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
91 name: str, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
92 extra: dict, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
93 service: jid.JID, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
94 repos_type: str, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
95 sharing_ns: str, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
96 path: str, |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
97 ): |
3028 | 98 if repos_type == "files": |
99 type_human = _("file sharing") | |
100 elif repos_type == "photos": | |
3299
83795ff8a633
plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
101 type_human = _("photo album") |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 else: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
103 log.warning( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
104 "Unknown repository type: {repos_type}".format(repos_type=repos_type) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
105 ) |
3028 | 106 repos_type = "file" |
107 type_human = _("file sharing") | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
108 log.info( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
109 _( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
110 "{profile} has received an invitation for a files repository ({type_human}) " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
111 "with namespace {sharing_ns!r} at path [{path}]" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
112 ).format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
113 profile=client.profile, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
114 type_human=type_human, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
115 sharing_ns=sharing_ns, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
116 path=path, |
2917
adf6e33a3e50
plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 ) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
118 ) |
3299
83795ff8a633
plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
119 return defer.ensureDeferred( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
120 self.host.plugins["LIST_INTEREST"].register_file_sharing( |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3324
diff
changeset
|
121 client, service, repos_type, sharing_ns, path, name, extra |
3299
83795ff8a633
plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
122 ) |
83795ff8a633
plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
123 ) |