comparison libervia/web/pages/merge-requests/view/page_meta.py @ 1518:eb00d593801d

refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 16:49:28 +0200
parents libervia/pages/merge-requests/view/page_meta.py@106bae41f5c8
children
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3
4 from libervia.web.server.constants import Const as C
5 from libervia.backend.core.i18n import _
6 from libervia.web.server.utils import SubPage
7 from libervia.web.server import session_iface
8 from twisted.words.protocols.jabber import jid
9 from libervia.backend.tools.common import template_xmlui
10 from libervia.backend.tools.common import uri
11 from libervia.backend.tools.common import data_format
12 from libervia.backend.core.log import getLogger
13
14 name = "merge-requests_view"
15 access = C.PAGES_ACCESS_PUBLIC
16 template = "merge-request/item.html"
17 log = getLogger(__name__)
18
19
20 def parse_url(self, request):
21 try:
22 item_id = self.next_path(request)
23 except IndexError:
24 log.warning(_("no list item id specified"))
25 self.page_error(request, C.HTTP_BAD_REQUEST)
26
27 data = self.get_r_data(request)
28 data["list_item_id"] = item_id
29
30
31 async def prepare_render(self, request):
32 data = self.get_r_data(request)
33 template_data = request.template_data
34 session = self.host.get_session_data(request, session_iface.IWebSession)
35 service, node, list_item_id = (
36 data.get("service", ""),
37 data.get("node", ""),
38 data["list_item_id"],
39 )
40 profile = self.get_profile(request)
41
42 if profile is None:
43 profile = C.SERVICE_PROFILE
44
45 merge_requests = data_format.deserialise(
46 await self.host.bridge_call(
47 "merge_requests_get",
48 service.full() if service else "",
49 node,
50 C.NO_LIMIT,
51 [list_item_id],
52 "",
53 data_format.serialise({"parse": C.BOOL_TRUE, "labels_as_list": C.BOOL_TRUE}),
54 profile,
55 )
56 )
57 list_item = template_xmlui.create(
58 self.host, merge_requests['items'][0], ignore=["request_data", "type"]
59 )
60 template_data["item"] = list_item
61 template_data["patches"] = merge_requests['items_patches'][0]
62 comments_uri = list_item.widgets["comments_uri"].value
63 if comments_uri:
64 uri_data = uri.parse_xmpp_uri(comments_uri)
65 template_data["comments_node"] = comments_node = uri_data["node"]
66 template_data["comments_service"] = comments_service = uri_data["path"]
67 template_data["comments"] = data_format.deserialise(await self.host.bridge_call(
68 "mb_get", comments_service, comments_node, C.NO_LIMIT, [],
69 data_format.serialise({}), profile
70 ))
71
72 template_data["login_url"] = self.get_page_redirect_url(request)
73
74 if session.connected:
75 # we set edition URL only if user is the publisher or the node owner
76 publisher = jid.JID(list_item.widgets["publisher"].value)
77 is_publisher = publisher.userhostJID() == session.jid.userhostJID()
78 affiliation = None
79 if not is_publisher:
80 node = node or self.host.ns_map["merge_requests"]
81 affiliation = await self.host.get_affiliation(request, service, node)
82 if is_publisher or affiliation == "owner":
83 template_data["url_list_item_edit"] = self.get_url_by_path(
84 SubPage("merge-requests"),
85 service.full(),
86 node or "@",
87 SubPage("merge-requests_edit"),
88 list_item_id,
89 )
90
91
92 async def on_data_post(self, request):
93 type_ = self.get_posted_data(request, "type")
94 if type_ == "comment":
95 blog_page = self.get_page_by_name("blog_view")
96 await blog_page.on_data_post(self, request)
97 else:
98 log.warning(_("Unhandled data type: {}").format(type_))