annotate libervia/pages/tickets/view/page_meta.py @ 1194:bed008b65d7c

pages (merge-requests/edit, tickets/edit, tickets/new): use serialised extra following backend change + fixed use of "update" when editing ticket: "update" was not set in extra, as a result some metadata could be lost on update (author, comments_uri). fix 301
author Goffi <goffi@goffi.org>
date Fri, 14 Jun 2019 12:50:59 +0200
parents 29eb15062416
children b2d067339de3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
4d1dcf97740f pages (tickets): tickets first draft:
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
967
4d1dcf97740f pages (tickets): tickets first draft:
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
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 from sat.tools.common import template_xmlui
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 from sat.tools.common import uri
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 from sat.tools.common import data_objects
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 """ticket handling pages"""
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17
981
97cce8c1e96a pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents: 975
diff changeset
18 name = u"tickets_view"
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 access = C.PAGES_ACCESS_PUBLIC
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 template = u"ticket/item.html"
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 def parse_url(self, request):
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 try:
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 item_id = self.nextPath(request)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 except IndexError:
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 log.warning(_(u"no ticket id specified"))
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 self.pageError(request, C.HTTP_BAD_REQUEST)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 data = self.getRData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
31 data[u"ticket_id"] = item_id
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
32
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 @defer.inlineCallbacks
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 def prepare_render(self, request):
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 data = self.getRData(request)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 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
38 session = self.host.getSessionData(request, session_iface.ISATSession)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
39 service, node, ticket_id = (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
40 data.get(u"service", u""),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
41 data.get(u"node", u""),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
42 data[u"ticket_id"],
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
43 )
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 profile = self.getProfile(request)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 if profile is None:
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 profile = C.SERVICE_PROFILE
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
49 tickets = yield self.host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
50 "ticketsGet",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
51 service.full() if service else u"",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
52 node,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
53 C.NO_LIMIT,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
54 [ticket_id],
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
55 "",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
56 {"labels_as_list": C.BOOL_TRUE},
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
57 profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
58 )
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
59 ticket = [template_xmlui.create(self.host, x) for x in tickets[0]][0]
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
60 template_data[u"item"] = ticket
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
61 comments_uri = ticket.widgets["comments_uri"].value
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 if comments_uri:
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
66 comments = yield self.host.bridgeCall(
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
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
68 )
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
70 template_data[u"comments"] = data_objects.BlogItems(comments)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
71 template_data[u"login_url"] = self.getPageRedirectURL(request)
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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"]
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
80 affiliation = yield 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":
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
82 template_data[u"url_ticket_edit"] = self.getURLByPath(
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(),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
85 node or u"@",
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
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 @defer.inlineCallbacks
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 def on_data_post(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
93 type_ = self.getPostedData(request, u"type")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
94 if type_ == u"comment":
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1098
diff changeset
95 blog_page = self.getPageByName(u"blog_view")
967
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 yield blog_page.on_data_post(self, request)
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 else:
4d1dcf97740f pages (tickets): tickets first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 log.warning(_(u"Unhandled data type: {}").format(type_))