web/views/owl.py
branchreldefsecurity
changeset 3877 7ca53fc72a0a
parent 3689 deb13e88e037
child 3890 d7a270f50f54
equal deleted inserted replaced
3876:1169d3154be6 3877:7ca53fc72a0a
    69             self.w(OWL_OPENING_ROOT % {'appid': self.schema.name})
    69             self.w(OWL_OPENING_ROOT % {'appid': self.schema.name})
    70         self.visit_schema(skiptypes=skipmeta and schema.SKIP_TYPES or ())
    70         self.visit_schema(skiptypes=skipmeta and schema.SKIP_TYPES or ())
    71         if writeprefix:
    71         if writeprefix:
    72             self.w(OWL_CLOSING_ROOT)
    72             self.w(OWL_CLOSING_ROOT)
    73 
    73 
    74     def should_display_rschema(self, rschema):
    74     def should_display_rschema(self, eschema, rschema, tschemas, role):
    75         return not rschema in self.skiptypes and (
    75         return rschema.may_have_permissions('read', self.req, eschema, role)
    76             rschema.has_local_role('read') or
       
    77             rschema.has_perm(self.req, 'read'))
       
    78 
    76 
    79     def visit_schema(self, skiptypes):
    77     def visit_schema(self, skiptypes):
    80         """get a layout for a whole schema"""
    78         """get a layout for a whole schema"""
    81         self.skiptypes = skiptypes
    79         self.skiptypes = skiptypes
    82         entities = sorted(eschema for eschema in self.schema.entities()
    80         entities = sorted(eschema for eschema in self.schema.entities()
    92     def visit_entityschema(self, eschema):
    90     def visit_entityschema(self, eschema):
    93         """get a layout for an entity OWL schema"""
    91         """get a layout for an entity OWL schema"""
    94         self.w(u'<owl:Class rdf:ID="%s">'% eschema)
    92         self.w(u'<owl:Class rdf:ID="%s">'% eschema)
    95         self.w(u'<!-- relations -->')
    93         self.w(u'<!-- relations -->')
    96         for rschema, targetschemas, role in eschema.relation_definitions():
    94         for rschema, targetschemas, role in eschema.relation_definitions():
    97             if not self.should_display_rschema(rschema):
    95             if not self.should_display_rschema(eschema, rschema, targetschemas, role):
    98                 continue
    96                 continue
    99             for oeschema in targetschemas:
    97             for oeschema in targetschemas:
   100                 if role == 'subject':
    98                 if role == 'subject':
   101                     card = rschema.rproperty(eschema, oeschema, 'cardinality')[0]
    99                     card = rschema.rproperty(eschema, oeschema, 'cardinality')[0]
   102                 else:
   100                 else:
   110  </owl:Restriction>
   108  </owl:Restriction>
   111 </rdfs:subClassOf>''' % (rschema, cardtag))
   109 </rdfs:subClassOf>''' % (rschema, cardtag))
   112 
   110 
   113         self.w(u'<!-- attributes -->')
   111         self.w(u'<!-- attributes -->')
   114         for rschema, aschema in eschema.attribute_definitions():
   112         for rschema, aschema in eschema.attribute_definitions():
   115             if not self.should_display_rschema(rschema):
   113             if not self.should_display_rschema(eschema, rschema, (aschema,), 'subject'):
   116                 continue
   114                 continue
   117             self.w(u'''<rdfs:subClassOf>
   115             self.w(u'''<rdfs:subClassOf>
   118   <owl:Restriction>
   116   <owl:Restriction>
   119    <owl:onProperty rdf:resource="#%s"/>
   117    <owl:onProperty rdf:resource="#%s"/>
   120    <rdf:type rdf:resource="&owl;FunctionalProperty"/>
   118    <rdf:type rdf:resource="&owl;FunctionalProperty"/>
   123         self.w(u'</owl:Class>')
   121         self.w(u'</owl:Class>')
   124 
   122 
   125     def visit_property_schema(self, eschema):
   123     def visit_property_schema(self, eschema):
   126         """get a layout for property entity OWL schema"""
   124         """get a layout for property entity OWL schema"""
   127         for rschema, targetschemas, role in eschema.relation_definitions():
   125         for rschema, targetschemas, role in eschema.relation_definitions():
   128             if not self.should_display_rschema(rschema):
   126             if not self.should_display_rschema(eschema, rschema, targetschemas, role):
   129                 continue
   127                 continue
   130             for oeschema in targetschemas:
   128             for oeschema in targetschemas:
   131                 self.w(u'''<owl:ObjectProperty rdf:ID="%s">
   129                 self.w(u'''<owl:ObjectProperty rdf:ID="%s">
   132  <rdfs:domain rdf:resource="#%s"/>
   130  <rdfs:domain rdf:resource="#%s"/>
   133  <rdfs:range rdf:resource="#%s"/>
   131  <rdfs:range rdf:resource="#%s"/>
   134 </owl:ObjectProperty>''' % (rschema, eschema, oeschema.type))
   132 </owl:ObjectProperty>''' % (rschema, eschema, oeschema.type))
   135 
   133 
   136     def visit_property_object_schema(self, eschema):
   134     def visit_property_object_schema(self, eschema):
   137         for rschema, aschema in eschema.attribute_definitions():
   135         for rschema, aschema in eschema.attribute_definitions():
   138             if not self.should_display_rschema(rschema):
   136             if not self.should_display_rschema(eschema, rschema, (aschema,), 'subject'):
   139                 continue
   137                 continue
   140             self.w(u'''<owl:DatatypeProperty rdf:ID="%s">
   138             self.w(u'''<owl:DatatypeProperty rdf:ID="%s">
   141   <rdfs:domain rdf:resource="#%s"/>
   139   <rdfs:domain rdf:resource="#%s"/>
   142   <rdfs:range rdf:resource="%s"/>
   140   <rdfs:range rdf:resource="%s"/>
   143 </owl:DatatypeProperty>''' % (rschema, eschema, OWL_TYPE_MAP[aschema.type]))
   141 </owl:DatatypeProperty>''' % (rschema, eschema, OWL_TYPE_MAP[aschema.type]))
   172         self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid))
   170         self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid))
   173         self.w(u'<!--attributes-->')
   171         self.w(u'<!--attributes-->')
   174         for rschema, aschema in eschema.attribute_definitions():
   172         for rschema, aschema in eschema.attribute_definitions():
   175             if rschema.meta:
   173             if rschema.meta:
   176                 continue
   174                 continue
   177             if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
   175             rdef = rschema.rdef(eschema, aschema)
       
   176             if not rdef.may_have_permission('read', self.req):
   178                 continue
   177                 continue
   179             aname = rschema.type
   178             aname = rschema.type
   180             if aname == 'eid':
   179             if aname == 'eid':
   181                 continue
   180                 continue
   182             try:
   181             try:
   187                 pass
   186                 pass
   188         self.w(u'<!--relations -->')
   187         self.w(u'<!--relations -->')
   189         for rschema, targetschemas, role in eschema.relation_definitions():
   188         for rschema, targetschemas, role in eschema.relation_definitions():
   190             if rschema.meta:
   189             if rschema.meta:
   191                 continue
   190                 continue
   192             if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
   191             for tschema in targetschemas:
   193                 continue
   192                 rdef = rschema.role_rdef(eschema, tschema, role)
       
   193                 if not rdef.may_have_permission('read', self.req):
       
   194                     continue
   194             if role == 'object':
   195             if role == 'object':
   195                 attr = 'reverse_%s' % rschema.type
   196                 attr = 'reverse_%s' % rschema.type
   196             else:
   197             else:
   197                 attr = rschema.type
   198                 attr = rschema.type
   198             for x in getattr(entity, attr):
   199             for x in getattr(entity, attr):