web/views/cwuser.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 27 Feb 2012 17:02:31 +0100
changeset 8298 2a4bc6f75e9c
parent 8190 2a3c1b787688
child 8665 e65af61bde7d
permissions -rw-r--r--
[twisted] move out url logic from twisted (closes #2200593) Data, fck and static file are now served by cubicweb controller by default. Some hackish url rewriting is necessary to have them selected. This is necessary because cubicweb does not selection controller on multi level path. - 'Expires' header seems to conflict with Cache-Control set by HTTPCacheManger (don't know yet why HTTPCacheManager is involved here) mod_wsgi is now usable in simple cases (e.g. still requires persisten sessions).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6950
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
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: 4719
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5423
e15abfdcce38 backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5239 5421
diff changeset
    18
"""Specific views for users and groups"""
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"
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6339
diff changeset
    21
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    23
from hashlib import sha1 # pylint: disable=E0611
6325
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    24
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    25
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
7327
72bb52edbb6b [user mgmt] should show user login in first column in any case (e.g. application specific override)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7291
diff changeset
    27
from cubicweb import tags
6950
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
    28
from cubicweb.schema import display_name
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8083
diff changeset
    29
from cubicweb.predicates import one_line_rset, is_instance, match_user_groups
6950
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
    30
from cubicweb.view import EntityView, StartupView
6891
e409a012c505 [user form] use InOutWidget to edit CWUser in_group relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    31
from cubicweb.web import action, uicfg, formwidgets
7806
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
    32
from cubicweb.web.views import tabs, tableview, actions, add_etype_button
557
8bb60606e5ad small fix
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 556
diff changeset
    33
4719
aaed3f813ef8 kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    34
_pvs = uicfg.primaryview_section
aaed3f813ef8 kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    35
_pvs.tag_attribute(('CWUser', 'login'), 'hidden')
3808
60e78e93a0e5 [web ui] primaryview_section tags for CWGroup
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2971
diff changeset
    36
6891
e409a012c505 [user form] use InOutWidget to edit CWUser in_group relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    37
_affk = uicfg.autoform_field_kwargs
e409a012c505 [user form] use InOutWidget to edit CWUser in_group relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    38
_affk.tag_subject_of(('CWUser', 'in_group', 'CWGroup'),
e409a012c505 [user form] use InOutWidget to edit CWUser in_group relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    39
                    {'widget': formwidgets.InOutWidget})
e409a012c505 [user form] use InOutWidget to edit CWUser in_group relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
    40
1288
0d0f09c36bba fix some euser rcategories, drop editgroup form which 1. is unused 2. has no advantage vs muledit of users
sylvain.thenault@logilab.fr
parents: 1153
diff changeset
    41
class UserPreferencesEntityAction(action.Action):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2971
diff changeset
    42
    __regid__ = 'prefs'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    43
    __select__ = (one_line_rset() & is_instance('CWUser') &
728
a95b284150d1 first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
    44
                  match_user_groups('owners', 'managers'))
1508
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    45
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    46
    title = _('preferences')
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    47
    category = 'mainactions'
1508
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    48
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    49
    def url(self):
7990
a673d1d9a738 [diet] drop pre 3.6 API compatibility (but attempt to keep data cmopatibility). Closes #2017916
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7894
diff changeset
    50
        user = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
a673d1d9a738 [diet] drop pre 3.6 API compatibility (but attempt to keep data cmopatibility). Closes #2017916
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7894
diff changeset
    51
        return user.absolute_url(vid='propertiesform')
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    52
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 619
diff changeset
    53
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    54
class FoafView(EntityView):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2971
diff changeset
    55
    __regid__ = 'foaf'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    56
    __select__ = is_instance('CWUser')
1508
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    57
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    58
    title = _('foaf')
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    59
    templatable = False
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    60
    content_type = 'text/xml'
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    61
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    62
    def call(self):
950
8ac01018f499 require unicode
sylvain.thenault@logilab.fr
parents: 926
diff changeset
    63
        self.w(u'''<?xml version="1.0" encoding="%s"?>
619
9efa2cc9c02c adding foaf_usable views to supports reusing foaf fragment in other views (for instance sioc view)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 586
diff changeset
    64
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
9efa2cc9c02c adding foaf_usable views to supports reusing foaf fragment in other views (for instance sioc view)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 586
diff changeset
    65
         xmlns:rdfs="http://www.w3org/2000/01/rdf-schema#"
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    66
         xmlns:foaf="http://xmlns.com/foaf/0.1/"> '''% self._cw.encoding)
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    67
        for i in xrange(self.cw_rset.rowcount):
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    68
            self.cell_call(i, 0)
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    69
        self.w(u'</rdf:RDF>\n')
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    70
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
    71
    def entity_call(self, entity, **kwargs):
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
    72
        entity.complete()
6325
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    73
        # account
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    74
        self.w(u'<foaf:OnlineAccount rdf:about="%s">\n' % entity.absolute_url())
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    75
        self.w(u'  <foaf:accountName>%s</foaf:accountName>\n' % entity.login)
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    76
        self.w(u'</foaf:OnlineAccount>\n')
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    77
        # person
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    78
        self.w(u'<foaf:Person rdf:about="%s#user">\n' % entity.absolute_url())
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    79
        self.w(u'  <foaf:account rdf:resource="%s" />\n' % entity.absolute_url())
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    80
        if entity.surname:
6325
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    81
            self.w(u'<foaf:familyName>%s</foaf:familyName>\n'
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    82
                   % xml_escape(entity.surname))
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    83
        if entity.firstname:
6325
38cfda1ab60f [views] fix foaf view for CWUser
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5877
diff changeset
    84
            self.w(u'<foaf:givenName>%s</foaf:givenName>\n'
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    85
                   % xml_escape(entity.firstname))
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    86
        emailaddr = entity.cw_adapt_to('IEmailable').get_email()
523
f01cfce2e8d2 foaf euser view
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    87
        if emailaddr:
6339
bdc3dc94d744 [foaf] we should encode email addr: even if we know it should be ascii, nothing prevent from putting something else in (tests at least do it)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6325
diff changeset
    88
            self.w(u'<foaf:mbox_sha1sum>%s</foaf:mbox_sha1sum>\n'
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    89
                   % sha1(emailaddr.encode('utf-8')).hexdigest())
586
09ec2839e447 small fix
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 568
diff changeset
    90
        self.w(u'</foaf:Person>\n')
5224
34e669b6fd95 [mq]: worklfow view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    91
5235
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
    92
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
    93
# group views ##################################################################
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
    94
7333
0deded0dc5da [cwgroup views] uicfg rules cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7327
diff changeset
    95
_pvs.tag_attribute(('CWGroup', 'name'), 'hidden')
0deded0dc5da [cwgroup views] uicfg rules cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7327
diff changeset
    96
_pvs.tag_subject_of(('CWGroup', 'read_permission', '*'), 'relations')
0deded0dc5da [cwgroup views] uicfg rules cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7327
diff changeset
    97
_pvs.tag_subject_of(('CWGroup', 'add_permission', '*'), 'relations')
0deded0dc5da [cwgroup views] uicfg rules cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7327
diff changeset
    98
_pvs.tag_subject_of(('CWGroup', 'delete_permission', '*'), 'relations')
0deded0dc5da [cwgroup views] uicfg rules cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7327
diff changeset
    99
_pvs.tag_subject_of(('CWGroup', 'update_permission', '*'), 'relations')
5235
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   100
_pvs.tag_object_of(('CWUser', 'in_group', 'CWGroup'), 'hidden')
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   101
_pvs.tag_object_of(('*', 'require_group', 'CWGroup'), 'hidden')
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   102
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   103
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   104
class CWGroupPrimaryView(tabs.TabbedPrimaryView):
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   105
    __select__ = is_instance('CWGroup')
5235
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   106
    tabs = [_('cwgroup-main'), _('cwgroup-permissions')]
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   107
    default_tab = 'cwgroup-main'
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   108
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   109
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   110
class CWGroupMainTab(tabs.PrimaryTab):
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   111
    __regid__ = 'cwgroup-main'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   112
    __select__ = tabs.PrimaryTab.__select__ & is_instance('CWGroup')
5235
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   113
5239
471554b842d2 [schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5237
diff changeset
   114
    def render_entity_attributes(self, entity):
7993
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   115
        rset = self._cw.execute(
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   116
            'Any U, FN, LN, CD, LL ORDERBY L WHERE U in_group G, '
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   117
            'U login L, U firstname FN, U surname LN, U creation_date CD, '
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   118
            'U last_login_time LL, G eid %(x)s', {'x': entity.eid})
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   119
        self.wview('cwgroup.users', rset, 'null')
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   120
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   121
class CWGroupUsersTable(tableview.RsetTableView):
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   122
    __regid__ = 'cwgroup.users'
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   123
    __select__ = is_instance('CWUser')
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   124
    headers = (_(u'user'), _(u'first name'), _(u'last name'),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   125
               _(u'creation date'), _(u'last login time'))
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   126
    layout_args = {'display_filter': 'top'}
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   127
    finalvid = 'editable-final'
5235
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   128
7802
d0bf71aff4a1 [web test] fix test broken by new users/groups management views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7800
diff changeset
   129
5235
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   130
class CWGroupPermTab(EntityView):
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   131
    __regid__ = 'cwgroup-permissions'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   132
    __select__ = is_instance('CWGroup')
5235
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   133
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   134
    def entity_call(self, entity):
5235
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   135
        self._cw.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   136
        access_types = ('read', 'delete', 'add', 'update')
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   137
        w = self.w
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   138
        objtype_access = {'CWEType': ('read', 'delete', 'add', 'update'),
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   139
                          'CWRelation': ('add', 'delete')}
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   140
        rql_cwetype = 'DISTINCT Any X WHERE X %s_permission CWG, X is CWEType, ' \
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   141
                      'CWG eid %%(e)s'
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   142
        rql_cwrelation = 'DISTINCT Any RT WHERE X %s_permission CWG, X is CWRelation, ' \
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   143
                         'X relation_type RT, CWG eid %%(e)s'
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   144
        self.render_objtype_access(entity, 'CWEType', objtype_access, rql_cwetype)
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   145
        self.render_objtype_access(entity, 'CWRelation', objtype_access, rql_cwrelation)
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   146
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   147
    def render_objtype_access(self, entity, objtype, objtype_access, rql):
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   148
        self.w(u'<h4>%s</h4>' % self._cw._(objtype))
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   149
        for access_type in objtype_access[objtype]:
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   150
            rset = self._cw.execute(rql % access_type, {'e': entity.eid})
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   151
            if rset:
5237
10dd0dd78778 [schema view] fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5236
diff changeset
   152
                self.w(u'<div>%s:</div>' % self._cw.__(access_type + '_permission'))
10dd0dd78778 [schema view] fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5236
diff changeset
   153
                self.w(u'<div>%s</div><br/>' % self._cw.view('csv', rset, 'null'))
5235
3a92e6d92a64 ticket #344404, cwgroup primary view improvement, use tabs to display nicely permissions
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5234
diff changeset
   154
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   155
5224
34e669b6fd95 [mq]: worklfow view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
   156
class CWGroupInContextView(EntityView):
34e669b6fd95 [mq]: worklfow view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
   157
    __regid__ = 'incontext'
5877
0c7b7b76a84f [selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   158
    __select__ = is_instance('CWGroup')
5234
e2476d78b060 ticket #787103, relation schema view enhancements
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 5224
diff changeset
   159
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   160
    def entity_call(self, entity, **kwargs):
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   161
        entity.complete()
5224
34e669b6fd95 [mq]: worklfow view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
   162
        self.w(u'<a href="%s" class="%s">%s</a>' % (
34e669b6fd95 [mq]: worklfow view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
   163
            entity.absolute_url(), entity.name, entity.printable_value('name')))
6950
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   164
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   165
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   166
# user / groups management views ###############################################
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   167
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   168
class ManageUsersAction(actions.ManagersAction):
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   169
    __regid__ = 'cwuser' # see rewrite rule /cwuser
6961
686c59dfc401 [manage view] cleanup manage view and user menu
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6950
diff changeset
   170
    title = _('users and groups')
6950
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   171
    category = 'manage'
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   172
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   173
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   174
class UsersAndGroupsManagementView(tabs.TabsMixin, StartupView):
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   175
    __regid__ = 'cw.users-and-groups-management'
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   176
    __select__ = StartupView.__select__ & match_user_groups('managers')
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   177
    title = _('Users and groups management')
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   178
    tabs = [_('cw.users-management'), _('cw.groups-management'),]
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   179
    default_tab = 'cw.users-management'
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   180
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   181
    def call(self, **kwargs):
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   182
        """The default view representing the instance's management"""
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   183
        self.w(u'<h1>%s</h1>' % self._cw._(self.title))
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   184
        self.render_tabs(self.tabs, self.default_tab)
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   185
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   186
6950
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   187
class CWUserManagementView(StartupView):
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   188
    __regid__ = 'cw.users-management'
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   189
    __select__ = StartupView.__select__ & match_user_groups('managers')
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   190
    cache_max_age = 0 # disable caching
7737
db6d296cc66f [web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7334
diff changeset
   191
    # XXX one could wish to display for instance only user's firstname/surname
db6d296cc66f [web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7334
diff changeset
   192
    # for non managers but filtering out NULL cause crash with an ldapuser
db6d296cc66f [web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7334
diff changeset
   193
    # source.
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   194
    rql = ('Any U,US,F,S,U,UAA,UDS, L,UAA,USN,UDSN ORDERBY L WHERE U is CWUser, '
7289
f91e8e25510c [users management] enhance users table: show state, primary email and data source; show filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6961
diff changeset
   195
           'U login L, U firstname F, U surname S, '
f91e8e25510c [users management] enhance users table: show state, primary email and data source; show filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6961
diff changeset
   196
           'U in_state US, US name USN, '
f91e8e25510c [users management] enhance users table: show state, primary email and data source; show filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6961
diff changeset
   197
           'U primary_email UA?, UA address UAA, '
f91e8e25510c [users management] enhance users table: show state, primary email and data source; show filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6961
diff changeset
   198
           'U cw_source UDS, US name UDSN')
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   199
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   200
    def call(self, **kwargs):
7993
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   201
        self.w(add_etype_button(self._cw, 'CWUser'))
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   202
        self.w(u'<div class="clear"></div>')
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   203
        self.wview('cw.users-table', self._cw.execute(self.rql))
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   204
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   205
7993
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   206
class CWUsersTable(tableview.EntityTableView):
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   207
    __regid__ = 'cw.users-table'
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   208
    __select__ = is_instance('CWUser')
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   209
    columns = ['user', 'in_state', 'firstname', 'surname',
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   210
               'in_group', 'primary_email', 'cw_source']
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   211
    layout_args = {'display_filter': 'top'}
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   212
    finalvid = 'editable-final'
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   213
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   214
    column_renderers = {
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   215
        'user': tableview.EntityTableColRenderer(
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   216
            renderfunc=lambda w,x: w(tags.a(x.login, href=x.absolute_url())),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   217
            sortfunc=lambda x: x.login),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   218
        'in_state': tableview.EntityTableColRenderer(
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   219
            renderfunc=lambda w,x: w(x.cw_adapt_to('IWorkflowable').printable_state),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   220
            sortfunc=lambda x: x.cw_adapt_to('IWorkflowable').printable_state),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   221
        'in_group': tableview.EntityTableColRenderer(
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   222
            renderfunc=lambda w,x: x.view('reledit', rtype='in_group', role='subject', w=w)),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   223
        'primary_email': tableview.RelatedEntityColRenderer(
8083
3db2f3317d15 [users management view] return None if no entity related, not an empty tuple. Closes #2089085
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7993
diff changeset
   224
            getrelated=lambda x:x.primary_email and x.primary_email[0] or None),
7993
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   225
        'cw_source': tableview.RelatedEntityColRenderer(
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   226
            getrelated=lambda x: x.cw_source[0]),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   227
        }
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   228
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   229
7800
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   230
class CWGroupsManagementView(StartupView):
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   231
    __regid__ = 'cw.groups-management'
ea496a3ed703 [user management] users and groups management now really lead to that (closes #1931478)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7777
diff changeset
   232
    __select__ = StartupView.__select__ & match_user_groups('managers')
7777
2764987eb17a [user management] disable http cache on user management view (not really a startup view)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7740
diff changeset
   233
    cache_max_age = 0 # disable caching
7993
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   234
    rql = ('Any G,GN ORDERBY GN WHERE G is CWGroup, G name GN, NOT G name "owners"')
6950
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   235
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   236
    def call(self, **kwargs):
7993
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   237
        self.w(add_etype_button(self._cw, 'CWGroup'))
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   238
        self.w(u'<div class="clear"></div>')
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   239
        self.wview('cw.groups-table', self._cw.execute(self.rql))
6950
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   240
8a17e6e34f0f [admin ui] nicer views for users/groups management
Charles Hébert <charles.hebert@logilab.fr>
parents: 6891
diff changeset
   241
7993
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   242
class CWGroupsTable(tableview.EntityTableView):
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   243
    __regid__ = 'cw.groups-table'
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   244
    __select__ = is_instance('CWGroup')
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   245
    columns = ['group', 'nb_users']
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   246
    layout_args = {'display_filter': 'top'}
7327
72bb52edbb6b [user mgmt] should show user login in first column in any case (e.g. application specific override)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7291
diff changeset
   247
7993
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   248
    column_renderers = {
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   249
        'group': tableview.MainEntityColRenderer(),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   250
        'nb_users': tableview.EntityTableColRenderer(
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   251
            header=_('num. users'),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   252
            renderfunc=lambda w,x: w(unicode(x.num_users())),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   253
            sortfunc=lambda x: x.num_users()),
aa0addce4dae [management table] fix and upgrade users and groups management tables to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   254
        }