require_group/match_user_group -> match_user_groups tls-sprint
authorsylvain.thenault@logilab.fr
Mon, 16 Feb 2009 20:06:18 +0100
branchtls-sprint
changeset 635 305da8d6aa2d
parent 634 0badd061ce0f
child 640 8e64f12be69c
require_group/match_user_group -> match_user_groups
common/view.py
goa/appobjects/dbmgmt.py
goa/appobjects/sessions.py
web/controller.py
web/test/unittest_viewselector.py
web/views/basecontrollers.py
web/views/boxes.py
web/views/debug.py
web/views/management.py
web/views/massmailing.py
--- a/common/view.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/common/view.py	Mon Feb 16 20:06:18 2009 +0100
@@ -13,36 +13,16 @@
 from logilab.mtconverter import html_escape
 
 from cubicweb import NotAnEntity, NoSelectableObject
+from cubicweb.selectors import (yes, match_user_groups, implements,
+                                nonempty_rset, none_rset)
+from cubicweb.selectors import require_group_compat, accepts_compat
 from cubicweb.common.registerers import accepts_registerer, priority_registerer
-from cubicweb.common.selectors import (yes, match_user_groups, implements,
-                                       nonempty_rset, none_rset)
 from cubicweb.common.appobject import AppRsetObject, ComponentMixIn
 from cubicweb.common.utils import UStringIO, HTMLStream
 
 _ = unicode
 
 
-def require_group_compat(registered):
-    def plug_selector(cls, vreg):
-        cls = registered(cls, vreg)
-        if getattr(cls, 'require_groups', None):
-            warn('use "use match_user_groups(group1, group2)" instead of using require_groups',
-                 DeprecationWarning)
-            cls.__selectors__ += (match_user_groups(cls.require_groups),)
-        return cls
-    return classmethod(plug_selector)
-
-def accepts_compat(registered):
-    def plug_selector(cls, vreg):
-        cls = registered(cls, vreg)
-        if getattr(cls, 'accepts', None):
-            warn('use "use match_user_groups(group1, group2)" instead of using require_groups',
-                 DeprecationWarning)
-            cls.__selectors__ += (implements(*cls.accepts),)
-        return cls
-    return classmethod(plug_selector)
-
-
 # robots control
 NOINDEX = u'<meta name="ROBOTS" content="NOINDEX" />'
 NOFOLLOW = u'<meta name="ROBOTS" content="NOFOLLOW" />'
--- a/goa/appobjects/dbmgmt.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/goa/appobjects/dbmgmt.py	Mon Feb 16 20:06:18 2009 +0100
@@ -2,7 +2,7 @@
 restoration).
 
 :organization: Logilab
-:copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 __docformat__ = "restructuredtext en"
@@ -13,6 +13,7 @@
 from logilab.common.decorators import cached
 from logilab.mtconverter import html_escape
 
+from cubicweb.common.selectors import none_rset, match_user_groups
 from cubicweb.common.view import StartupView
 from cubicweb.web import Redirect
 from cubicweb.goa.dbinit import fix_entities, init_persistent_schema, insert_versions
@@ -39,7 +40,7 @@
     which are doing datastore administration requests
     """
     id = 'authinfo'
-    require_groups = ('managers',)
+    __selectors__ = (none_rset, match_user_groups('managers'),)
 
     def call(self):
         cookie = self.req.get_cookie()
@@ -61,7 +62,7 @@
     step by step to avoid depassing quotas
     """
     id = 'contentinit'
-    require_groups = ('managers',)
+    __selectors__ = (none_rset, match_user_groups('managers'),)
 
     def server_session(self):
         ssession = self.config.repo_session(self.req.cnx.sessionid)
@@ -166,7 +167,7 @@
         
 class ContentClear(StartupView):
     id = 'contentclear'
-    require_groups = ('managers',)
+    __selectors__ = (none_rset, match_user_groups('managers'),)
     skip_etypes = ('EGroup', 'EUser')
     
     def call(self):
--- a/goa/appobjects/sessions.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/goa/appobjects/sessions.py	Mon Feb 16 20:06:18 2009 +0100
@@ -1,7 +1,7 @@
 """persistent sessions stored in big table
 
 :organization: Logilab
-:copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 
 XXX TODO:
@@ -18,6 +18,7 @@
 from cubicweb import UnknownEid, BadConnectionId
 from cubicweb.dbapi import Connection, ConnectionProperties, repo_connect
 from cubicweb.server.session import Session
+from cubicweb.common.selectors import none_rset, match_user_groups
 from cubicweb.web import InvalidSession
 from cubicweb.web.application import AbstractSessionManager
 from cubicweb.web.application import AbstractAuthenticationManager
@@ -254,7 +255,7 @@
 
 class SessionsCleaner(StartupView):
     id = 'cleansessions'
-    require_groups = ('managers',)
+    __selectors__ = (none_rset, match_user_groups('managers'),)
     
     def call(self):
         # clean web session
--- a/web/controller.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/web/controller.py	Mon Feb 16 20:06:18 2009 +0100
@@ -2,7 +2,7 @@
 
 
 :organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 __docformat__ = "restructuredtext en"
@@ -11,7 +11,7 @@
 
 from cubicweb import typed_eid
 from cubicweb.common.registerers import priority_registerer
-from cubicweb.common.selectors import match_user_group
+from cubicweb.common.selectors import yes, require_group_compat
 from cubicweb.common.appobject import AppObject
 from cubicweb.web import LOGGER, Redirect, RequestError
 
@@ -68,8 +68,8 @@
     """
     __registry__ = 'controllers'
     __registerer__ = priority_registerer
-    __selectors__ = (match_user_group,)
-    require_groups = ()
+    __selectors__ = (yes,)
+    registered = require_group_compat(AppObject.registered.im_func)
 
     def __init__(self, *args, **kwargs):
         super(Controller, self).__init__(*args, **kwargs)
--- a/web/test/unittest_viewselector.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/web/test/unittest_viewselector.py	Mon Feb 16 20:06:18 2009 +0100
@@ -9,7 +9,7 @@
 
 
 from cubicweb import CW_SOFTWARE_ROOT as BASE, Binary
-from cubicweb.common.selectors import match_user_group
+from cubicweb.common.selectors import match_user_groups
 
 from cubicweb.web._exceptions import NoSelectableObject
 from cubicweb.web.action import Action
@@ -411,8 +411,7 @@
         class SomeAction(Action):
             id = 'yo'
             category = 'foo'
-            __selectors__ = (match_user_group,)
-            require_groups = ('owners', )            
+            __selectors__ = (match_user_groups('owners'),)
         self.vreg.register_vobject_class(SomeAction)
         self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions'])
         try:
--- a/web/views/basecontrollers.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/web/views/basecontrollers.py	Mon Feb 16 20:06:18 2009 +0100
@@ -18,10 +18,10 @@
 from logilab.common.decorators import cached
 
 from cubicweb import NoSelectableObject, ValidationError, typed_eid
+from cubicweb.selectors import match_user_groups
 from cubicweb.common.selectors import yes
 from cubicweb.common.mail import format_mail
 from cubicweb.common.view import STRICT_DOCTYPE, CW_XHTML_EXTENSIONS
-
 from cubicweb.web import ExplicitLogin, Redirect, RemoteCallFailed
 from cubicweb.web.controller import Controller
 from cubicweb.web.views import vid_from_rset
@@ -462,7 +462,7 @@
 
 class SendMailController(Controller):
     id = 'sendmail'
-    require_groups = ('managers', 'users')
+    __selectors__ = (match_user_groups('managers', 'users'),)
 
     def recipients(self):
         """returns an iterator on email's recipients as entities"""
--- a/web/views/boxes.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/web/views/boxes.py	Mon Feb 16 20:06:18 2009 +0100
@@ -17,7 +17,7 @@
 
 from logilab.mtconverter import html_escape
 
-from cubicweb.common.selectors import any_rset, appobject_selectable
+from cubicweb.selectors import any_rset, appobject_selectable, match_user_groups
 from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, BoxHtml, RawBoxItem
 from cubicweb.web.box import BoxTemplate, ExtResourcesBoxTemplate
 
@@ -167,10 +167,10 @@
 class PossibleViewsBox(BoxTemplate):
     """display a box containing links to all possible views"""
     id = 'possible_views_box'
+    __selectors__ = (match_user_groups('users', 'managers'),)
     
     title = _('possible views')
     order = 10
-    require_groups = ('users', 'managers')
     visible = False
 
     def call(self, **kwargs):
--- a/web/views/debug.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/web/views/debug.py	Mon Feb 16 20:06:18 2009 +0100
@@ -2,7 +2,7 @@
 
 
 :organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 __docformat__ = "restructuredtext en"
@@ -11,6 +11,7 @@
 
 from logilab.mtconverter import html_escape
 
+from cubicweb.selectors import none_rset, match_user_groups
 from cubicweb.common.view import StartupView
 
 def dict_to_html(w, dict):
@@ -21,11 +22,12 @@
             w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % (
                 html_escape(str(key)), html_escape(repr(dict[key]))))
         w(u'</ul>')
+
     
 class DebugView(StartupView):
     id = 'debug'
+    __selectors__ = (none_rset, match_user_groups('managers'),)
     title = _('server debug information')
-    require_groups = ('managers',)
 
     def call(self, **kwargs):
         """display server information"""
--- a/web/views/management.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/web/views/management.py	Mon Feb 16 20:06:18 2009 +0100
@@ -2,7 +2,7 @@
 
 
 :organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 """
 __docformat__ = "restructuredtext en"
@@ -11,12 +11,11 @@
 
 from logilab.common.decorators import cached
 
+from cubicweb.selectors import (yes, one_line_rset, none_rset,
+                                match_user_groups, chainfirst, chainall)
 from cubicweb.common.utils import UStringIO
 from cubicweb.common.view import AnyRsetView, StartupView, EntityView
 from cubicweb.common.uilib import html_traceback, rest_traceback
-from cubicweb.common.selectors import (yes, one_line_rset, match_user_groups,
-                                       accept_rset, none_rset,
-                                       chainfirst, chainall)
 from cubicweb.web import INTERNAL_FIELD_VALUE, eid_param, stdmsgs
 from cubicweb.web.widgets import StaticComboBoxWidget
 from cubicweb.web.form import FormMixIn
@@ -294,10 +293,11 @@
     return someclass and 'class="%s"' % someclass or ''
 
 class SystemEPropertiesForm(FormMixIn, StartupView):
+    id = 'systemepropertiesform'
+    __selectors__ = (none_rset, match_user_groups('managers'),)
+
+    title = _('site configuration')
     controller = 'edit'
-    id = 'systemepropertiesform'
-    title = _('site configuration')
-    require_groups = ('managers',)
     category = 'startupview'
 
     def linkable(self):
@@ -507,8 +507,9 @@
 
 class ProcessInformationView(StartupView):
     id = 'info'
+    __selectors__ = (none_rset, match_user_groups('managers'),)
+    
     title = _('server information')
-    require_groups = ('managers',)
 
     def call(self, **kwargs):
         """display server information"""
--- a/web/views/massmailing.py	Mon Feb 16 20:05:55 2009 +0100
+++ b/web/views/massmailing.py	Mon Feb 16 20:06:18 2009 +0100
@@ -10,17 +10,16 @@
 from logilab.mtconverter import html_escape
 
 from cubicweb.interfaces import IEmailable
+from cubicweb.selectors import implements, match_user_groups
 from cubicweb.common.view import EntityView
-from cubicweb.common.selectors import implement_interface, match_user_group
 from cubicweb.web.action import EntityAction
 from cubicweb.web import stdmsgs
 
 
 class SendEmailAction(EntityAction):
     category = 'mainactions'
-    __selectors__ = (implement_interface, match_user_group)
-    accepts_interfaces = (IEmailable,) # XXX should check email is set as well
-    require_groups = ('managers', 'users')
+    # XXX should check email is set as well
+    __selectors__ = (implements(IEmailable), match_user_groups('managers', 'users'))
 
     id = 'sendemail'
     title = _('send email')
@@ -35,10 +34,7 @@
 
 class MassMailingForm(EntityView):
     id = 'massmailing'
-    __selectors__ = (implement_interface, match_user_group)
-    accepts_interfaces = (IEmailable,)
-    require_groups = ('managers', 'users')
-    
+    __selectors__ = (implements(IEmailable), match_user_groups('managers', 'users'))
 
     form_template = u"""
 <div id="compose">