18 from logilab.common.testlib import unittest_main, mock_object |
18 from logilab.common.testlib import unittest_main, mock_object |
19 |
19 |
20 from cubicweb.devtools.testlib import CubicWebTC |
20 from cubicweb.devtools.testlib import CubicWebTC |
21 from cubicweb.web.views import uicfg |
21 from cubicweb.web.views import uicfg |
22 from cubicweb.web.formwidgets import AutoCompletionWidget |
22 from cubicweb.web.formwidgets import AutoCompletionWidget |
|
23 from cubicweb.schema import RRQLExpression |
|
24 |
23 |
25 |
24 AFFK = uicfg.autoform_field_kwargs |
26 AFFK = uicfg.autoform_field_kwargs |
25 AFS = uicfg.autoform_section |
27 AFS = uicfg.autoform_section |
26 |
28 |
27 def rbc(entity, formtype, section): |
29 def rbc(entity, formtype, section): |
177 with self.admin_access.web_request() as req: |
179 with self.admin_access.web_request() as req: |
178 with self.temporary_permissions(EmailAddress={'add': ()}): |
180 with self.temporary_permissions(EmailAddress={'add': ()}): |
179 autoform = self.vreg['forms'].select('edition', req, entity=req.user) |
181 autoform = self.vreg['forms'].select('edition', req, entity=req.user) |
180 self.assertEqual(list(autoform.inlined_form_views()), []) |
182 self.assertEqual(list(autoform.inlined_form_views()), []) |
181 |
183 |
|
184 def test_check_inlined_rdef_permissions(self): |
|
185 # try to check permissions when creating an entity ('user' below is a |
|
186 # fresh entity without an eid) |
|
187 with self.admin_access.web_request() as req: |
|
188 ttype = 'EmailAddress' |
|
189 rschema = self.schema['use_email'] |
|
190 rdef = rschema.rdefs[('CWUser', ttype)] |
|
191 tschema = self.schema[ttype] |
|
192 role = 'subject' |
|
193 with self.temporary_permissions((rdef, {'add': ()})): |
|
194 user = self.vreg['etypes'].etype_class('CWUser')(req) |
|
195 autoform = self.vreg['forms'].select('edition', req, entity=user) |
|
196 self.assertFalse(autoform.check_inlined_rdef_permissions(rschema, role, |
|
197 tschema, ttype)) |
|
198 # we actually don't care about the actual expression, |
|
199 # may_have_permission only checks the presence of such expressions |
|
200 expr = RRQLExpression('S use_email O') |
|
201 with self.temporary_permissions((rdef, {'add': (expr,)})): |
|
202 user = self.vreg['etypes'].etype_class('CWUser')(req) |
|
203 autoform = self.vreg['forms'].select('edition', req, entity=user) |
|
204 self.assertTrue(autoform.check_inlined_rdef_permissions(rschema, role, |
|
205 tschema, ttype)) |
|
206 |
182 |
207 |
183 class FormViewsTC(CubicWebTC): |
208 class FormViewsTC(CubicWebTC): |
184 |
209 |
185 def test_delete_conf_formview(self): |
210 def test_delete_conf_formview(self): |
186 with self.admin_access.web_request() as req: |
211 with self.admin_access.web_request() as req: |