79 """return a fake request/session using specified user""" |
79 """return a fake request/session using specified user""" |
80 session = Session(user, self.repo) |
80 session = Session(user, self.repo) |
81 session._threaddata = self.actual_session()._threaddata |
81 session._threaddata = self.actual_session()._threaddata |
82 return session |
82 return session |
83 |
83 |
84 def _change_relation(self, cb, fromeid, rtype, toeid): |
84 def _super_call(self, __cb, *args, **kwargs): |
85 if self.is_super_session: |
85 if self.is_super_session: |
86 cb(self, fromeid, rtype, toeid) |
86 __cb(self, *args, **kwargs) |
87 return |
87 return |
88 self.is_super_session = True |
88 self.is_super_session = True |
89 try: |
89 try: |
90 cb(self, fromeid, rtype, toeid) |
90 __cb(self, *args, **kwargs) |
91 finally: |
91 finally: |
92 self.is_super_session = False |
92 self.is_super_session = False |
93 |
93 |
94 def add_relation(self, fromeid, rtype, toeid): |
94 def add_relation(self, fromeid, rtype, toeid): |
95 """provide direct access to the repository method to add a relation. |
95 """provide direct access to the repository method to add a relation. |
100 |
100 |
101 without read security check but also all the burden of rql execution. |
101 without read security check but also all the burden of rql execution. |
102 You may use this in hooks when you know both eids of the relation you |
102 You may use this in hooks when you know both eids of the relation you |
103 want to add. |
103 want to add. |
104 """ |
104 """ |
105 self._change_relation(self.repo.glob_add_relation, |
105 if self.vreg.schema[rtype].inlined: |
106 fromeid, rtype, toeid) |
106 entity = self.entity_from_eid(fromeid) |
|
107 entity[rtype] = toeid |
|
108 self._super_call(self.repo.glob_update_entity, |
|
109 entity, set((rtype,))) |
|
110 else: |
|
111 self._super_call(self.repo.glob_add_relation, |
|
112 fromeid, rtype, toeid) |
|
113 |
107 def delete_relation(self, fromeid, rtype, toeid): |
114 def delete_relation(self, fromeid, rtype, toeid): |
108 """provide direct access to the repository method to delete a relation. |
115 """provide direct access to the repository method to delete a relation. |
109 |
116 |
110 This is equivalent to the following rql query: |
117 This is equivalent to the following rql query: |
111 |
118 |
113 |
120 |
114 without read security check but also all the burden of rql execution. |
121 without read security check but also all the burden of rql execution. |
115 You may use this in hooks when you know both eids of the relation you |
122 You may use this in hooks when you know both eids of the relation you |
116 want to delete. |
123 want to delete. |
117 """ |
124 """ |
118 self._change_relation(self.repo.glob_delete_relation, |
125 if self.vreg.schema[rtype].inlined: |
119 fromeid, rtype, toeid) |
126 entity = self.entity_from_eid(fromeid) |
|
127 entity[rtype] = None |
|
128 self._super_call(self.repo.glob_update_entity, |
|
129 entity, set((rtype,))) |
|
130 else: |
|
131 self._super_call(self.repo.glob_delete_relation, |
|
132 fromeid, rtype, toeid) |
120 |
133 |
121 # relations cache handling ################################################# |
134 # relations cache handling ################################################# |
122 |
135 |
123 def update_rel_cache_add(self, subject, rtype, object, symetric=False): |
136 def update_rel_cache_add(self, subject, rtype, object, symetric=False): |
124 self._update_entity_rel_cache_add(subject, rtype, 'subject', object) |
137 self._update_entity_rel_cache_add(subject, rtype, 'subject', object) |
147 rset, entities = rcache |
160 rset, entities = rcache |
148 rset.rows.append([targeteid]) |
161 rset.rows.append([targeteid]) |
149 if not isinstance(rset.description, list): # else description not set |
162 if not isinstance(rset.description, list): # else description not set |
150 rset.description = list(rset.description) |
163 rset.description = list(rset.description) |
151 rset.description.append([self.describe(targeteid)[0]]) |
164 rset.description.append([self.describe(targeteid)[0]]) |
|
165 targetentity = self.entity_from_eid(targeteid) |
|
166 if targetentity.rset is None: |
|
167 targetentity.rset = rset |
|
168 targetentity.row = rset.rowcount |
|
169 targetentity.col = 0 |
152 rset.rowcount += 1 |
170 rset.rowcount += 1 |
153 targetentity = self.entity_from_eid(targeteid) |
|
154 entities.append(targetentity) |
171 entities.append(targetentity) |
155 |
172 |
156 def _update_entity_rel_cache_del(self, eid, rtype, role, targeteid): |
173 def _update_entity_rel_cache_del(self, eid, rtype, role, targeteid): |
157 rcache = self._rel_cache(eid, rtype, role) |
174 rcache = self._rel_cache(eid, rtype, role) |
158 if rcache is not None: |
175 if rcache is not None: |