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