schemaviewer.py
branchreldefsecurity
changeset 3877 7ca53fc72a0a
parent 3768 8c85a2f7f5ad
child 4087 2b8bc4cfd6ee
equal deleted inserted replaced
3876:1169d3154be6 3877:7ca53fc72a0a
    10 
    10 
    11 from logilab.common.ureports import Section, Title, Table, Link, Span, Text
    11 from logilab.common.ureports import Section, Title, Table, Link, Span, Text
    12 from yams.schema2dot import CARD_MAP
    12 from yams.schema2dot import CARD_MAP
    13 
    13 
    14 I18NSTRINGS = [_('read'), _('add'), _('delete'), _('update'), _('order')]
    14 I18NSTRINGS = [_('read'), _('add'), _('delete'), _('update'), _('order')]
       
    15 
    15 
    16 
    16 class SchemaViewer(object):
    17 class SchemaViewer(object):
    17     """return an ureport layout for some part of a schema"""
    18     """return an ureport layout for some part of a schema"""
    18     def __init__(self, req=None, encoding=None):
    19     def __init__(self, req=None, encoding=None):
    19         self.req = req
    20         self.req = req
    66 
    67 
    67     def _entity_attributes_data(self, eschema):
    68     def _entity_attributes_data(self, eschema):
    68         _ = self.req._
    69         _ = self.req._
    69         data = [_('attribute'), _('type'), _('default'), _('constraints')]
    70         data = [_('attribute'), _('type'), _('default'), _('constraints')]
    70         for rschema, aschema in eschema.attribute_definitions():
    71         for rschema, aschema in eschema.attribute_definitions():
    71             if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
    72             rdef = eschema.rdef(rschema)
       
    73             if not rdef.may_have_permission('read', self.req):
    72                 continue
    74                 continue
    73             aname = rschema.type
    75             aname = rschema.type
    74             if aname == 'eid':
    76             if aname == 'eid':
    75                 continue
    77                 continue
    76             data.append('%s (%s)' % (aname, _(aname)))
    78             data.append('%s (%s)' % (aname, _(aname)))
    77             data.append(_(aschema.type))
    79             data.append(_(aschema.type))
    78             defaultval = eschema.default(aname)
    80             defaultval = eschema.default(aname)
    79             if defaultval is not None:
    81             if defaultval is not None:
    80                 default = self.to_string(defaultval)
    82                 default = self.to_string(defaultval)
    81             elif eschema.rproperty(rschema, 'cardinality')[0] == '1':
    83             elif rdef.cardinality[0] == '1':
    82                 default = _('required field')
    84                 default = _('required field')
    83             else:
    85             else:
    84                 default = ''
    86                 default = ''
    85             data.append(default)
    87             data.append(default)
    86             constraints = rschema.rproperty(eschema.type, aschema.type,
    88             constraints = rschema.rproperty(eschema.type, aschema.type,
   117         data.append(Section(children='', klass='vl'))
   119         data.append(Section(children='', klass='vl'))
   118         data.append(Section(children='', klass='hl'))
   120         data.append(Section(children='', klass='hl'))
   119         t_vars = []
   121         t_vars = []
   120         rels = []
   122         rels = []
   121         first = True
   123         first = True
   122         for rschema, targetschemas, x in eschema.relation_definitions():
   124         for rschema, targetschemas, role in eschema.relation_definitions():
   123             if rschema.type in skiptypes:
   125             if rschema.type in skiptypes:
   124                 continue
       
   125             if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
       
   126                 continue
   126                 continue
   127             rschemaurl = self.rschema_link_url(rschema)
   127             rschemaurl = self.rschema_link_url(rschema)
   128             for oeschema in targetschemas:
   128             for oeschema in targetschemas:
       
   129                 rdef = rschema.role_rdef(eschema, oeschema, role)
       
   130                 if not rdef.may_have_permission('read', self.req):
       
   131                     continue
   129                 label = rschema.type
   132                 label = rschema.type
   130                 if x == 'subject':
   133                 if role == 'subject':
   131                     cards = rschema.rproperty(eschema, oeschema, 'cardinality')
   134                     cards = rschema.rproperty(eschema, oeschema, 'cardinality')
   132                 else:
   135                 else:
   133                     cards = rschema.rproperty(oeschema, eschema, 'cardinality')
   136                     cards = rschema.rproperty(oeschema, eschema, 'cardinality')
   134                     cards = cards[::-1]
   137                     cards = cards[::-1]
   135                 label = '%s %s (%s) %s' % (CARD_MAP[cards[1]], label, display_name(self.req, label, x), CARD_MAP[cards[0]])
   138                 label = '%s %s (%s) %s' % (CARD_MAP[cards[1]], label,
       
   139                                            display_name(self.req, label, role),
       
   140                                            CARD_MAP[cards[0]])
   136                 rlink = Link(rschemaurl, label)
   141                 rlink = Link(rschemaurl, label)
   137                 elink = Link(self.eschema_link_url(oeschema), oeschema.type)
   142                 elink = Link(self.eschema_link_url(oeschema), oeschema.type)
   138                 if first:
   143                 if first:
   139                     t_vars.append(Section(children=(elink,), klass='firstvar'))
   144                     t_vars.append(Section(children=(elink,), klass='firstvar'))
   140                     rels.append(Section(children=(rlink,), klass='firstrel'))
   145                     rels.append(Section(children=(rlink,), klass='firstrel'))