server/session.py
branch3.5
changeset 3198 d2f48d30e73e
parent 3184 613064b49331
parent 3197 b27d19c0db1c
child 3199 fc63b80ec979
child 3240 8604a15995d1
equal deleted inserted replaced
3192:93c8fdcd943e 3198:d2f48d30e73e
    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)
   150             rset, entities = rcache
   163             rset, entities = rcache
   151             rset.rows.append([targeteid])
   164             rset.rows.append([targeteid])
   152             if not isinstance(rset.description, list): # else description not set
   165             if not isinstance(rset.description, list): # else description not set
   153                 rset.description = list(rset.description)
   166                 rset.description = list(rset.description)
   154             rset.description.append([self.describe(targeteid)[0]])
   167             rset.description.append([self.describe(targeteid)[0]])
       
   168             targetentity = self.entity_from_eid(targeteid)
       
   169             if targetentity.rset is None:
       
   170                 targetentity.rset = rset
       
   171                 targetentity.row = rset.rowcount
       
   172                 targetentity.col = 0
   155             rset.rowcount += 1
   173             rset.rowcount += 1
   156             targetentity = self.entity_from_eid(targeteid)
       
   157             entities.append(targetentity)
   174             entities.append(targetentity)
   158 
   175 
   159     def _update_entity_rel_cache_del(self, eid, rtype, role, targeteid):
   176     def _update_entity_rel_cache_del(self, eid, rtype, role, targeteid):
   160         rcache = self._rel_cache(eid, rtype, role)
   177         rcache = self._rel_cache(eid, rtype, role)
   161         if rcache is not None:
   178         if rcache is not None: