Mercurial > libervia-web
annotate libervia/pages/tickets/view/page_meta.py @ 1376:1b94a5ab155f
pages (blog/view): Full-Text Search is used when `search` query argument is present
the new `LiberviaPage.handleSearch` method implements FTS in PubSub based features.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 Dec 2020 17:35:06 +0100 |
parents | 04e7dd6b6f4d |
children |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
967 | 3 |
4 from libervia.server.constants import Const as C | |
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 |
967 | 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 |
967 | 10 from sat.tools.common import template_xmlui |
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 |
967 | 13 from sat.core.log import getLogger |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
14 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
15 log = getLogger(__name__) |
967 | 16 """ticket handling pages""" |
17 | |
1216 | 18 name = "tickets_view" |
967 | 19 access = C.PAGES_ACCESS_PUBLIC |
1216 | 20 template = "ticket/item.html" |
967 | 21 |
22 | |
23 def parse_url(self, request): | |
24 try: | |
25 item_id = self.nextPath(request) | |
26 except IndexError: | |
1216 | 27 log.warning(_("no ticket id specified")) |
967 | 28 self.pageError(request, C.HTTP_BAD_REQUEST) |
29 | |
30 data = self.getRData(request) | |
1216 | 31 data["ticket_id"] = item_id |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
32 |
967 | 33 |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
34 async def prepare_render(self, request): |
967 | 35 data = self.getRData(request) |
36 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
|
37 session = self.host.getSessionData(request, session_iface.ISATSession) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
38 service, node, ticket_id = ( |
1216 | 39 data.get("service", ""), |
40 data.get("node", ""), | |
41 data["ticket_id"], | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
42 ) |
967 | 43 profile = self.getProfile(request) |
44 | |
45 if profile is None: | |
46 profile = C.SERVICE_PROFILE | |
47 | |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
48 tickets_raw = await self.host.bridgeCall( |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
49 "ticketsGet", |
1216 | 50 service.full() if service else "", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
51 node, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
52 C.NO_LIMIT, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
53 [ticket_id], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
54 "", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
55 {"labels_as_list": C.BOOL_TRUE}, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
56 profile, |
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 tickets, metadata = data_format.deserialise(tickets_raw, type_check=list) |
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
59 ticket = [template_xmlui.create(self.host, x) for x in tickets][0] |
1216 | 60 template_data["item"] = ticket |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
61 comments_uri = ticket.widgets["comments_uri"].value |
967 | 62 if comments_uri: |
63 uri_data = uri.parseXMPPUri(comments_uri) | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
64 template_data["comments_node"] = comments_node = uri_data["node"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
65 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
|
66 comments = data_format.deserialise(await self.host.bridgeCall( |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
67 "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
|
68 )) |
967 | 69 |
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 template_data["comments"] = comments |
1216 | 71 template_data["login_url"] = self.getPageRedirectURL(request) |
967 | 72 |
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
|
73 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
|
74 # 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
|
75 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
|
76 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
|
77 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
|
78 if not is_publisher: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
79 node = node or self.host.ns_map["tickets"] |
1302
04e7dd6b6f4d
pages (blog, tickets, merge-requests): updated code to handle new serialisation, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
80 affiliation = await self.host.getAffiliation(request, service, node) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
81 if is_publisher or affiliation == "owner": |
1216 | 82 template_data["url_ticket_edit"] = self.getURLByPath( |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
83 SubPage("tickets"), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
84 service.full(), |
1216 | 85 node or "@", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
86 SubPage("tickets_edit"), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
87 ticket_id, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
88 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1098
diff
changeset
|
89 |
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
|
90 |
967 | 91 @defer.inlineCallbacks |
92 def on_data_post(self, request): | |
1216 | 93 type_ = self.getPostedData(request, "type") |
94 if type_ == "comment": | |
95 blog_page = self.getPageByName("blog_view") | |
967 | 96 yield blog_page.on_data_post(self, request) |
97 else: | |
1216 | 98 log.warning(_("Unhandled data type: {}").format(type_)) |