Mercurial > libervia-web
annotate src/pages/merge-requests/view/page_meta.py @ 1107:2066d4fd9036
browser: fixed XMLUI Panel and Dialog
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 03 Jun 2018 14:04:05 +0200 |
parents | 01e95ec9df9e |
children | cdd389ef97bc |
rev | line source |
---|---|
991
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2.7 |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
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 |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 from sat.tools.common import data_objects |
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 |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 name = u"merge-requests_view" |
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 |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 template = u"merge-request/item.html" |
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
|
18 log = getLogger(u'pages/' + 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: |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 log.warning(_(u"no ticket id specified")) |
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) |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 data[u'ticket_id'] = item_id |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 @defer.inlineCallbacks |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 def prepare_render(self, request): |
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) |
991
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 service, node, ticket_id = data.get(u'service', u''), data.get(u'node', u''), data[u'ticket_id'] |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 profile = self.getProfile(request) |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 if profile is None: |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 profile = C.SERVICE_PROFILE |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
1098
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
42 tickets, metadata, parsed_tickets = yield self.host.bridgeCall("mergeRequestsGet", service.full() if service else u'', |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
43 node, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
44 C.NO_LIMIT, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
45 [ticket_id], |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
46 '', |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
47 {'parse': C.BOOL_TRUE, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
48 'labels_as_list': C.BOOL_TRUE}, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
49 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
|
50 ticket = template_xmlui.create(self.host, tickets[0], ignore=['request_data', 'type']) |
991
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 template_data[u'item'] = ticket |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 template_data['patches'] = parsed_tickets[0] |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 comments_uri = ticket.widgets['comments_uri'].value |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 if comments_uri: |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 uri_data = uri.parseXMPPUri(comments_uri) |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 template_data['comments_node'] = comments_node = uri_data['node'] |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 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:
1097
diff
changeset
|
58 comments = yield self.host.bridgeCall("mbGet", |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
59 comments_service, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
60 comments_node, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
61 C.NO_LIMIT, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
62 [], |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
63 {}, |
01e95ec9df9e
server, pages: fixed blocking calls to bridge by using bridgeCall instead
Goffi <goffi@goffi.org>
parents:
1097
diff
changeset
|
64 profile) |
991
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 template_data[u'comments'] = data_objects.BlogItems(comments) |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 template_data[u'login_url'] = self.getPageRedirectURL(request) |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 |
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
|
69 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
|
70 # 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
|
71 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
|
72 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
|
73 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
|
74 if not is_publisher: |
1097
f134c0ecb1d5
pages (merge-requests/view): fixed default node when checking affiliations
Goffi <goffi@goffi.org>
parents:
1095
diff
changeset
|
75 node = node or self.host.ns_map['merge_requests'] |
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 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
|
77 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
|
78 template_data[u'url_ticket_edit'] = self.getURLByPath(SubPage('merge-requests'), service.full(), node or u'@', SubPage('merge-requests_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
|
79 |
991
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 @defer.inlineCallbacks |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 def on_data_post(self, request): |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 type_ = self.getPostedData(request, u'type') |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 if type_ == u'comment': |
1085
1c09f41e2f52
pages: fixed used of "blog" page instead of "blog_view"
Goffi <goffi@goffi.org>
parents:
994
diff
changeset
|
84 blog_page = self.getPageByName(u'blog_view') |
991
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 yield blog_page.on_data_post(self, request) |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 else: |
6ce9647011b3
pages(merge-requests): merge requests new, view and list pages implementations.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 log.warning(_(u"Unhandled data type: {}").format(type_)) |