annotate libervia/web/pages/lists/create_from_tpl/page_meta.py @ 1595:7941444c1671

pages: set `own_local_jid` to avoid confusion with `own_jid`: - `own_jid` is the real JID of the user. - `own_local_jid` is the JID used in chat, which can be real JID, or a room JID.
author Goffi <goffi@goffi.org>
date Wed, 13 Dec 2023 22:05:48 +0100
parents eb00d593801d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
3 from libervia.backend.tools.common import data_format
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
4 from libervia.backend.core.log import getLogger
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
5 from libervia.backend.core.i18n import D_
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
6 from libervia.backend.core import exceptions
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
7 from libervia.web.server.constants import Const as C
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
8 from libervia.frontends.bridge.bridge_frontend import BridgeException
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 log = getLogger(__name__)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 name = "list_create_from_tpl"
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 access = C.PAGES_ACCESS_PROFILE
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 template = "list/create_from_template.html"
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 def parse_url(self, request):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
18 self.get_path_args(request, ["template_id"])
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 async def prepare_render(self, request):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
21 data = self.get_r_data(request)
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 template_id = data["template_id"]
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 if not template_id:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
24 self.page_error(request, C.HTTP_BAD_REQUEST)
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 template_data = request.template_data
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
27 profile = self.get_profile(request)
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
28 tpl_raw = await self.host.bridge_call(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
29 "list_template_get",
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 template_id,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 "",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 profile,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 template = data_format.deserialise(tpl_raw)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 template['id'] = template_id
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 template_data["list_template"] = template
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 async def on_data_post(self, request):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
39 data = self.get_r_data(request)
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 template_id = data['template_id']
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
41 name, access = self.get_posted_data(request, ('name', 'access'))
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 if access == 'private':
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 access_model = 'whitelist'
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 elif access == 'public':
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 access_model = 'open'
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 log.warning(f"Unknown access for template creation: {access}")
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
48 self.page_error(request, C.HTTP_BAD_REQUEST)
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
49 profile = self.get_profile(request)
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 try:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
51 service, node = await self.host.bridge_call(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
52 "list_template_create", template_id, name, access_model, profile
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 except BridgeException as e:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 if e.condition == "conflict":
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 raise exceptions.DataError(D_("A list with this name already exists"))
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 log.error(f"Can't create list from template: {e}")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 raise e
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 data["post_redirect_page"] = (
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1387
diff changeset
61 self.get_page_by_name("lists"),
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 service,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 node or "@",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 )