web/views/management.py
author Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
Thu, 26 Nov 2015 11:30:54 +0100
changeset 10935 049209b9e9d6
parent 10922 7d01c8c675a0
permissions -rw-r--r--
[qunit] stop dealing with filesystem paths qunit tests need a few things served by cubicweb: - qunit itself, which is now handled by CWDevtoolsStaticController (serving files in cubicweb/devtools/data) - standard cubicweb or cubes data files, handled by the DataController - the tests themselves and their dependencies. These can live in <apphome>/data or <apphome>/static and be served by one of the STATIC_CONTROLLERS This avoids having to guess in CWSoftwareRootStaticController where to serve things from (some files may be installed, others are in the source tree), and should hopefully make it possible to have these tests pass when using tox, and to write qunit tests for cubes, outside of cubicweb itself. This requires modifying the tests to only declare URL paths instead of filesystem paths, and moving support files below test/data/static.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7808
diff changeset
     1
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4714
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5528
5d1b2ae7d459 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    18
"""security management and error screens"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
10666
7f6b5f023884 [py3k] replace '_ = unicode' in global scope (closes #7589459)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10662
diff changeset
    21
from cubicweb import _
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
8605
797fc2e2fb78 [web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents: 8604
diff changeset
    23
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
    24
from logilab.mtconverter import xml_escape
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7808
diff changeset
    25
from logilab.common.registry import yes
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7808
diff changeset
    27
from cubicweb.predicates import none_rset, match_user_groups, authenticated_user
4706
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
    28
from cubicweb.view import AnyRsetView, StartupView, EntityView, View
6683
68cfebd3b9f3 fix #724689: exception's display during ajax call
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6453
diff changeset
    29
from cubicweb.uilib import html_traceback, rest_traceback, exc_message
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
    30
from cubicweb.web import formwidgets as wdgs
1402
04b7afb14b50 new style security management forms
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    31
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
    32
from cubicweb.web.views.schema import SecurityViewMixIn
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
5232
78c1a531f7b3 ticket #787032, schema view improvement
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4714
diff changeset
    34
from yams.buildobjs import EntityType
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
1388
6d5f0ccf31b8 new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents: 836
diff changeset
    36
SUBMIT_MSGID = _('Submit bug report')
6d5f0ccf31b8 new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents: 836
diff changeset
    37
MAIL_SUBMIT_MSGID = _('Submit bug report by mail')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5232
diff changeset
    39
class SecurityManagementView(SecurityViewMixIn, EntityView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
    """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
    41
    __regid__ = 'security'
1877
10b9feeb7905 anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1806
diff changeset
    42
    __select__ = EntityView.__select__ & authenticated_user()
10b9feeb7905 anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1806
diff changeset
    43
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
    title = _('security')
1941
4f38e8b81a1a egroup -> cwgroup #343418
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1877
diff changeset
    45
1569
99a19875ef1e set progress div in call() to avoid duplication when applied on multiple entities
sylvain.thenault@logilab.fr
parents: 1568
diff changeset
    46
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    47
        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
    48
        super(SecurityManagementView, self).call()
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
    49
7797
a71618a75b53 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
    50
    def entity_call(self, entity):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    51
        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
    52
        self._cw.add_css('cubicweb.acl.css')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
        w = self.w
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    54
        _ = self._cw._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
        w(u'<h1><span class="etype">%s</span> <a href="%s">%s</a></h1>'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
          % (entity.dc_type().capitalize(),
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
    57
             xml_escape(entity.absolute_url()),
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
    58
             xml_escape(entity.dc_title())))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
        # first show permissions defined by the schema
7808
d90338624ea0 [security view] slight changes to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7797
diff changeset
    60
        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
    61
        self.permissions_table(entity.e_schema)
7808
d90338624ea0 [security view] slight changes to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7797
diff changeset
    62
        self.w('<h2>%s</h2>' % _('Manage security'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
        # ownership information
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4023
diff changeset
    64
        if self._cw.vreg.schema.rschema('owned_by').has_perm(self._cw, 'add',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
                                                    fromeid=entity.eid):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
            self.owned_by_edit_form(entity)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
            self.owned_by_information(entity)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
    def owned_by_edit_form(self, entity):
7808
d90338624ea0 [security view] slight changes to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7797
diff changeset
    71
        self.w('<h3>%s</h3>' % self._cw._('Ownership'))
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    72
        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
    73
        form = self._cw.vreg['forms'].select('base', self._cw, entity=entity,
7808
d90338624ea0 [security view] slight changes to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7797
diff changeset
    74
                                         form_renderer_id='onerowtable', submitmsg=msg,
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
    75
                                         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
    76
                                         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
    77
                                         __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
    78
                                         __redirectpath=entity.rest_path())
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8605
diff changeset
    79
        field = guess_field(entity.e_schema,
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8605
diff changeset
    80
                            self._cw.vreg.schema['owned_by'],
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8605
diff changeset
    81
                            req=self._cw)
1453
a9841184be7c guess_field now takes an entity schema as first argument, not an entity class
sylvain.thenault@logilab.fr
parents: 1402
diff changeset
    82
        form.append_field(field)
6453
7fdd780d87e4 [form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
    83
        form.render(w=self.w, display_progress_div=False)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
    def owned_by_information(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
        ownersrset = entity.related('owned_by')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
        if ownersrset:
7808
d90338624ea0 [security view] slight changes to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7797
diff changeset
    88
            self.w('<h3>%s</h3>' % self._cw._('Ownership'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
            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
    90
            self.w(self._cw._('this entity is currently owned by') + ' ')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
            self.wview('csv', entity.related('owned_by'), 'null')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
            self.w(u'</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        # else we don't know if this is because entity has no owner or becayse
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        # user as no access to owner users entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
class ErrorView(AnyRsetView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
    """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
    99
    __select__ = yes()
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
   100
    __regid__ = 'error'
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   101
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    def page_title(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        """returns a title according to the result set - used for the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        title in the HTML header
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
        """
6109
47d9c0e0f7b7 integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5973
diff changeset
   106
        return self._cw._('an error occurred')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
10390
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   108
    def _excinfo(self):
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   109
        req = self._cw
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   110
        ex = req.data.get('ex')
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   111
        excinfo = req.data.get('excinfo')
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   112
        if 'errmsg' in req.data:
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   113
            errmsg = req.data['errmsg']
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   114
            exclass = None
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   115
        else:
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   116
            errmsg = exc_message(ex, req.encoding)
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   117
            exclass = ex.__class__.__name__
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   118
        return errmsg, exclass, excinfo
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   119
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   121
        req = self._cw.reset_headers()
1388
6d5f0ccf31b8 new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents: 836
diff changeset
   122
        w = self.w
6109
47d9c0e0f7b7 integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5973
diff changeset
   123
        title = self._cw._('an error occurred')
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   124
        w(u'<h2>%s</h2>' % title)
10390
0bbd211cf4d7 [views] implement a custom json error view
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9034
diff changeset
   125
        ex, exclass, excinfo = self._excinfo()
3733
c3feb6a33f58 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3451
diff changeset
   126
        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
   127
            if exclass is None:
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   128
                w(u'<div class="tb">%s</div>'
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
   129
                       % 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
   130
            else:
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   131
                w(u'<div class="tb">%s: %s</div>'
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
   132
                       % (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
   133
            w(u'<hr />')
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   134
            w(u'<div class="tb">%s</div>' % html_traceback(excinfo, ex, ''))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        else:
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
   136
            w(u'<div class="tb">%s</div>' % (xml_escape(ex).replace("\n","<br />")))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
        # if excinfo is not None, it's probably not a bug
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
        if excinfo is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
            return
10922
7d01c8c675a0 [web] Stop using webconfig.vc_config()
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
   140
        vcconf = self._cw.cnx.repo.get_versions()
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   141
        w(u"<div>")
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   142
        eversion = vcconf.get('cubicweb', self._cw._('no version information'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
        # 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
   144
        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
   145
        cversions = []
3733
c3feb6a33f58 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3451
diff changeset
   146
        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
   147
            cubeversion = vcconf.get(cube, self._cw._('no version information'))
5435
cc7d00a1b36e [management] fix vocab: use cube instead of package
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
   148
            w(u"<b>Cube %s version:</b> %s<br/>\n" % (cube, cubeversion))
1388
6d5f0ccf31b8 new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents: 836
diff changeset
   149
            cversions.append((cube, cubeversion))
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   150
        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
   151
        # 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
   152
        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
   153
            form = self._cw.vreg['forms'].select('base', self._cw, rset=None,
5358
d4d294610ee7 [forms] no crash if restore_previous_post has not be called, has in report bug form in management.py for instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5234
diff changeset
   154
                                                 mainform=False)
1388
6d5f0ccf31b8 new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents: 836
diff changeset
   155
            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
   156
            form.add_hidden('description', binfo,
119a374c5eb4 form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4045
diff changeset
   157
                            # 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
   158
                            widget=wdgs.TextArea({'class': 'hidden'}))
8605
797fc2e2fb78 [web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents: 8604
diff changeset
   159
            # add a signature so one can't send arbitrary text
797fc2e2fb78 [web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents: 8604
diff changeset
   160
            form.add_hidden('__signature', req.vreg.config.sign_text(binfo))
4164
119a374c5eb4 form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4045
diff changeset
   161
            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
   162
            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
   163
            form.action = req.build_url('reportbug')
6453
7fdd780d87e4 [form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6109
diff changeset
   164
            form.render(w=w)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
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
   168
    binfo = rest_traceback(excinfo, xml_escape(ex))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
    binfo += u'\n\n:URL: %s\n' % req.url()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
    if not '__bugreporting' in req.form:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
        binfo += u'\n:form params:\n'
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10411
diff changeset
   172
        binfo += u'\n'.join(u'  * %s = %s' % (k, v) for k, v in req.form.items())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    binfo += u'\n\n:CubicWeb version: %s\n'  % (eversion,)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
    for pkg, pkgversion in cubes:
5435
cc7d00a1b36e [management] fix vocab: use cube instead of package
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
   175
        binfo += u":Cube %s version: %s\n" % (pkg, pkgversion)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
    binfo += '\n'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
    return binfo
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
1877
10b9feeb7905 anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1806
diff changeset
   179
4706
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   180
class CwStats(View):
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   181
    """A textual stats output for monitoring tools such as munin """
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   182
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   183
    __regid__ = 'processinfo'
8604
7bacc4f21edc [web/views] bugfix: the mime type is text/plain, not text/txt (closes #2526345)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8190
diff changeset
   184
    content_type = 'text/plain'
4706
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   185
    templatable = False
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   186
    __select__ = none_rset() & match_user_groups('users', 'managers')
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   187
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   188
    def call(self):
9034
cc3442054e48 [repo] move repo stats to Service (closes #2951067)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8666
diff changeset
   189
        stats = self._cw.call_service('repo_stats')
10309
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9034
diff changeset
   190
        stats['looping_tasks'] = ', '.join('%s (%s seconds)' % (n, i) for n, i in stats['looping_tasks'])
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9034
diff changeset
   191
        stats['threads'] = ', '.join(sorted(stats['threads']))
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9034
diff changeset
   192
        for k in stats:
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9034
diff changeset
   193
            if k in ('extid_cache_size', 'type_source_cache_size'):
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9034
diff changeset
   194
                continue
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9034
diff changeset
   195
            if k.endswith('_cache_size'):
35bf741203d6 [services] Prevent 'repo_stats' service from aggregating information
David Douard <david.douard@logilab.fr>
parents: 9034
diff changeset
   196
                stats[k] = '%s / %s' % (stats[k]['size'], stats[k]['maxsize'])
4706
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   197
        results = []
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   198
        for element in stats:
4713
785299dfc2c0 [i18n] nothing to translate here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4706
diff changeset
   199
            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
   200
        self.w(u'\n'.join(results))