[views] epropertiesform renamed propertiesform stable
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Tue, 21 Jul 2009 12:56:29 +0200
branchstable
changeset 2401 890f6b990dd7
parent 2398 a8d18e320ef3
child 2403 74f7fa676a52
child 2404 2d3c1a3f76c5
[views] epropertiesform renamed propertiesform
web/test/unittest_viewselector.py
web/views/cwproperties.py
web/views/cwuser.py
--- a/web/test/unittest_viewselector.py	Tue Jul 21 12:38:10 2009 +0200
+++ b/web/test/unittest_viewselector.py	Tue Jul 21 12:56:29 2009 +0200
@@ -1,7 +1,9 @@
-# -*- coding: iso-8859-1 -*-
+# -*- coding: utf-8 -*-
 """XXX rename, split, reorganize this
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+from __future__ import with_statement
+
 from logilab.common.testlib import unittest_main
 
 from cubicweb.devtools.apptest import EnvBasedTC
@@ -122,6 +124,33 @@
                               ('xml', xmlrss.XMLView),
                               ])
 
+    def test_propertiesform_admin(self):
+        rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"')
+        rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "anon"')
+        with traced_selection():
+            self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=None))
+            self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=rset1))
+            self.failUnless(self.vreg.select_object('views', 'propertiesform', req2, rset=rset2))
+
+    def test_propertiesform_anon(self):
+        self.login('anon')
+        rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"')
+        rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "anon"')
+        with traced_selection():
+            self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=None)
+            self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset1)
+            self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset2)
+
+    def test_propertiesform_jdoe(self):
+        self.create_user('jdoe')
+        self.login('jdoe')
+        rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"')
+        rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "jdoe"')
+        with traced_selection():
+            self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=None))
+            self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset1)
+            self.failUnless(self.vreg.select_object('views', 'propertiesform', req2, rset=rset2))
+
     def test_possible_views_multiple_different_types(self):
         rset, req = self.env.get_rset_and_req('Any X')
         self.assertListEqual(self.pviews(req, rset),
--- a/web/views/cwproperties.py	Tue Jul 21 12:38:10 2009 +0200
+++ b/web/views/cwproperties.py	Tue Jul 21 12:56:29 2009 +0200
@@ -228,10 +228,9 @@
 class CWPropertiesForm(SystemCWPropertiesForm):
     id = 'propertiesform'
     __select__ = (
-        # we don't want guests to be able to come here
-        match_user_groups('users', 'managers') &
-        (none_rset() | ((one_line_rset() & is_user_prefs()) &
-                        (one_line_rset() & match_user_groups('managers'))))
+        (none_rset() & match_user_groups('users','managers'))
+        | (one_line_rset() & match_user_groups('users') & is_user_prefs())
+        | (one_line_rset() & match_user_groups('managers') & implements('CWUSer'))
         )
 
     title = _('preferences')
--- a/web/views/cwuser.py	Tue Jul 21 12:38:10 2009 +0200
+++ b/web/views/cwuser.py	Tue Jul 21 12:56:29 2009 +0200
@@ -25,7 +25,7 @@
 
     def url(self):
         login = self.rset.get_entity(self.row or 0, self.col or 0).login
-        return self.build_url('cwuser/%s'%login, vid='epropertiesform')
+        return self.build_url('cwuser/%s'%login, vid='propertiesform')
 
 
 class FoafView(EntityView):