comparison libervia/pages/merge-requests/view/page_meta.py @ 1378:e3e303a30a74

pages (tickets): renamed "tickets" to "lists": "lists" is more generic, and tickets is actually a specific kind of list. /!\ "tickets_trackers_json" option has been renamed to "lists_directory_json".
author Goffi <goffi@goffi.org>
date Thu, 28 Jan 2021 18:51:44 +0100
parents 04e7dd6b6f4d
children 907f519faaf0
comparison
equal deleted inserted replaced
1377:46ce79eac754 1378:e3e303a30a74
3 3
4 from libervia.server.constants import Const as C 4 from libervia.server.constants import Const as C
5 from sat.core.i18n import _ 5 from sat.core.i18n import _
6 from libervia.server.utils import SubPage 6 from libervia.server.utils import SubPage
7 from libervia.server import session_iface 7 from libervia.server import session_iface
8 from twisted.internet import defer
9 from twisted.words.protocols.jabber import jid 8 from twisted.words.protocols.jabber import jid
10 from sat.tools.common import template_xmlui 9 from sat.tools.common import template_xmlui
11 from sat.tools.common import uri 10 from sat.tools.common import uri
12 from sat.tools.common import data_format 11 from sat.tools.common import data_format
13 from sat.core.log import getLogger 12 from sat.core.log import getLogger
20 19
21 def parse_url(self, request): 20 def parse_url(self, request):
22 try: 21 try:
23 item_id = self.nextPath(request) 22 item_id = self.nextPath(request)
24 except IndexError: 23 except IndexError:
25 log.warning(_("no ticket id specified")) 24 log.warning(_("no list item id specified"))
26 self.pageError(request, C.HTTP_BAD_REQUEST) 25 self.pageError(request, C.HTTP_BAD_REQUEST)
27 26
28 data = self.getRData(request) 27 data = self.getRData(request)
29 data["ticket_id"] = item_id 28 data["list_item_id"] = item_id
30 29
31 30
32 async def prepare_render(self, request): 31 async def prepare_render(self, request):
33 data = self.getRData(request) 32 data = self.getRData(request)
34 template_data = request.template_data 33 template_data = request.template_data
35 session = self.host.getSessionData(request, session_iface.ISATSession) 34 session = self.host.getSessionData(request, session_iface.ISATSession)
36 service, node, ticket_id = ( 35 service, node, list_item_id = (
37 data.get("service", ""), 36 data.get("service", ""),
38 data.get("node", ""), 37 data.get("node", ""),
39 data["ticket_id"], 38 data["list_item_id"],
40 ) 39 )
41 profile = self.getProfile(request) 40 profile = self.getProfile(request)
42 41
43 if profile is None: 42 if profile is None:
44 profile = C.SERVICE_PROFILE 43 profile = C.SERVICE_PROFILE
47 await self.host.bridgeCall( 46 await self.host.bridgeCall(
48 "mergeRequestsGet", 47 "mergeRequestsGet",
49 service.full() if service else "", 48 service.full() if service else "",
50 node, 49 node,
51 C.NO_LIMIT, 50 C.NO_LIMIT,
52 [ticket_id], 51 [list_item_id],
53 "", 52 "",
54 {"parse": C.BOOL_TRUE, "labels_as_list": C.BOOL_TRUE}, 53 {"parse": C.BOOL_TRUE, "labels_as_list": C.BOOL_TRUE},
55 profile, 54 profile,
56 ) 55 )
57 ) 56 )
58 ticket = template_xmlui.create( 57 list_item = template_xmlui.create(
59 self.host, merge_requests['items'][0], ignore=["request_data", "type"] 58 self.host, merge_requests['items'][0], ignore=["request_data", "type"]
60 ) 59 )
61 template_data["item"] = ticket 60 template_data["item"] = list_item
62 template_data["patches"] = merge_requests['items_patches'][0] 61 template_data["patches"] = merge_requests['items_patches'][0]
63 comments_uri = ticket.widgets["comments_uri"].value 62 comments_uri = list_item.widgets["comments_uri"].value
64 if comments_uri: 63 if comments_uri:
65 uri_data = uri.parseXMPPUri(comments_uri) 64 uri_data = uri.parseXMPPUri(comments_uri)
66 template_data["comments_node"] = comments_node = uri_data["node"] 65 template_data["comments_node"] = comments_node = uri_data["node"]
67 template_data["comments_service"] = comments_service = uri_data["path"] 66 template_data["comments_service"] = comments_service = uri_data["path"]
68 template_data["comments"] = data_format.deserialise(await self.host.bridgeCall( 67 template_data["comments"] = data_format.deserialise(await self.host.bridgeCall(
71 70
72 template_data["login_url"] = self.getPageRedirectURL(request) 71 template_data["login_url"] = self.getPageRedirectURL(request)
73 72
74 if session.connected: 73 if session.connected:
75 # we set edition URL only if user is the publisher or the node owner 74 # we set edition URL only if user is the publisher or the node owner
76 publisher = jid.JID(ticket.widgets["publisher"].value) 75 publisher = jid.JID(list_item.widgets["publisher"].value)
77 is_publisher = publisher.userhostJID() == session.jid.userhostJID() 76 is_publisher = publisher.userhostJID() == session.jid.userhostJID()
78 affiliation = None 77 affiliation = None
79 if not is_publisher: 78 if not is_publisher:
80 node = node or self.host.ns_map["merge_requests"] 79 node = node or self.host.ns_map["merge_requests"]
81 affiliation = await self.host.getAffiliation(request, service, node) 80 affiliation = await self.host.getAffiliation(request, service, node)
82 if is_publisher or affiliation == "owner": 81 if is_publisher or affiliation == "owner":
83 template_data["url_ticket_edit"] = self.getURLByPath( 82 template_data["url_list_item_edit"] = self.getURLByPath(
84 SubPage("merge-requests"), 83 SubPage("merge-requests"),
85 service.full(), 84 service.full(),
86 node or "@", 85 node or "@",
87 SubPage("merge-requests_edit"), 86 SubPage("merge-requests_edit"),
88 ticket_id, 87 list_item_id,
89 ) 88 )
90 89
91 90
92 async def on_data_post(self, request): 91 async def on_data_post(self, request):
93 type_ = self.getPostedData(request, "type") 92 type_ = self.getPostedData(request, "type")