101 self.commit() |
101 self.commit() |
102 eid2 = self.execute('INSERT CWUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][0] |
102 eid2 = self.execute('INSERT CWUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][0] |
103 e = self.execute('Any X WHERE X eid %(x)s', {'x': eid2}).get_entity(0, 0) |
103 e = self.execute('Any X WHERE X eid %(x)s', {'x': eid2}).get_entity(0, 0) |
104 e.copy_relations(user.eid) |
104 e.copy_relations(user.eid) |
105 self.commit() |
105 self.commit() |
106 e.clear_related_cache('in_state', 'subject') |
106 e.cw_clear_relation_cache('in_state', 'subject') |
107 self.assertEquals(e.cw_adapt_to('IWorkflowable').state, 'activated') |
107 self.assertEquals(e.cw_adapt_to('IWorkflowable').state, 'activated') |
108 |
108 |
109 def test_related_cache_both(self): |
109 def test_related_cache_both(self): |
110 user = self.execute('Any X WHERE X eid %(x)s', {'x':self.user().eid}).get_entity(0, 0) |
110 user = self.execute('Any X WHERE X eid %(x)s', {'x':self.user().eid}).get_entity(0, 0) |
111 adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
111 adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
112 self.commit() |
112 self.commit() |
113 self.assertEquals(user._related_cache, {}) |
113 self.assertEquals(user._cw_related_cache, {}) |
114 email = user.primary_email[0] |
114 email = user.primary_email[0] |
115 self.assertEquals(sorted(user._related_cache), ['primary_email_subject']) |
115 self.assertEquals(sorted(user._cw_related_cache), ['primary_email_subject']) |
116 self.assertEquals(email._related_cache.keys(), ['primary_email_object']) |
116 self.assertEquals(email._cw_related_cache.keys(), ['primary_email_object']) |
117 groups = user.in_group |
117 groups = user.in_group |
118 self.assertEquals(sorted(user._related_cache), ['in_group_subject', 'primary_email_subject']) |
118 self.assertEquals(sorted(user._cw_related_cache), ['in_group_subject', 'primary_email_subject']) |
119 for group in groups: |
119 for group in groups: |
120 self.failIf('in_group_subject' in group._related_cache, group._related_cache.keys()) |
120 self.failIf('in_group_subject' in group._cw_related_cache, group._cw_related_cache.keys()) |
121 |
121 |
122 def test_related_limit(self): |
122 def test_related_limit(self): |
123 req = self.request() |
123 req = self.request() |
124 p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
124 p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
125 for tag in u'abcd': |
125 for tag in u'abcd': |
195 self.failUnless(issubclass(self.vreg['etypes'].etype_class('SubNote'), Note)) |
195 self.failUnless(issubclass(self.vreg['etypes'].etype_class('SubNote'), Note)) |
196 Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type')) |
196 Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type')) |
197 Note.fetch_attrs, Note.fetch_order = fetch_config(('type',)) |
197 Note.fetch_attrs, Note.fetch_order = fetch_config(('type',)) |
198 SubNote.fetch_attrs, SubNote.fetch_order = fetch_config(('type',)) |
198 SubNote.fetch_attrs, SubNote.fetch_order = fetch_config(('type',)) |
199 p = self.request().create_entity('Personne', nom=u'pouet') |
199 p = self.request().create_entity('Personne', nom=u'pouet') |
200 self.assertEquals(p.related_rql('evaluee'), |
200 self.assertEquals(p.cw_related_rql('evaluee'), |
201 'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, ' |
201 'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, ' |
202 'X type AA, X modification_date AB') |
202 'X type AA, X modification_date AB') |
203 Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', )) |
203 Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', )) |
204 # XXX |
204 # XXX |
205 self.assertEquals(p.related_rql('evaluee'), |
205 self.assertEquals(p.cw_related_rql('evaluee'), |
206 'Any X,AA ORDERBY AA DESC ' |
206 'Any X,AA ORDERBY AA DESC ' |
207 'WHERE E eid %(x)s, E evaluee X, X modification_date AA') |
207 'WHERE E eid %(x)s, E evaluee X, X modification_date AA') |
208 |
208 |
209 tag = self.vreg['etypes'].etype_class('Tag')(self.request()) |
209 tag = self.vreg['etypes'].etype_class('Tag')(self.request()) |
210 self.assertEquals(tag.related_rql('tags', 'subject'), |
210 self.assertEquals(tag.cw_related_rql('tags', 'subject'), |
211 'Any X,AA ORDERBY AA DESC ' |
211 'Any X,AA ORDERBY AA DESC ' |
212 'WHERE E eid %(x)s, E tags X, X modification_date AA') |
212 'WHERE E eid %(x)s, E tags X, X modification_date AA') |
213 self.assertEquals(tag.related_rql('tags', 'subject', ('Personne',)), |
213 self.assertEquals(tag.cw_related_rql('tags', 'subject', ('Personne',)), |
214 'Any X,AA,AB ORDERBY AA ASC ' |
214 'Any X,AA,AB ORDERBY AA ASC ' |
215 'WHERE E eid %(x)s, E tags X, X is IN (Personne), X nom AA, ' |
215 'WHERE E eid %(x)s, E tags X, X is IN (Personne), X nom AA, ' |
216 'X modification_date AB') |
216 'X modification_date AB') |
217 |
217 |
218 def test_related_rql_ambigous_cant_use_fetch_order(self): |
218 def test_related_rql_ambigous_cant_use_fetch_order(self): |
219 tag = self.vreg['etypes'].etype_class('Tag')(self.request()) |
219 tag = self.vreg['etypes'].etype_class('Tag')(self.request()) |
220 for ttype in self.schema['tags'].objects(): |
220 for ttype in self.schema['tags'].objects(): |
221 self.vreg['etypes'].etype_class(ttype).fetch_attrs = ('modification_date',) |
221 self.vreg['etypes'].etype_class(ttype).fetch_attrs = ('modification_date',) |
222 self.assertEquals(tag.related_rql('tags', 'subject'), |
222 self.assertEquals(tag.cw_related_rql('tags', 'subject'), |
223 'Any X,AA ORDERBY AA DESC ' |
223 'Any X,AA ORDERBY AA DESC ' |
224 'WHERE E eid %(x)s, E tags X, X modification_date AA') |
224 'WHERE E eid %(x)s, E tags X, X modification_date AA') |
225 |
225 |
226 def test_unrelated_rql_security_1(self): |
226 def test_unrelated_rql_security_1(self): |
227 user = self.request().user |
227 user = self.request().user |
228 rql = user.unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
228 rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
229 self.assertEquals(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
229 self.assertEquals(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
230 'WHERE NOT S use_email O, S eid %(x)s, O is EmailAddress, O address AA, O alias AB, O modification_date AC') |
230 'WHERE NOT S use_email O, S eid %(x)s, O is EmailAddress, O address AA, O alias AB, O modification_date AC') |
231 self.create_user('toto') |
231 self.create_user('toto') |
232 self.login('toto') |
232 self.login('toto') |
233 user = self.request().user |
233 user = self.request().user |
234 rql = user.unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
234 rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
235 self.assertEquals(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
235 self.assertEquals(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
236 'WHERE NOT S use_email O, S eid %(x)s, O is EmailAddress, O address AA, O alias AB, O modification_date AC') |
236 'WHERE NOT S use_email O, S eid %(x)s, O is EmailAddress, O address AA, O alias AB, O modification_date AC') |
237 user = self.execute('Any X WHERE X login "admin"').get_entity(0, 0) |
237 user = self.execute('Any X WHERE X login "admin"').get_entity(0, 0) |
238 self.assertRaises(Unauthorized, user.unrelated_rql, 'use_email', 'EmailAddress', 'subject') |
238 self.assertRaises(Unauthorized, user.cw_unrelated_rql, 'use_email', 'EmailAddress', 'subject') |
239 self.login('anon') |
239 self.login('anon') |
240 user = self.request().user |
240 user = self.request().user |
241 self.assertRaises(Unauthorized, user.unrelated_rql, 'use_email', 'EmailAddress', 'subject') |
241 self.assertRaises(Unauthorized, user.cw_unrelated_rql, 'use_email', 'EmailAddress', 'subject') |
242 |
242 |
243 def test_unrelated_rql_security_2(self): |
243 def test_unrelated_rql_security_2(self): |
244 email = self.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
244 email = self.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
245 rql = email.unrelated_rql('use_email', 'CWUser', 'object')[0] |
245 rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
246 self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ASC ' |
246 self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ASC ' |
247 'WHERE NOT S use_email O, O eid %(x)s, S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD') |
247 'WHERE NOT S use_email O, O eid %(x)s, S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD') |
248 #rql = email.unrelated_rql('use_email', 'Person', 'object')[0] |
248 #rql = email.cw_unrelated_rql('use_email', 'Person', 'object')[0] |
249 #self.assertEquals(rql, '') |
249 #self.assertEquals(rql, '') |
250 self.login('anon') |
250 self.login('anon') |
251 email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
251 email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
252 rql = email.unrelated_rql('use_email', 'CWUser', 'object')[0] |
252 rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
253 self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
253 self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
254 'WHERE NOT S use_email O, O eid %(x)s, S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD, ' |
254 'WHERE NOT S use_email O, O eid %(x)s, S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD, ' |
255 'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)') |
255 'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)') |
256 #rql = email.unrelated_rql('use_email', 'Person', 'object')[0] |
256 #rql = email.cw_unrelated_rql('use_email', 'Person', 'object')[0] |
257 #self.assertEquals(rql, '') |
257 #self.assertEquals(rql, '') |
258 |
258 |
259 def test_unrelated_rql_security_nonexistant(self): |
259 def test_unrelated_rql_security_nonexistant(self): |
260 self.login('anon') |
260 self.login('anon') |
261 email = self.vreg['etypes'].etype_class('EmailAddress')(self.request()) |
261 email = self.vreg['etypes'].etype_class('EmailAddress')(self.request()) |
262 rql = email.unrelated_rql('use_email', 'CWUser', 'object')[0] |
262 rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
263 self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
263 self.assertEquals(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
264 'WHERE S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD, ' |
264 'WHERE S is CWUser, S login AA, S firstname AB, S surname AC, S modification_date AD, ' |
265 'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)') |
265 'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)') |
266 |
266 |
267 def test_unrelated_base(self): |
267 def test_unrelated_base(self): |