server/session.py
branchstable
changeset 3197 b27d19c0db1c
parent 3196 77936fa67ae6
child 3198 d2f48d30e73e
equal deleted inserted replaced
3196:77936fa67ae6 3197:b27d19c0db1c
    82         """return a fake request/session using specified user"""
    82         """return a fake request/session using specified user"""
    83         session = Session(user, self.repo)
    83         session = Session(user, self.repo)
    84         session._threaddata = self.actual_session()._threaddata
    84         session._threaddata = self.actual_session()._threaddata
    85         return session
    85         return session
    86 
    86 
    87     def _change_relation(self, cb, fromeid, rtype, toeid):
    87     def _super_call(self, __cb, *args, **kwargs):
    88         if self.is_super_session:
    88         if self.is_super_session:
    89             cb(self, fromeid, rtype, toeid)
    89             __cb(self, *args, **kwargs)
    90             return
    90             return
    91         self.is_super_session = True
    91         self.is_super_session = True
    92         try:
    92         try:
    93             cb(self, fromeid, rtype, toeid)
    93             __cb(self, *args, **kwargs)
    94         finally:
    94         finally:
    95             self.is_super_session = False
    95             self.is_super_session = False
    96 
    96 
    97     def add_relation(self, fromeid, rtype, toeid):
    97     def add_relation(self, fromeid, rtype, toeid):
    98         """provide direct access to the repository method to add a relation.
    98         """provide direct access to the repository method to add a relation.
   103 
   103 
   104         without read security check but also all the burden of rql execution.
   104         without read security check but also all the burden of rql execution.
   105         You may use this in hooks when you know both eids of the relation you
   105         You may use this in hooks when you know both eids of the relation you
   106         want to add.
   106         want to add.
   107         """
   107         """
   108         self._change_relation(self.repo.glob_add_relation,
   108         if self.vreg.schema[rtype].inlined:
   109                               fromeid, rtype, toeid)
   109             entity = self.entity_from_eid(fromeid)
       
   110             entity[rtype] = toeid
       
   111             self._super_call(self.repo.glob_update_entity,
       
   112                              entity, set((rtype,)))
       
   113         else:
       
   114             self._super_call(self.repo.glob_add_relation,
       
   115                              fromeid, rtype, toeid)
       
   116 
   110     def delete_relation(self, fromeid, rtype, toeid):
   117     def delete_relation(self, fromeid, rtype, toeid):
   111         """provide direct access to the repository method to delete a relation.
   118         """provide direct access to the repository method to delete a relation.
   112 
   119 
   113         This is equivalent to the following rql query:
   120         This is equivalent to the following rql query:
   114 
   121 
   116 
   123 
   117         without read security check but also all the burden of rql execution.
   124         without read security check but also all the burden of rql execution.
   118         You may use this in hooks when you know both eids of the relation you
   125         You may use this in hooks when you know both eids of the relation you
   119         want to delete.
   126         want to delete.
   120         """
   127         """
   121         self._change_relation(self.repo.glob_delete_relation,
   128         if self.vreg.schema[rtype].inlined:
   122                               fromeid, rtype, toeid)
   129             entity = self.entity_from_eid(fromeid)
       
   130             entity[rtype] = None
       
   131             self._super_call(self.repo.glob_update_entity,
       
   132                              entity, set((rtype,)))
       
   133         else:
       
   134             self._super_call(self.repo.glob_delete_relation,
       
   135                              fromeid, rtype, toeid)
   123 
   136 
   124     # relations cache handling #################################################
   137     # relations cache handling #################################################
   125 
   138 
   126     def update_rel_cache_add(self, subject, rtype, object, symetric=False):
   139     def update_rel_cache_add(self, subject, rtype, object, symetric=False):
   127         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
   140         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)