Mercurial > libervia-web
annotate src/pages/tickets/view/page_meta.py @ 1106:09feea19d7b9
browser, server: added namespacesGet, so Libervia legacy app can run again
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 03 Jun 2018 13:55:09 +0200 |
parents | 01e95ec9df9e |
children | cdd389ef97bc |
rev | line source |
---|---|
967 | 1 #!/usr/bin/env python2.7 |
2 # -*- coding: utf-8 -*- | |
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 | |
12 from sat.tools.common import data_objects | |
13 from sat.core.log import getLogger | |
14 log = getLogger('pages/tickets/view') | |
15 """ticket handling pages""" | |
16 | |
981
97cce8c1e96a
pages(tickets): better URL handling:
Goffi <goffi@goffi.org>
parents:
975
diff
changeset
|
17 name = u"tickets_view" |
967 | 18 access = C.PAGES_ACCESS_PUBLIC |
19 template = u"ticket/item.html" | |
20 | |
21 | |
22 def parse_url(self, request): | |
23 try: | |
24 item_id = self.nextPath(request) | |
25 except IndexError: | |
26 log.warning(_(u"no ticket id specified")) | |
27 self.pageError(request, C.HTTP_BAD_REQUEST) | |
28 | |
29 data = self.getRData(request) | |
30 data[u'ticket_id'] = item_id | |
31 | |
32 @defer.inlineCallbacks | |
33 def prepare_render(self, request): | |
34 data = self.getRData(request) | |
35 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
|
36 session = self.host.getSessionData(request, session_iface.ISATSession) |
967 | 37 service, node, ticket_id = data.get(u'service', u''), data.get(u'node', u''), data[u'ticket_id'] |
38 profile = self.getProfile(request) | |
39 | |
40 if profile is None: | |
41 profile = C.SERVICE_PROFILE | |
42 | |
1098
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1095
diff
changeset
|
43 tickets = yield self.host.bridgeCall("ticketsGet", service.full() if service else u'', node, C.NO_LIMIT, [ticket_id], '', {'labels_as_list': C.BOOL_TRUE}, profile) |
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
|
44 ticket = [template_xmlui.create(self.host, x) for x in tickets[0]][0] |
967 | 45 template_data[u'item'] = ticket |
46 comments_uri = ticket.widgets['comments_uri'].value | |
47 if comments_uri: | |
48 uri_data = uri.parseXMPPUri(comments_uri) | |
49 template_data['comments_node'] = comments_node = uri_data['node'] | |
50 template_data['comments_service'] = comments_service = uri_data['path'] | |
1098
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1095
diff
changeset
|
51 comments = yield self.host.bridgeCall("mbGet", comments_service, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1095
diff
changeset
|
52 comments_node, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1095
diff
changeset
|
53 C.NO_LIMIT, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1095
diff
changeset
|
54 [], |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1095
diff
changeset
|
55 {}, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1095
diff
changeset
|
56 profile) |
967 | 57 |
58 template_data[u'comments'] = data_objects.BlogItems(comments) | |
59 template_data[u'login_url'] = self.getPageRedirectURL(request) | |
60 | |
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
|
61 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
|
62 # we set edition URL only if user is the publisher or the node owner |
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
|
63 publisher = jid.JID(ticket.widgets['publisher'].value) |
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
|
64 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
|
65 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
|
66 if not is_publisher: |
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
|
67 node = node or self.host.ns_map['tickets'] |
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
|
68 affiliation = yield self.host.getAffiliation(request, service, node) |
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
|
69 if is_publisher or affiliation == 'owner': |
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
|
70 template_data[u'url_ticket_edit'] = self.getURLByPath(SubPage('tickets'), service.full(), node or u'@', SubPage('tickets_edit'), ticket_id) |
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
|
71 |
967 | 72 @defer.inlineCallbacks |
73 def on_data_post(self, request): | |
74 type_ = self.getPostedData(request, u'type') | |
75 if type_ == u'comment': | |
1085
1c09f41e2f52
pages: fixed used of "blog" page instead of "blog_view"
Goffi <goffi@goffi.org>
parents:
994
diff
changeset
|
76 blog_page = self.getPageByName(u'blog_view') |
967 | 77 yield blog_page.on_data_post(self, request) |
78 else: | |
79 log.warning(_(u"Unhandled data type: {}").format(type_)) |