author | sylvain.thenault@logilab.fr |
Tue, 12 May 2009 11:56:12 +0200 | |
branch | tls-sprint |
changeset 1739 | 78b0819162a8 |
parent 1641 | 2c80b09d8d86 |
child 1806 | e94b65445826 |
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 |
|
635
305da8d6aa2d
require_group/match_user_group -> match_user_groups
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 |
""" |
|
8 |
__docformat__ = "restructuredtext en" |
|
1641 | 9 |
_ = unicode |
0 | 10 |
|
11 |
from logilab.mtconverter import html_escape |
|
12 |
||
691
35133d86970b
move EProperty management views into eproperties.py
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
688
diff
changeset
|
13 |
from cubicweb.selectors import yes, none_rset, match_user_groups |
836 | 14 |
from cubicweb.view import AnyRsetView, StartupView, EntityView |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
602
diff
changeset
|
15 |
from cubicweb.common.uilib import html_traceback, rest_traceback |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
16 |
from cubicweb.web import formwidgets |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
17 |
from cubicweb.web.form import FieldsForm, EntityFieldsForm |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
18 |
from cubicweb.web.formfields import guess_field |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
19 |
from cubicweb.web.formrenderers import HTableFormRenderer |
0 | 20 |
|
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
21 |
SUBMIT_MSGID = _('Submit bug report') |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
22 |
MAIL_SUBMIT_MSGID = _('Submit bug report by mail') |
0 | 23 |
|
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
24 |
class SecurityViewMixIn(object): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
25 |
"""display security information for a given schema """ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
26 |
def schema_definition(self, eschema, link=True, access_types=None): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
27 |
w = self.w |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
28 |
_ = self.req._ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
29 |
if not access_types: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
30 |
access_types = eschema.ACTIONS |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
31 |
w(u'<table class="schemaInfo">') |
1641 | 32 |
w(u'<tr><th>%s</th><th>%s</th><th>%s</th></tr>' % ( |
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
33 |
_("permission"), _('granted to groups'), _('rql expressions'))) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
34 |
for access_type in access_types: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
35 |
w(u'<tr>') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
36 |
w(u'<td>%s</td>' % _('%s_perm' % access_type)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
37 |
groups = eschema.get_groups(access_type) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
38 |
l = [] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
39 |
groups = [(_(group), group) for group in groups] |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
40 |
for trad, group in sorted(groups): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
41 |
if link: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
42 |
l.append(u'<a href="%s" class="%s">%s</a><br/>' % ( |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
43 |
self.build_url('egroup/%s' % group), group, trad)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
44 |
else: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
45 |
l.append(u'<div class="%s">%s</div>' % (group, trad)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
46 |
w(u'<td>%s</td>' % u''.join(l)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
47 |
rqlexprs = eschema.get_rqlexprs(access_type) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
48 |
w(u'<td>%s</td>' % u'<br/><br/>'.join(expr.expression for expr in rqlexprs)) |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
49 |
w(u'</tr>\n') |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
50 |
w(u'</table>') |
0 | 51 |
|
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
52 |
def has_schema_modified_permissions(self, eschema, access_types): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
53 |
""" return True if eschema's actual permissions are diffrents |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
54 |
from the default ones |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
55 |
""" |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
56 |
for access_type in access_types: |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
57 |
if eschema.get_rqlexprs(access_type): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
58 |
return True |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
59 |
if eschema.get_groups(access_type) != \ |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
60 |
frozenset(eschema.get_default_groups()[access_type]): |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
61 |
return True |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
62 |
return False |
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
63 |
|
1525
cc2e2cbd7019
include dom id of the form in __errorurl in case there are multiple forms in a page
sylvain.thenault@logilab.fr
parents:
1522
diff
changeset
|
64 |
|
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
65 |
class SecurityManagementView(EntityView, SecurityViewMixIn): |
0 | 66 |
"""display security information for a given entity""" |
67 |
id = 'security' |
|
68 |
title = _('security') |
|
1569
99a19875ef1e
set progress div in call() to avoid duplication when applied on multiple entities
sylvain.thenault@logilab.fr
parents:
1568
diff
changeset
|
69 |
def call(self): |
99a19875ef1e
set progress div in call() to avoid duplication when applied on multiple entities
sylvain.thenault@logilab.fr
parents:
1568
diff
changeset
|
70 |
self.w(u'<div id="progress">%s</div>' % self.req._('validating...')) |
99a19875ef1e
set progress div in call() to avoid duplication when applied on multiple entities
sylvain.thenault@logilab.fr
parents:
1568
diff
changeset
|
71 |
super(SecurityManagementView, self).call() |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
72 |
|
0 | 73 |
def cell_call(self, row, col): |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
74 |
self.req.add_js('cubicweb.edition.js') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
75 |
self.req.add_css('cubicweb.acl.css') |
0 | 76 |
entity = self.entity(row, col) |
77 |
w = self.w |
|
78 |
_ = self.req._ |
|
79 |
w(u'<h1><span class="etype">%s</span> <a href="%s">%s</a></h1>' |
|
80 |
% (entity.dc_type().capitalize(), |
|
81 |
html_escape(entity.absolute_url()), |
|
82 |
html_escape(entity.dc_title()))) |
|
83 |
# first show permissions defined by the schema |
|
84 |
self.w('<h2>%s</h2>' % _('schema\'s permissions definitions')) |
|
1494
d68aac1cda0d
#342695: add new security section to the schema view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1333
diff
changeset
|
85 |
self.schema_definition(entity.e_schema) |
0 | 86 |
self.w('<h2>%s</h2>' % _('manage security')) |
87 |
# ownership information |
|
88 |
if self.schema.rschema('owned_by').has_perm(self.req, 'add', |
|
89 |
fromeid=entity.eid): |
|
90 |
self.owned_by_edit_form(entity) |
|
91 |
else: |
|
92 |
self.owned_by_information(entity) |
|
1518 | 93 |
# cwpermissions |
0 | 94 |
if 'require_permission' in entity.e_schema.subject_relations(): |
95 |
w('<h3>%s</h3>' % _('permissions for this entity')) |
|
96 |
reqpermschema = self.schema.rschema('require_permission') |
|
97 |
self.require_permission_information(entity, reqpermschema) |
|
98 |
if reqpermschema.has_perm(self.req, 'add', fromeid=entity.eid): |
|
99 |
self.require_permission_edit_form(entity) |
|
100 |
||
101 |
def owned_by_edit_form(self, entity): |
|
102 |
self.w('<h3>%s</h3>' % self.req._('ownership')) |
|
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
103 |
msg = self.req._('ownerships have been changed') |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
104 |
form = EntityFieldsForm(self.req, None, entity=entity, submitmsg=msg, |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
105 |
form_buttons=[formwidgets.SubmitButton()], |
1525
cc2e2cbd7019
include dom id of the form in __errorurl in case there are multiple forms in a page
sylvain.thenault@logilab.fr
parents:
1522
diff
changeset
|
106 |
domid='ownership%s' % entity.eid, |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
107 |
__redirectvid='security', |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
108 |
__redirectpath=entity.rest_path()) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
109 |
field = guess_field(entity.e_schema, self.schema.rschema('owned_by')) |
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
110 |
form.append_field(field) |
1567 | 111 |
self.w(form.form_render(display_progress_div=False)) |
0 | 112 |
|
113 |
def owned_by_information(self, entity): |
|
114 |
ownersrset = entity.related('owned_by') |
|
115 |
if ownersrset: |
|
116 |
self.w('<h3>%s</h3>' % self.req._('ownership')) |
|
117 |
self.w(u'<div class="ownerInfo">') |
|
118 |
self.w(self.req._('this entity is currently owned by') + ' ') |
|
119 |
self.wview('csv', entity.related('owned_by'), 'null') |
|
120 |
self.w(u'</div>') |
|
121 |
# else we don't know if this is because entity has no owner or becayse |
|
122 |
# user as no access to owner users entities |
|
123 |
||
124 |
def require_permission_information(self, entity, reqpermschema): |
|
125 |
if entity.require_permission: |
|
126 |
w = self.w |
|
127 |
_ = self.req._ |
|
128 |
if reqpermschema.has_perm(self.req, 'delete', fromeid=entity.eid): |
|
129 |
delurl = self.build_url('edit', __redirectvid='security', |
|
130 |
__redirectpath=entity.rest_path()) |
|
131 |
delurl = delurl.replace('%', '%%') |
|
132 |
# don't give __delete value to build_url else it will be urlquoted |
|
133 |
# and this will replace %s by %25s |
|
134 |
delurl += '&__delete=%s:require_permission:%%s' % entity.eid |
|
135 |
dellinktempl = u'[<a href="%s" title="%s">-</a>] ' % ( |
|
136 |
html_escape(delurl), _('delete this permission')) |
|
137 |
else: |
|
138 |
dellinktempl = None |
|
139 |
w(u'<table class="schemaInfo">') |
|
140 |
w(u'<tr><th>%s</th><th>%s</th></tr>' % (_("permission"), |
|
141 |
_('granted to groups'))) |
|
1518 | 142 |
for cwperm in entity.require_permission: |
0 | 143 |
w(u'<tr>') |
144 |
if dellinktempl: |
|
1518 | 145 |
w(u'<td>%s%s</td>' % (dellinktempl % cwperm.eid, |
146 |
cwperm.view('oneline'))) |
|
0 | 147 |
else: |
1518 | 148 |
w(u'<td>%s</td>' % cwperm.view('oneline')) |
149 |
w(u'<td>%s</td>' % self.view('csv', cwperm.related('require_group'), 'null')) |
|
0 | 150 |
w(u'</tr>\n') |
151 |
w(u'</table>') |
|
152 |
else: |
|
1518 | 153 |
self.w(self.req._('no associated permissions')) |
0 | 154 |
|
155 |
def require_permission_edit_form(self, entity): |
|
156 |
w = self.w |
|
157 |
_ = self.req._ |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1388
diff
changeset
|
158 |
newperm = self.vreg.etype_class('CWPermission')(self.req, None) |
0 | 159 |
newperm.eid = self.req.varmaker.next() |
160 |
w(u'<p>%s</p>' % _('add a new permission')) |
|
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
161 |
form = EntityFieldsForm(self.req, None, entity=newperm, |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
162 |
form_buttons=[formwidgets.SubmitButton()], |
1525
cc2e2cbd7019
include dom id of the form in __errorurl in case there are multiple forms in a page
sylvain.thenault@logilab.fr
parents:
1522
diff
changeset
|
163 |
domid='reqperm%s' % entity.eid, |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
164 |
__redirectvid='security', |
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
165 |
__redirectpath=entity.rest_path()) |
1531 | 166 |
form.form_add_hidden('require_permission', entity.eid, role='object', |
167 |
eidparam=True) |
|
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
168 |
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
|
169 |
cwpermschema = newperm.e_schema |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
170 |
if permnames is not 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
|
171 |
field = guess_field(cwpermschema, self.schema.rschema('name'), |
1531 | 172 |
widget=formwidgets.Select({'size': 1}), |
173 |
choices=permnames) |
|
0 | 174 |
else: |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
175 |
field = guess_field(cwpermschema, self.schema.rschema('name')) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
176 |
form.append_field(field) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
177 |
field = guess_field(cwpermschema, self.schema.rschema('label')) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
178 |
form.append_field(field) |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
179 |
field = guess_field(cwpermschema, self.schema.rschema('require_group')) |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
180 |
form.append_field(field) |
1566
85a8e6b1279a
avoid progress_div duplication causing xhtml validation failures
sylvain.thenault@logilab.fr
parents:
1531
diff
changeset
|
181 |
self.w(form.form_render(renderer=HTableFormRenderer(display_progress_div=False))) |
0 | 182 |
|
183 |
||
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
184 |
|
0 | 185 |
class ErrorView(AnyRsetView): |
186 |
"""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
|
187 |
__select__ = yes() |
0 | 188 |
id = 'error' |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
189 |
|
0 | 190 |
def page_title(self): |
191 |
"""returns a title according to the result set - used for the |
|
192 |
title in the HTML header |
|
193 |
""" |
|
194 |
return self.req._('an error occured') |
|
195 |
||
196 |
def call(self): |
|
197 |
req = self.req.reset_headers() |
|
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
198 |
w = self.w |
0 | 199 |
ex = req.data.get('ex')#_("unable to find exception information")) |
200 |
excinfo = req.data.get('excinfo') |
|
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
201 |
title = self.req._('an error occured') |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
202 |
w(u'<h2>%s</h2>' % title) |
0 | 203 |
if 'errmsg' in req.data: |
204 |
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
|
205 |
exclass = None |
0 | 206 |
else: |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
207 |
exclass = ex.__class__.__name__ |
0 | 208 |
ex = exc_message(ex, req.encoding) |
209 |
if excinfo is not None and self.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
|
210 |
if exclass is None: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
211 |
w(u'<div class="tb">%s</div>' |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
212 |
% html_escape(ex).replace("\n","<br />")) |
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
213 |
else: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
214 |
w(u'<div class="tb">%s: %s</div>' |
174
a2966960d550
get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
215 |
% (exclass, html_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
|
216 |
w(u'<hr />') |
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
217 |
w(u'<div class="tb">%s</div>' % html_traceback(excinfo, ex, '')) |
0 | 218 |
else: |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
219 |
w(u'<div class="tb">%s</div>' % (html_escape(ex).replace("\n","<br />"))) |
0 | 220 |
# if excinfo is not None, it's probably not a bug |
221 |
if excinfo is None: |
|
222 |
return |
|
223 |
vcconf = self.config.vc_config() |
|
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
224 |
w(u"<div>") |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
225 |
eversion = vcconf.get('cubicweb', self.req._('no version information')) |
0 | 226 |
# 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
|
227 |
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
|
228 |
cversions = [] |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
229 |
for cube in self.config.cubes(): |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
230 |
cubeversion = vcconf.get(cube, self.req._('no version information')) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
231 |
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
|
232 |
cversions.append((cube, cubeversion)) |
602
1454282a8b45
[views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
431
diff
changeset
|
233 |
w(u"</div>") |
0 | 234 |
# creates a bug submission link if SUBMIT_URL is set |
235 |
submiturl = self.config['submit-url'] |
|
236 |
submitmail = self.config['submit-mail'] |
|
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
237 |
if submiturl or submitmail: |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
238 |
form = FieldsForm(self.req, set_error_url=False) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
239 |
binfo = text_error_description(ex, excinfo, req, eversion, cversions) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
240 |
form.form_add_hidden('description', binfo) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
241 |
form.form_add_hidden('__bugreporting', '1') |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
242 |
if submitmail: |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
243 |
form.form_buttons = [formwidgets.SubmitButton(MAIL_SUBMIT_MSGID)] |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
244 |
form.action = req.build_url('reportbug') |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
245 |
w(form.form_render()) |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
246 |
if submiturl: |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
247 |
form.form_add_hidden('description_format', 'text/rest') |
1402
04b7afb14b50
new style security management forms
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
248 |
form.form_buttons = [formwidgets.SubmitButton(SUBMIT_MSGID)] |
1388
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
249 |
form.action = submiturl |
6d5f0ccf31b8
new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents:
836
diff
changeset
|
250 |
w(form.form_render()) |
0 | 251 |
|
252 |
||
253 |
def exc_message(ex, encoding): |
|
254 |
try: |
|
255 |
return unicode(ex) |
|
256 |
except: |
|
257 |
try: |
|
258 |
return unicode(str(ex), encoding, 'replace') |
|
259 |
except: |
|
260 |
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
|
261 |
|
0 | 262 |
def text_error_description(ex, excinfo, req, eversion, cubes): |
263 |
binfo = rest_traceback(excinfo, html_escape(ex)) |
|
264 |
binfo += u'\n\n:URL: %s\n' % req.url() |
|
265 |
if not '__bugreporting' in req.form: |
|
266 |
binfo += u'\n:form params:\n' |
|
267 |
binfo += u'\n'.join(u' * %s = %s' % (k, v) for k, v in req.form.iteritems()) |
|
268 |
binfo += u'\n\n:CubicWeb version: %s\n' % (eversion,) |
|
269 |
for pkg, pkgversion in cubes: |
|
270 |
binfo += u":Package %s version: %s\n" % (pkg, pkgversion) |
|
271 |
binfo += '\n' |
|
272 |
return binfo |
|
273 |
||
274 |
class ProcessInformationView(StartupView): |
|
275 |
id = 'info' |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
731
diff
changeset
|
276 |
__select__ = none_rset() & match_user_groups('managers') |
1453
a9841184be7c
guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents:
1402
diff
changeset
|
277 |
|
0 | 278 |
title = _('server information') |
279 |
||
280 |
def call(self, **kwargs): |
|
281 |
"""display server information""" |
|
282 |
vcconf = self.config.vc_config() |
|
283 |
req = self.req |
|
284 |
_ = req._ |
|
285 |
# display main information |
|
286 |
self.w(u'<h3>%s</h3>' % _('Application')) |
|
287 |
self.w(u'<table border="1">') |
|
288 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
289 |
'CubicWeb', vcconf.get('cubicweb', _('no version information')))) |
|
290 |
for pkg in self.config.cubes(): |
|
291 |
pkgversion = vcconf.get(pkg, _('no version information')) |
|
292 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
293 |
pkg, pkgversion)) |
|
294 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
295 |
_('home'), self.config.apphome)) |
|
296 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
297 |
_('base url'), req.base_url())) |
|
298 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
299 |
_('data directory url'), req.datadir_url)) |
|
300 |
self.w(u'</table>') |
|
301 |
self.w(u'<br/>') |
|
302 |
# environment and request and server information |
|
303 |
try: |
|
304 |
# need to remove our adapter and then modpython-apache wrapper... |
|
305 |
env = req._areq._req.subprocess_env |
|
306 |
except AttributeError: |
|
307 |
return |
|
308 |
self.w(u'<h3>%s</h3>' % _('Environment')) |
|
309 |
self.w(u'<table border="1">') |
|
310 |
for attr in env.keys(): |
|
311 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' |
|
312 |
% (attr, html_escape(env[attr]))) |
|
313 |
self.w(u'</table>') |
|
314 |
self.w(u'<h3>%s</h3>' % _('Request')) |
|
315 |
self.w(u'<table border="1">') |
|
316 |
for attr in ('filename', 'form', 'hostname', 'main', 'method', |
|
317 |
'path_info', 'protocol', |
|
318 |
'search_state', 'the_request', 'unparsed_uri', 'uri'): |
|
319 |
val = getattr(req, attr) |
|
320 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' |
|
321 |
% (attr, html_escape(val))) |
|
322 |
self.w(u'</table>') |
|
323 |
server = req.server |
|
324 |
self.w(u'<h3>%s</h3>' % _('Server')) |
|
325 |
self.w(u'<table border="1">') |
|
326 |
for attr in dir(server): |
|
327 |
val = getattr(server, attr) |
|
328 |
if attr.startswith('_') or callable(val): |
|
329 |
continue |
|
330 |
self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' |
|
331 |
% (attr, html_escape(val))) |
|
332 |
self.w(u'</table>') |
|
333 |