server/session.py
branchstable
changeset 3112 873202e181bb
parent 3074 141cfaac6b97
child 3120 57ceabc6dfbc
child 3161 005f745315b0
equal deleted inserted replaced
3109:e7e1bb06b716 3112:873202e181bb
    76 
    76 
    77     @property
    77     @property
    78     def schema(self):
    78     def schema(self):
    79         return self.repo.schema
    79         return self.repo.schema
    80 
    80 
    81     def add_relation(self, fromeid, rtype, toeid):
    81     def hijack_user(self, user):
       
    82         """return a fake request/session using specified user"""
       
    83         session = Session(user, self.repo)
       
    84         session._threaddata = self._threaddata
       
    85         return session
       
    86 
       
    87     def _change_relation(self, cb, fromeid, rtype, toeid):
    82         if self.is_super_session:
    88         if self.is_super_session:
    83             self.repo.glob_add_relation(self, fromeid, rtype, toeid)
    89             cb(self, fromeid, rtype, toeid)
    84             return
    90             return
    85         self.is_super_session = True
    91         self.is_super_session = True
    86         try:
    92         try:
    87             self.repo.glob_add_relation(self, fromeid, rtype, toeid)
    93             cb(self, fromeid, rtype, toeid)
    88         finally:
    94         finally:
    89             self.is_super_session = False
    95             self.is_super_session = False
       
    96 
       
    97     def add_relation(self, fromeid, rtype, toeid):
       
    98         """provide direct access to the repository method to add a relation.
       
    99 
       
   100         This is equivalent to the following rql query:
       
   101 
       
   102           SET X rtype Y WHERE X eid  fromeid, T eid toeid
       
   103 
       
   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
       
   106         want to add.
       
   107         """
       
   108         self._change_relation(self.repo.glob_add_relation,
       
   109                               fromeid, rtype, toeid)
       
   110     def delete_relation(self, fromeid, rtype, toeid):
       
   111         """provide direct access to the repository method to delete a relation.
       
   112 
       
   113         This is equivalent to the following rql query:
       
   114 
       
   115           DELETE X rtype Y WHERE X eid  fromeid, T eid toeid
       
   116 
       
   117         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
       
   119         want to delete.
       
   120         """
       
   121         self._change_relation(self.repo.glob_delete_relation,
       
   122                               fromeid, rtype, toeid)
       
   123 
       
   124     # relations cache handling #################################################
    90 
   125 
    91     def update_rel_cache_add(self, subject, rtype, object, symetric=False):
   126     def update_rel_cache_add(self, subject, rtype, object, symetric=False):
    92         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
   127         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
    93         if symetric:
   128         if symetric:
    94             self._update_entity_rel_cache_add(object, rtype, 'subject', subject)
   129             self._update_entity_rel_cache_add(object, rtype, 'subject', subject)