annotate libervia/pages/merge-requests/view/page_meta.py @ 1302:04e7dd6b6f4d

pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
author Goffi <goffi@goffi.org>
date Thu, 16 Jul 2020 09:08:47 +0200
parents f511f8fbbf8a
children e3e303a30a74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
2
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
3
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.i18n import _
1095
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
6 from libervia.server.utils import SubPage
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
7 from libervia.server import session_iface
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from twisted.internet import defer
1095
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
9 from twisted.words.protocols.jabber import jid
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
10 from sat.tools.common import template_xmlui
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
11 from sat.tools.common import uri
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
12 from sat.tools.common import data_format
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
13 from sat.core.log import getLogger
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
14
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
15 name = "merge-requests_view"
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
16 access = C.PAGES_ACCESS_PUBLIC
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
17 template = "merge-request/item.html"
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
18 log = getLogger(__name__)
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
19
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
20
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
21 def parse_url(self, request):
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
22 try:
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
23 item_id = self.nextPath(request)
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
24 except IndexError:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
25 log.warning(_("no ticket id specified"))
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
26 self.pageError(request, C.HTTP_BAD_REQUEST)
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
27
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
28 data = self.getRData(request)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
29 data["ticket_id"] = item_id
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
30
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
31
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
32 async def prepare_render(self, request):
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
33 data = self.getRData(request)
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
34 template_data = request.template_data
1095
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
35 session = self.host.getSessionData(request, session_iface.ISATSession)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
36 service, node, ticket_id = (
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
37 data.get("service", ""),
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
38 data.get("node", ""),
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
39 data["ticket_id"],
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
40 )
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
41 profile = self.getProfile(request)
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
42
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
43 if profile is None:
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
44 profile = C.SERVICE_PROFILE
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
45
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
46 merge_requests = data_format.deserialise(
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
47 await self.host.bridgeCall(
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
48 "mergeRequestsGet",
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
49 service.full() if service else "",
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
50 node,
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
51 C.NO_LIMIT,
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
52 [ticket_id],
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
53 "",
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
54 {"parse": C.BOOL_TRUE, "labels_as_list": C.BOOL_TRUE},
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
55 profile,
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
56 )
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
57 )
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
58 ticket = template_xmlui.create(
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
59 self.host, merge_requests['items'][0], ignore=["request_data", "type"]
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
60 )
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
61 template_data["item"] = ticket
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
62 template_data["patches"] = merge_requests['items_patches'][0]
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
63 comments_uri = ticket.widgets["comments_uri"].value
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
64 if comments_uri:
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
65 uri_data = uri.parseXMPPUri(comments_uri)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
66 template_data["comments_node"] = comments_node = uri_data["node"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
67 template_data["comments_service"] = comments_service = uri_data["path"]
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
68 template_data["comments"] = data_format.deserialise(await self.host.bridgeCall(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
69 "mbGet", comments_service, comments_node, C.NO_LIMIT, [], {}, profile
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
70 ))
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
71
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
72 template_data["login_url"] = self.getPageRedirectURL(request)
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
73
1095
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
74 if session.connected:
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
75 # we set edition URL only if user is the publisher or the node owner
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
76 publisher = jid.JID(ticket.widgets["publisher"].value)
1095
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
77 is_publisher = publisher.userhostJID() == session.jid.userhostJID()
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
78 affiliation = None
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
79 if not is_publisher:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
80 node = node or self.host.ns_map["merge_requests"]
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
81 affiliation = await self.host.getAffiliation(request, service, node)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
82 if is_publisher or affiliation == "owner":
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
83 template_data["url_ticket_edit"] = self.getURLByPath(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
84 SubPage("merge-requests"),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
85 service.full(),
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
86 node or "@",
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
87 SubPage("merge-requests_edit"),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
88 ticket_id,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
89 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
90
1095
7d5633ccbaf2 merge-requests (view), tickets (view): fill "url_ticket_edit" when logged user is publisher of ticket, or node owner.
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
91
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
92 async def on_data_post(self, request):
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
93 type_ = self.getPostedData(request, "type")
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
94 if type_ == "comment":
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
95 blog_page = self.getPageByName("blog_view")
1302
04e7dd6b6f4d pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
96 await blog_page.on_data_post(self, request)
991
6ce9647011b3 pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff changeset
97 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
98 log.warning(_("Unhandled data type: {}").format(type_))