schemaviewer.py
branchreldefsecurity
changeset 3877 7ca53fc72a0a
parent 3768 8c85a2f7f5ad
child 4087 2b8bc4cfd6ee
--- a/schemaviewer.py	Wed Nov 18 09:16:38 2009 +0100
+++ b/schemaviewer.py	Thu Nov 19 12:55:47 2009 +0100
@@ -13,6 +13,7 @@
 
 I18NSTRINGS = [_('read'), _('add'), _('delete'), _('update'), _('order')]
 
+
 class SchemaViewer(object):
     """return an ureport layout for some part of a schema"""
     def __init__(self, req=None, encoding=None):
@@ -68,7 +69,8 @@
         _ = self.req._
         data = [_('attribute'), _('type'), _('default'), _('constraints')]
         for rschema, aschema in eschema.attribute_definitions():
-            if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
+            rdef = eschema.rdef(rschema)
+            if not rdef.may_have_permission('read', self.req):
                 continue
             aname = rschema.type
             if aname == 'eid':
@@ -78,7 +80,7 @@
             defaultval = eschema.default(aname)
             if defaultval is not None:
                 default = self.to_string(defaultval)
-            elif eschema.rproperty(rschema, 'cardinality')[0] == '1':
+            elif rdef.cardinality[0] == '1':
                 default = _('required field')
             else:
                 default = ''
@@ -119,20 +121,23 @@
         t_vars = []
         rels = []
         first = True
-        for rschema, targetschemas, x in eschema.relation_definitions():
+        for rschema, targetschemas, role in eschema.relation_definitions():
             if rschema.type in skiptypes:
                 continue
-            if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
-                continue
             rschemaurl = self.rschema_link_url(rschema)
             for oeschema in targetschemas:
+                rdef = rschema.role_rdef(eschema, oeschema, role)
+                if not rdef.may_have_permission('read', self.req):
+                    continue
                 label = rschema.type
-                if x == 'subject':
+                if role == 'subject':
                     cards = rschema.rproperty(eschema, oeschema, 'cardinality')
                 else:
                     cards = rschema.rproperty(oeschema, eschema, 'cardinality')
                     cards = cards[::-1]
-                label = '%s %s (%s) %s' % (CARD_MAP[cards[1]], label, display_name(self.req, label, x), CARD_MAP[cards[0]])
+                label = '%s %s (%s) %s' % (CARD_MAP[cards[1]], label,
+                                           display_name(self.req, label, role),
+                                           CARD_MAP[cards[0]])
                 rlink = Link(rschemaurl, label)
                 elink = Link(self.eschema_link_url(oeschema), oeschema.type)
                 if first: