[views/reledit] fix bad role handling in _may_add_related stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 16 Aug 2010 12:07:34 +0200
branchstable
changeset 6110 7c419cbe9809
parent 6109 47d9c0e0f7b7
child 6111 06c96a79c3c0
[views/reledit] fix bad role handling in _may_add_related
web/views/reledit.py
--- a/web/views/reledit.py	Fri Aug 13 08:23:14 2010 +0200
+++ b/web/views/reledit.py	Mon Aug 16 12:07:34 2010 +0200
@@ -42,7 +42,7 @@
     def field_by_name(self, rtype, role, eschema=None):
         return None
 
-class ClickAndEditFormView(FormViewMixIn, EntityView):
+class ClickAndEditFormView(EntityView):
     __regid__ = 'doreledit'
     __select__ = non_final_entity() & match_kwargs('rtype')
 
@@ -169,11 +169,15 @@
         if self._is_composite(entity.e_schema, rschema, role):
             if len(ttypes) > 1: # wrong cardinality: do not handle
                 return False
-            ttype = ttypes[0]
-            card = rschema.rdef(entity.e_schema, ttype).role_cardinality(role)
+            rdef = rschema.role_rdef(entity.e_schema, ttypes[0], role)
+            card = rdef.role_cardinality(role)
             if related_rset and card in '?1':
                 return False
-            if rschema.has_perm(self._cw, 'add', toetype=ttype):
+            if role == 'subject':
+                kwargs = {'fromeid': entity.eid}
+            else:
+                kwargs = {'toeid': entity.eid}
+            if rdef.has_perm(self._cw, 'add', **kwargs):
                 return True
         return False