server/hooks.py
branchreldefsecurity
changeset 3877 7ca53fc72a0a
parent 3859 85e6ba89837a
equal deleted inserted replaced
3876:1169d3154be6 3877:7ca53fc72a0a
   258     if session.is_super_session:
   258     if session.is_super_session:
   259         return
   259         return
   260     schema = session.vreg.schema
   260     schema = session.vreg.schema
   261     for attr in entity.edited_attributes:
   261     for attr in entity.edited_attributes:
   262         if schema.rschema(attr).final:
   262         if schema.rschema(attr).final:
   263             constraints = [c for c in entity.e_schema.constraints(attr)
   263             constraints = [c for c in entity.e_schema.rdef(attr).constraints
   264                            if isinstance(c, RQLVocabularyConstraint)]
   264                            if isinstance(c, RQLVocabularyConstraint)]
   265             if constraints:
   265             if constraints:
   266                 CheckConstraintsOperation(session, rdef=(entity.eid, attr, None),
   266                 CheckConstraintsOperation(session, rdef=(entity.eid, attr, None),
   267                                           constraints=constraints)
   267                                           constraints=constraints)
   268 
   268 
   315 def cardinalitycheck_after_add_entity(session, entity):
   315 def cardinalitycheck_after_add_entity(session, entity):
   316     """check cardinalities are satisfied"""
   316     """check cardinalities are satisfied"""
   317     if session.is_super_session:
   317     if session.is_super_session:
   318         return
   318         return
   319     eid = entity.eid
   319     eid = entity.eid
   320     for rschema, targetschemas, x in entity.e_schema.relation_definitions():
   320     for rschema, targetschemas, role in entity.e_schema.relation_definitions():
   321         # skip automatically handled relations
   321         # skip automatically handled relations
   322         if rschema.type in DONT_CHECK_RTYPES_ON_ADD:
   322         if rschema.type in DONT_CHECK_RTYPES_ON_ADD:
   323             continue
   323             continue
   324         if x == 'subject':
   324         if role == 'subject':
   325             subjtype = entity.e_schema
   325             subjtype = entity.e_schema
   326             objtype = targetschemas[0].type
   326             objtype = targetschemas[0].type
   327             cardindex = 0
       
   328             opcls = CheckSRelationOp
   327             opcls = CheckSRelationOp
   329         else:
   328         else:
   330             subjtype = targetschemas[0].type
   329             subjtype = targetschemas[0].type
   331             objtype = entity.e_schema
   330             objtype = entity.e_schema
   332             cardindex = 1
       
   333             opcls = CheckORelationOp
   331             opcls = CheckORelationOp
   334         card = rschema.rproperty(subjtype, objtype, 'cardinality')
   332         card = rschema.rdef(subjtype, objtype).role_cardinality(role)
   335         if card[cardindex] in '1+':
   333         if card in '1+':
   336             checkrel_if_necessary(session, opcls, rschema.type, eid)
   334             checkrel_if_necessary(session, opcls, rschema.type, eid)
   337 
   335 
   338 def cardinalitycheck_before_del_relation(session, eidfrom, rtype, eidto):
   336 def cardinalitycheck_before_del_relation(session, eidfrom, rtype, eidto):
   339     """check cardinalities are satisfied"""
   337     """check cardinalities are satisfied"""
   340     if session.is_super_session:
   338     if session.is_super_session: