author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 14 Apr 2010 10:29:38 +0200 | |
changeset 5244 | 5467674ad101 |
parent 5234 | e2476d78b060 |
child 5358 | d4d294610ee7 |
permissions | -rw-r--r-- |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
1 |
"""security management and error screens |
0 | 2 |
|
3 |
||
4 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3953
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1941
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
1641 | 10 |
_ = unicode |
0 | 11 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2270
diff
changeset
|
12 |
from logilab.mtconverter import xml_escape |
0 | 13 |
|
1877
10b9feeb7905
anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1806
diff
changeset
|
14 |
from cubicweb.selectors import yes, none_rset, match_user_groups, authenticated_user |
4706
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
15 |
from cubicweb.view import AnyRsetView, StartupView, EntityView, View |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
16 |
from cubicweb.uilib import html_traceback, rest_traceback |
2270
70c0da0f2181
should use a hidden text area for error description, not an hidden input (else the browser may remove line breaks)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2052
diff
changeset
|
17 |
from cubicweb.web import formwidgets as wdgs |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
18 |
from cubicweb.web.formfields import guess_field |
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5232
diff
changeset
|
19 |
from cubicweb.web.views.schema import SecurityViewMixIn |
0 | 20 |
|
5232
78c1a531f7b3
ticket #787032, schema view improvement
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4714
diff
changeset
|
21 |
from yams.buildobjs import EntityType |
78c1a531f7b3
ticket #787032, schema view improvement
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4714
diff
changeset
|
22 |
|
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
23 |
SUBMIT_MSGID = _('Submit bug report') |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
24 |
MAIL_SUBMIT_MSGID = _('Submit bug report by mail') |
0 | 25 |
|
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5232
diff
changeset
|
26 |
class SecurityManagementView(SecurityViewMixIn, EntityView): |
0 | 27 |
"""display security information for a given entity""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
28 |
__regid__ = 'security' |
1877
10b9feeb7905
anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1806
diff
changeset
|
29 |
__select__ = EntityView.__select__ & authenticated_user() |
10b9feeb7905
anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1806
diff
changeset
|
30 |
|
0 | 31 |
title = _('security') |
1941
4f38e8b81a1a
egroup -> cwgroup #343418
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1877
diff
changeset
|
32 |
|
1569
99a19875ef1e
set progress div in call() to avoid duplication when applied on multiple entities
sylvain.thenault@logilab.fr
parents:
1568
diff
changeset
|
33 |
def call(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
34 |
self.w(u'<div id="progress">%s</div>' % self._cw._('validating...')) |
1569
99a19875ef1e
set progress div in call() to avoid duplication when applied on multiple entities
sylvain.thenault@logilab.fr
parents:
1568
diff
changeset
|
35 |
super(SecurityManagementView, self).call() |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
36 |
|
0 | 37 |
def cell_call(self, row, col): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
38 |
self._cw.add_js('cubicweb.edition.js') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
39 |
self._cw.add_css('cubicweb.acl.css') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
40 |
entity = self.cw_rset.get_entity(row, col) |
0 | 41 |
w = self.w |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
42 |
_ = self._cw._ |
0 | 43 |
w(u'<h1><span class="etype">%s</span> <a href="%s">%s</a></h1>' |
44 |
% (entity.dc_type().capitalize(), |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2270
diff
changeset
|
45 |
xml_escape(entity.absolute_url()), |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2270
diff
changeset
|
46 |
xml_escape(entity.dc_title()))) |
0 | 47 |
# first show permissions defined by the schema |
48 |
self.w('<h2>%s</h2>' % _('schema\'s permissions definitions')) |
|
5234
e2476d78b060
ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
5232
diff
changeset
|
49 |
self.permissions_table(entity.e_schema) |
0 | 50 |
self.w('<h2>%s</h2>' % _('manage security')) |
51 |
# ownership information |
|
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
52 |
if self._cw.vreg.schema.rschema('owned_by').has_perm(self._cw, 'add', |
0 | 53 |
fromeid=entity.eid): |
54 |
self.owned_by_edit_form(entity) |
|
55 |
else: |
|
56 |
self.owned_by_information(entity) |
|
1518 | 57 |
# cwpermissions |
0 | 58 |
if 'require_permission' in entity.e_schema.subject_relations(): |
59 |
w('<h3>%s</h3>' % _('permissions for this entity')) |
|
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
60 |
reqpermschema = self._cw.vreg.schema.rschema('require_permission') |
0 | 61 |
self.require_permission_information(entity, reqpermschema) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
62 |
if reqpermschema.has_perm(self._cw, 'add', fromeid=entity.eid): |
0 | 63 |
self.require_permission_edit_form(entity) |
64 |
||
65 |
def owned_by_edit_form(self, entity): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
66 |
self.w('<h3>%s</h3>' % self._cw._('ownership')) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
67 |
msg = self._cw._('ownerships have been changed') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
68 |
form = self._cw.vreg['forms'].select('base', self._cw, entity=entity, |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
69 |
form_renderer_id='base', submitmsg=msg, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
70 |
form_buttons=[wdgs.SubmitButton()], |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
71 |
domid='ownership%s' % entity.eid, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
72 |
__redirectvid='security', |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
73 |
__redirectpath=entity.rest_path()) |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
74 |
field = guess_field(entity.e_schema, self._cw.vreg.schema.rschema('owned_by')) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
75 |
form.append_field(field) |
4297
5f2081181055
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
76 |
self.w(form.render(display_progress_div=False)) |
0 | 77 |
|
78 |
def owned_by_information(self, entity): |
|
79 |
ownersrset = entity.related('owned_by') |
|
80 |
if ownersrset: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
81 |
self.w('<h3>%s</h3>' % self._cw._('ownership')) |
0 | 82 |
self.w(u'<div class="ownerInfo">') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
83 |
self.w(self._cw._('this entity is currently owned by') + ' ') |
0 | 84 |
self.wview('csv', entity.related('owned_by'), 'null') |
85 |
self.w(u'</div>') |
|
86 |
# else we don't know if this is because entity has no owner or becayse |
|
87 |
# user as no access to owner users entities |
|
88 |
||
89 |
def require_permission_information(self, entity, reqpermschema): |
|
90 |
if entity.require_permission: |
|
91 |
w = self.w |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
92 |
_ = self._cw._ |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
93 |
if reqpermschema.has_perm(self._cw, 'delete', fromeid=entity.eid): |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
94 |
delurl = self._cw.build_url('edit', __redirectvid='security', |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
95 |
__redirectpath=entity.rest_path()) |
0 | 96 |
delurl = delurl.replace('%', '%%') |
97 |
# don't give __delete value to build_url else it will be urlquoted |
|
98 |
# and this will replace %s by %25s |
|
99 |
delurl += '&__delete=%s:require_permission:%%s' % entity.eid |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2670
diff
changeset
|
100 |
dellinktempl = u'[<a href="%s" title="%s">-</a>] ' % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2270
diff
changeset
|
101 |
xml_escape(delurl), _('delete this permission')) |
0 | 102 |
else: |
103 |
dellinktempl = None |
|
104 |
w(u'<table class="schemaInfo">') |
|
105 |
w(u'<tr><th>%s</th><th>%s</th></tr>' % (_("permission"), |
|
106 |
_('granted to groups'))) |
|
1518 | 107 |
for cwperm in entity.require_permission: |
0 | 108 |
w(u'<tr>') |
109 |
if dellinktempl: |
|
1518 | 110 |
w(u'<td>%s%s</td>' % (dellinktempl % cwperm.eid, |
111 |
cwperm.view('oneline'))) |
|
0 | 112 |
else: |
1518 | 113 |
w(u'<td>%s</td>' % cwperm.view('oneline')) |
114 |
w(u'<td>%s</td>' % self.view('csv', cwperm.related('require_group'), 'null')) |
|
0 | 115 |
w(u'</tr>\n') |
116 |
w(u'</table>') |
|
117 |
else: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
118 |
self.w(self._cw._('no associated permissions')) |
0 | 119 |
|
120 |
def require_permission_edit_form(self, entity): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
121 |
newperm = self._cw.vreg['etypes'].etype_class('CWPermission')(self._cw) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
122 |
newperm.eid = self._cw.varmaker.next() |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
123 |
self.w(u'<p>%s</p>' % self._cw._('add a new permission')) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
124 |
form = self._cw.vreg['forms'].select('base', self._cw, entity=newperm, |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
125 |
form_buttons=[wdgs.SubmitButton()], |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
126 |
domid='reqperm%s' % entity.eid, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
127 |
__redirectvid='security', |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
128 |
__redirectpath=entity.rest_path()) |
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4045
diff
changeset
|
129 |
form.add_hidden('require_permission', entity.eid, role='object', |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4045
diff
changeset
|
130 |
eidparam=True) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
131 |
permnames = getattr(entity, '__permissions__', None) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
132 |
cwpermschema = newperm.e_schema |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
133 |
if permnames is not None: |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
134 |
field = guess_field(cwpermschema, self._cw.vreg.schema.rschema('name'), |
2270
70c0da0f2181
should use a hidden text area for error description, not an hidden input (else the browser may remove line breaks)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2052
diff
changeset
|
135 |
widget=wdgs.Select({'size': 1}), |
1531 | 136 |
choices=permnames) |
0 | 137 |
else: |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
138 |
field = guess_field(cwpermschema, self._cw.vreg.schema.rschema('name')) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
139 |
form.append_field(field) |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
140 |
field = guess_field(cwpermschema, self._cw.vreg.schema.rschema('label')) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
141 |
form.append_field(field) |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
142 |
field = guess_field(cwpermschema, self._cw.vreg.schema.rschema('require_group')) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
143 |
form.append_field(field) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
144 |
renderer = self._cw.vreg['formrenderers'].select( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
145 |
'htable', self._cw, rset=None, display_progress_div=False) |
3953
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
146 |
self.w(form.render(renderer=renderer)) |
0 | 147 |
|
148 |
||
149 |
class ErrorView(AnyRsetView): |
|
150 |
"""default view when no result has been found""" |
|
731
ac4a94e50b60
some more s/__selectors__/__select__ but still more to come
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
691
diff
changeset
|
151 |
__select__ = yes() |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3230
diff
changeset
|
152 |
__regid__ = 'error' |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
153 |
|
0 | 154 |
def page_title(self): |
155 |
"""returns a title according to the result set - used for the |
|
156 |
title in the HTML header |
|
157 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
158 |
return self._cw._('an error occured') |
0 | 159 |
|
160 |
def call(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
161 |
req = self._cw.reset_headers() |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
162 |
w = self.w |
0 | 163 |
ex = req.data.get('ex')#_("unable to find exception information")) |
164 |
excinfo = req.data.get('excinfo') |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
165 |
title = self._cw._('an error occured') |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
166 |
w(u'<h2>%s</h2>' % title) |
0 | 167 |
if 'errmsg' in req.data: |
168 |
ex = req.data['errmsg'] |
|
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
169 |
exclass = None |
0 | 170 |
else: |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
171 |
exclass = ex.__class__.__name__ |
0 | 172 |
ex = exc_message(ex, req.encoding) |
3733
c3feb6a33f58
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
173 |
if excinfo is not None and self._cw.vreg.config['print-traceback']: |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
174 |
if exclass is None: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
175 |
w(u'<div class="tb">%s</div>' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2270
diff
changeset
|
176 |
% xml_escape(ex).replace("\n","<br />")) |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
177 |
else: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
178 |
w(u'<div class="tb">%s: %s</div>' |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2270
diff
changeset
|
179 |
% (exclass, xml_escape(ex).replace("\n","<br />"))) |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
180 |
w(u'<hr />') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
181 |
w(u'<div class="tb">%s</div>' % html_traceback(excinfo, ex, '')) |
0 | 182 |
else: |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2270
diff
changeset
|
183 |
w(u'<div class="tb">%s</div>' % (xml_escape(ex).replace("\n","<br />"))) |
0 | 184 |
# if excinfo is not None, it's probably not a bug |
185 |
if excinfo is None: |
|
186 |
return |
|
3733
c3feb6a33f58
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
187 |
vcconf = self._cw.vreg.config.vc_config() |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
188 |
w(u"<div>") |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
189 |
eversion = vcconf.get('cubicweb', self._cw._('no version information')) |
0 | 190 |
# NOTE: tuple wrapping needed since eversion is itself a tuple |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
191 |
w(u"<b>CubicWeb version:</b> %s<br/>\n" % (eversion,)) |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
192 |
cversions = [] |
3733
c3feb6a33f58
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
193 |
for cube in self._cw.vreg.config.cubes(): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
194 |
cubeversion = vcconf.get(cube, self._cw._('no version information')) |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
195 |
w(u"<b>Package %s version:</b> %s<br/>\n" % (cube, cubeversion)) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
196 |
cversions.append((cube, cubeversion)) |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
197 |
w(u"</div>") |
3200
747d17498cca
#345461: drop support for cube_eid / direct bug submission
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
198 |
# creates a bug submission link if submit-mail is set |
3733
c3feb6a33f58
remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3451
diff
changeset
|
199 |
if self._cw.vreg.config['submit-mail']: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
200 |
form = self._cw.vreg['forms'].select('base', self._cw, rset=None, |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2433
diff
changeset
|
201 |
mainform=False) |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
202 |
binfo = text_error_description(ex, excinfo, req, eversion, cversions) |
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4045
diff
changeset
|
203 |
form.add_hidden('description', binfo, |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4045
diff
changeset
|
204 |
# we must use a text area to keep line breaks |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4045
diff
changeset
|
205 |
widget=wdgs.TextArea({'class': 'hidden'})) |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4045
diff
changeset
|
206 |
form.add_hidden('__bugreporting', '1') |
3200
747d17498cca
#345461: drop support for cube_eid / direct bug submission
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
207 |
form.form_buttons = [wdgs.SubmitButton(MAIL_SUBMIT_MSGID)] |
747d17498cca
#345461: drop support for cube_eid / direct bug submission
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
208 |
form.action = req.build_url('reportbug') |
3953
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
209 |
w(form.render()) |
0 | 210 |
|
211 |
||
212 |
def exc_message(ex, encoding): |
|
213 |
try: |
|
214 |
return unicode(ex) |
|
215 |
except: |
|
216 |
try: |
|
217 |
return unicode(str(ex), encoding, 'replace') |
|
218 |
except: |
|
219 |
return unicode(repr(ex), encoding, 'replace') |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
220 |
|
0 | 221 |
def text_error_description(ex, excinfo, req, eversion, cubes): |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2270
diff
changeset
|
222 |
binfo = rest_traceback(excinfo, xml_escape(ex)) |
0 | 223 |
binfo += u'\n\n:URL: %s\n' % req.url() |
224 |
if not '__bugreporting' in req.form: |
|
225 |
binfo += u'\n:form params:\n' |
|
226 |
binfo += u'\n'.join(u' * %s = %s' % (k, v) for k, v in req.form.iteritems()) |
|
227 |
binfo += u'\n\n:CubicWeb version: %s\n' % (eversion,) |
|
228 |
for pkg, pkgversion in cubes: |
|
229 |
binfo += u":Package %s version: %s\n" % (pkg, pkgversion) |
|
230 |
binfo += '\n' |
|
231 |
return binfo |
|
232 |
||
1877
10b9feeb7905
anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1806
diff
changeset
|
233 |
|
4706
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
234 |
class CwStats(View): |
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
235 |
"""A textual stats output for monitoring tools such as munin """ |
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
236 |
|
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
237 |
__regid__ = 'processinfo' |
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
238 |
content_type = 'text/txt' |
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
239 |
templatable = False |
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
240 |
__select__ = none_rset() & match_user_groups('users', 'managers') |
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
241 |
|
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
242 |
def call(self): |
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
243 |
stats = self._cw.vreg.config.repository(None).stats() |
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
244 |
results = [] |
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4297
diff
changeset
|
245 |
for element in stats: |
4713
785299dfc2c0
[i18n] nothing to translate here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4706
diff
changeset
|
246 |
results.append(u'%s %s' % (element, stats[element])) |
785299dfc2c0
[i18n] nothing to translate here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4706
diff
changeset
|
247 |
self.w(u'\n'.join(results)) |