73 |
73 |
74 def __str__(self): |
74 def __str__(self): |
75 return '<%ssession %s (%s 0x%x)>' % (self.cnxtype, self.user.login, |
75 return '<%ssession %s (%s 0x%x)>' % (self.cnxtype, self.user.login, |
76 self.id, id(self)) |
76 self.id, id(self)) |
77 |
77 |
78 def add_relation(self, fromeid, rtype, toeid): |
78 def _change_relation(self, cb, fromeid, rtype, toeid): |
79 if self.is_super_session: |
79 if self.is_super_session: |
80 self.repo.glob_add_relation(self, fromeid, rtype, toeid) |
80 cb(self, fromeid, rtype, toeid) |
81 return |
81 return |
82 self.is_super_session = True |
82 self.is_super_session = True |
83 try: |
83 try: |
84 self.repo.glob_add_relation(self, fromeid, rtype, toeid) |
84 cb(self, fromeid, rtype, toeid) |
85 finally: |
85 finally: |
86 self.is_super_session = False |
86 self.is_super_session = False |
|
87 |
|
88 def add_relation(self, fromeid, rtype, toeid): |
|
89 """provide direct access to the repository method to add a relation. |
|
90 |
|
91 This is equivalent to the following rql query: |
|
92 |
|
93 SET X rtype Y WHERE X eid fromeid, T eid toeid |
|
94 |
|
95 without read security check but also all the burden of rql execution. |
|
96 You may use this in hooks when you know both eids of the relation you |
|
97 want to add. |
|
98 """ |
|
99 self._change_relation(self.repo.glob_add_relation, |
|
100 fromeid, rtype, toeid) |
|
101 def delete_relation(self, fromeid, rtype, toeid): |
|
102 """provide direct access to the repository method to delete a relation. |
|
103 |
|
104 This is equivalent to the following rql query: |
|
105 |
|
106 DELETE X rtype Y WHERE X eid fromeid, T eid toeid |
|
107 |
|
108 without read security check but also all the burden of rql execution. |
|
109 You may use this in hooks when you know both eids of the relation you |
|
110 want to delete. |
|
111 """ |
|
112 self._change_relation(self.repo.glob_delete_relation, |
|
113 fromeid, rtype, toeid) |
87 |
114 |
88 def update_rel_cache_add(self, subject, rtype, object, symetric=False): |
115 def update_rel_cache_add(self, subject, rtype, object, symetric=False): |
89 self._update_entity_rel_cache_add(subject, rtype, 'subject', object) |
116 self._update_entity_rel_cache_add(subject, rtype, 'subject', object) |
90 if symetric: |
117 if symetric: |
91 self._update_entity_rel_cache_add(object, rtype, 'subject', subject) |
118 self._update_entity_rel_cache_add(object, rtype, 'subject', subject) |