web/views/management.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 21 Jun 2010 15:29:10 +0200
branchstable
changeset 5812 d970049d7cfd
parent 5528 5d1b2ae7d459
child 5545 25fd74c23f91
permissions -rw-r--r--
[dbapi] Connection.load_appobjects should load site_cubicweb files as well, they may contains necessary RQL extension function definitions. Also kill some broken deprecated code in this method.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
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"
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1569 1618
diff changeset
    21
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
    23
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
1877
10b9feeb7905 anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1806
diff changeset
    25
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
    26
from cubicweb.view import AnyRsetView, StartupView, EntityView, View
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3998
diff changeset
    27
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
    28
from cubicweb.web import formwidgets as wdgs
1402
04b7afb14b50 new style security management forms
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    29
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
    30
from cubicweb.web.views.schema import SecurityViewMixIn
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
5232
78c1a531f7b3 ticket #787032, schema view improvement
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4714
diff changeset
    32
from yams.buildobjs import EntityType
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
1388
6d5f0ccf31b8 new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents: 836
diff changeset
    34
SUBMIT_MSGID = _('Submit bug report')
6d5f0ccf31b8 new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents: 836
diff changeset
    35
MAIL_SUBMIT_MSGID = _('Submit bug report by mail')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5232
diff changeset
    37
class SecurityManagementView(SecurityViewMixIn, EntityView):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
    """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
    39
    __regid__ = 'security'
1877
10b9feeb7905 anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1806
diff changeset
    40
    __select__ = EntityView.__select__ & authenticated_user()
10b9feeb7905 anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1806
diff changeset
    41
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    title = _('security')
1941
4f38e8b81a1a egroup -> cwgroup #343418
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1877
diff changeset
    43
1569
99a19875ef1e set progress div in call() to avoid duplication when applied on multiple entities
sylvain.thenault@logilab.fr
parents: 1568
diff changeset
    44
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    45
        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
    46
        super(SecurityManagementView, self).call()
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
    47
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
    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
    49
        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
    50
        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
    51
        entity = self.cw_rset.get_entity(row, col)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
        w = self.w
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    53
        _ = self._cw._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        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
    55
          % (entity.dc_type().capitalize(),
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
    56
             xml_escape(entity.absolute_url()),
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
    57
             xml_escape(entity.dc_title())))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
        # first show permissions defined by the schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
        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
    60
        self.permissions_table(entity.e_schema)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
        self.w('<h2>%s</h2>' % _('manage security'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        # ownership information
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4023
diff changeset
    63
        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
    64
                                                    fromeid=entity.eid):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
            self.owned_by_edit_form(entity)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
            self.owned_by_information(entity)
1518
8f4d2892e809 eperm -> cwperm
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
    68
        # cwpermissions
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        if 'require_permission' in entity.e_schema.subject_relations():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
            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
    71
            reqpermschema = self._cw.vreg.schema.rschema('require_permission')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
            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
    73
            if reqpermschema.has_perm(self._cw, 'add', fromeid=entity.eid):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
                self.require_permission_edit_form(entity)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
    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
    77
        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
    78
        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
    79
        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
    80
                                         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
    81
                                         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
    82
                                         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
    83
                                         __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
    84
                                         __redirectpath=entity.rest_path())
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4023
diff changeset
    85
        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
    86
        form.append_field(field)
4297
5f2081181055 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    87
        self.w(form.render(display_progress_div=False))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
    def owned_by_information(self, entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
        ownersrset = entity.related('owned_by')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
        if ownersrset:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    92
            self.w('<h3>%s</h3>' % self._cw._('ownership'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
            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
    94
            self.w(self._cw._('this entity is currently owned by') + ' ')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
            self.wview('csv', entity.related('owned_by'), 'null')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
            self.w(u'</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
        # 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
    98
        # user as no access to owner users entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
    def require_permission_information(self, entity, reqpermschema):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
        if entity.require_permission:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
            w = self.w
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   103
            _ = self._cw._
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   104
            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
   105
                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
   106
                                            __redirectpath=entity.rest_path())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
                delurl = delurl.replace('%', '%%')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
                # don't give __delete value to build_url else it will be urlquoted
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
                # and this will replace %s by %25s
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
                delurl += '&__delete=%s:require_permission:%%s' % entity.eid
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2670
diff changeset
   111
                dellinktempl = u'[<a href="%s" title="%s">-</a>]&#160;' % (
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
   112
                    xml_escape(delurl), _('delete this permission'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
                dellinktempl = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
            w(u'<table class="schemaInfo">')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
            w(u'<tr><th>%s</th><th>%s</th></tr>' % (_("permission"),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
                                                    _('granted to groups')))
1518
8f4d2892e809 eperm -> cwperm
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   118
            for cwperm in entity.require_permission:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
                w(u'<tr>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
                if dellinktempl:
1518
8f4d2892e809 eperm -> cwperm
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   121
                    w(u'<td>%s%s</td>' % (dellinktempl % cwperm.eid,
8f4d2892e809 eperm -> cwperm
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   122
                                          cwperm.view('oneline')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
                else:
1518
8f4d2892e809 eperm -> cwperm
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   124
                    w(u'<td>%s</td>' % cwperm.view('oneline'))
8f4d2892e809 eperm -> cwperm
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   125
                w(u'<td>%s</td>' % self.view('csv', cwperm.related('require_group'), 'null'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
                w(u'</tr>\n')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
            w(u'</table>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
        else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   129
            self.w(self._cw._('no associated permissions'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
    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
   132
        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
   133
        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
   134
        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
   135
        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
   136
                                         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
   137
                                         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
   138
                                         __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
   139
                                         __redirectpath=entity.rest_path())
4164
119a374c5eb4 form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4045
diff changeset
   140
        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
   141
                        eidparam=True)
1402
04b7afb14b50 new style security management forms
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   142
        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
   143
        cwpermschema = newperm.e_schema
1402
04b7afb14b50 new style security management forms
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   144
        if permnames is not None:
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4023
diff changeset
   145
            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
   146
                                widget=wdgs.Select({'size': 1}),
1531
5fc1e6a15147 set size of select widget
sylvain.thenault@logilab.fr
parents: 1525
diff changeset
   147
                                choices=permnames)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
        else:
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4023
diff changeset
   149
            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
   150
        form.append_field(field)
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4023
diff changeset
   151
        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
   152
        form.append_field(field)
4045
f4a52abb6f4f cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 4023
diff changeset
   153
        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
   154
        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
   155
        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
   156
            '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
   157
        self.w(form.render(renderer=renderer))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
class ErrorView(AnyRsetView):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
    """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
   162
    __select__ = yes()
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
   163
    __regid__ = 'error'
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   164
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
    def page_title(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
        """returns a title according to the result set - used for the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
        title in the HTML header
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        """
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   169
        return self._cw._('an error occured')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   172
        req = self._cw.reset_headers()
1388
6d5f0ccf31b8 new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents: 836
diff changeset
   173
        w = self.w
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
        ex = req.data.get('ex')#_("unable to find exception information"))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
        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
   176
        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
   177
        w(u'<h2>%s</h2>' % title)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
        if 'errmsg' in req.data:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
            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
   180
            exclass = None
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
        else:
174
a2966960d550 get actual exception class instead of 'unicode' in the error view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 0
diff changeset
   182
            exclass = ex.__class__.__name__
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
            ex = exc_message(ex, req.encoding)
3733
c3feb6a33f58 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3451
diff changeset
   184
        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
   185
            if exclass is None:
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   186
                w(u'<div class="tb">%s</div>'
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
   187
                       % 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
   188
            else:
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   189
                w(u'<div class="tb">%s: %s</div>'
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
   190
                       % (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
   191
            w(u'<hr />')
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   192
            w(u'<div class="tb">%s</div>' % html_traceback(excinfo, ex, ''))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
        else:
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2270
diff changeset
   194
            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
   195
        # if excinfo is not None, it's probably not a bug
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
        if excinfo is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
            return
3733
c3feb6a33f58 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3451
diff changeset
   198
        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
   199
        w(u"<div>")
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   200
        eversion = vcconf.get('cubicweb', self._cw._('no version information'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
        # 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
   202
        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
   203
        cversions = []
3733
c3feb6a33f58 remove some warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3451
diff changeset
   204
        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
   205
            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
   206
            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
   207
            cversions.append((cube, cubeversion))
602
1454282a8b45 [views] cleanup, be less heavy with self.w ...
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 431
diff changeset
   208
        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
   209
        # 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
   210
        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
   211
            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
   212
                                                 mainform=False)
1388
6d5f0ccf31b8 new style form for submitting bug reports
sylvain.thenault@logilab.fr
parents: 836
diff changeset
   213
            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
   214
            form.add_hidden('description', binfo,
119a374c5eb4 form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4045
diff changeset
   215
                            # 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
   216
                            widget=wdgs.TextArea({'class': 'hidden'}))
119a374c5eb4 form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4045
diff changeset
   217
            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
   218
            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
   219
            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
   220
            w(form.render())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
def exc_message(ex, encoding):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
        return unicode(ex)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
    except:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   228
            return unicode(str(ex), encoding, 'replace')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
        except:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
            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
   231
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
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
   233
    binfo = rest_traceback(excinfo, xml_escape(ex))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
    binfo += u'\n\n:URL: %s\n' % req.url()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
    if not '__bugreporting' in req.form:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
        binfo += u'\n:form params:\n'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
        binfo += u'\n'.join(u'  * %s = %s' % (k, v) for k, v in req.form.iteritems())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
    binfo += u'\n\n:CubicWeb version: %s\n'  % (eversion,)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
    for pkg, pkgversion in cubes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
        binfo += u":Package %s version: %s\n" % (pkg, pkgversion)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
    binfo += '\n'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
    return binfo
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
1877
10b9feeb7905 anon should not see security management view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1806
diff changeset
   244
4706
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   245
class CwStats(View):
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   246
    """A textual stats output for monitoring tools such as munin """
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   247
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   248
    __regid__ = 'processinfo'
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   249
    content_type = 'text/txt'
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   250
    templatable = False
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   251
    __select__ = none_rset() & match_user_groups('users', 'managers')
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   252
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   253
    def call(self):
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   254
        stats = self._cw.vreg.config.repository(None).stats()
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   255
        results = []
6035e96b64dd added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents: 4297
diff changeset
   256
        for element in stats:
4713
785299dfc2c0 [i18n] nothing to translate here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4706
diff changeset
   257
            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
   258
        self.w(u'\n'.join(results))