3 :organization: Logilab |
3 :organization: Logilab |
4 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
4 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 from logilab.common.decorators import clear_cache |
|
9 from cubicweb.devtools import init_test_database |
8 from cubicweb.devtools import init_test_database |
10 from cubicweb.devtools.repotest import BasePlannerTC, test_plan |
9 from cubicweb.devtools.repotest import BasePlannerTC, test_plan |
11 |
10 |
12 class _SetGenerator(object): |
11 class _SetGenerator(object): |
13 """singleton to easily create set using "s[0]" or "s[0,1,2]" for instance |
12 """singleton to easily create set using "s[0]" or "s[0,1,2]" for instance |
76 # hijack Affaire security |
75 # hijack Affaire security |
77 affreadperms = list(self.schema['Affaire'].permissions['read']) |
76 affreadperms = list(self.schema['Affaire'].permissions['read']) |
78 self.prevrqlexpr_affaire = affreadperms[-1] |
77 self.prevrqlexpr_affaire = affreadperms[-1] |
79 # add access to type attribute so S can't be invariant |
78 # add access to type attribute so S can't be invariant |
80 affreadperms[-1] = ERQLExpression('X concerne S?, S owned_by U, S type "X"') |
79 affreadperms[-1] = ERQLExpression('X concerne S?, S owned_by U, S type "X"') |
81 self.schema['Affaire'].permissions['read'] = tuple(affreadperms) |
80 self.schema['Affaire'].set_action_permissions('read', affreadperms) |
82 # hijack CWUser security |
81 # hijack CWUser security |
83 userreadperms = list(self.schema['CWUser'].permissions['read']) |
82 userreadperms = list(self.schema['CWUser'].permissions['read']) |
84 self.prevrqlexpr_user = userreadperms[-1] |
83 self.prevrqlexpr_user = userreadperms[-1] |
85 userreadperms[-1] = ERQLExpression('X owned_by U') |
84 userreadperms[-1] = ERQLExpression('X owned_by U') |
86 self.schema['CWUser'].permissions['read'] = tuple(userreadperms) |
85 self.schema['CWUser'].set_action_permissions('read', userreadperms) |
87 self.add_source(FakeUserROSource, 'ldap') |
86 self.add_source(FakeUserROSource, 'ldap') |
88 self.add_source(FakeCardSource, 'cards') |
87 self.add_source(FakeCardSource, 'cards') |
89 |
88 |
90 def tearDown(self): |
89 def tearDown(self): |
91 super(BaseMSPlannerTC, self).tearDown() |
90 super(BaseMSPlannerTC, self).tearDown() |
94 self.restore_orig_cwuser_security() |
93 self.restore_orig_cwuser_security() |
95 |
94 |
96 def restore_orig_affaire_security(self): |
95 def restore_orig_affaire_security(self): |
97 affreadperms = list(self.schema['Affaire'].permissions['read']) |
96 affreadperms = list(self.schema['Affaire'].permissions['read']) |
98 affreadperms[-1] = self.prevrqlexpr_affaire |
97 affreadperms[-1] = self.prevrqlexpr_affaire |
99 self.schema['Affaire'].permissions['read'] = tuple(affreadperms) |
98 self.schema['Affaire'].set_action_permissions('read', affreadperms) |
100 clear_cache(self.schema['Affaire'], 'get_rqlexprs') |
|
101 #clear_cache(self.schema['Affaire'], 'get_groups') |
|
102 |
99 |
103 def restore_orig_cwuser_security(self): |
100 def restore_orig_cwuser_security(self): |
104 if hasattr(self, '_orig_cwuser_security_restored'): |
101 if hasattr(self, '_orig_cwuser_security_restored'): |
105 return |
102 return |
106 self._orig_cwuser_security_restored = True |
103 self._orig_cwuser_security_restored = True |
107 userreadperms = list(self.schema['CWUser'].permissions['read']) |
104 userreadperms = list(self.schema['CWUser'].permissions['read']) |
108 userreadperms[-1] = self.prevrqlexpr_user |
105 userreadperms[-1] = self.prevrqlexpr_user |
109 self.schema['CWUser'].permissions['read'] = tuple(userreadperms) |
106 self.schema['CWUser'].set_action_permissions('read', userreadperms) |
110 clear_cache(self.schema['CWUser'], 'get_rqlexprs') |
|
111 #clear_cache(self.schema['CWUser'], 'get_groups') |
|
112 |
107 |
113 |
108 |
114 class PartPlanInformationTC(BaseMSPlannerTC): |
109 class PartPlanInformationTC(BaseMSPlannerTC): |
115 |
110 |
116 def _test(self, rql, *args): |
111 def _test(self, rql, *args): |