equal
deleted
inserted
replaced
143 else: |
143 else: |
144 self.tx.enable_hook_categories(*self.categories) |
144 self.tx.enable_hook_categories(*self.categories) |
145 finally: |
145 finally: |
146 self.tx.hooks_mode = self.oldmode |
146 self.tx.hooks_mode = self.oldmode |
147 |
147 |
148 |
148 @deprecated('[3.17] use <object>.security_enabled instead') |
149 class security_enabled(object): |
149 def security_enabled(obj, *args, **kwargs): |
|
150 return obj.security_enabled(*args, **kwargs) |
|
151 |
|
152 class _security_enabled(object): |
150 """context manager to control security w/ session.execute, |
153 """context manager to control security w/ session.execute, |
151 |
154 |
152 By default security is disabled on queries executed on the repository |
155 By default security is disabled on queries executed on the repository |
153 side. |
156 side. |
154 """ |
157 """ |
853 2-uple is the rtype, and the second is a list of (fromeid, |
856 2-uple is the rtype, and the second is a list of (fromeid, |
854 toeid) tuples |
857 toeid) tuples |
855 ''' |
858 ''' |
856 edited_entities = {} |
859 edited_entities = {} |
857 relations_dict = {} |
860 relations_dict = {} |
858 with security_enabled(self, False, False): |
861 with self.security_enabled(False, False): |
859 for rtype, eids in relations: |
862 for rtype, eids in relations: |
860 if self.vreg.schema[rtype].inlined: |
863 if self.vreg.schema[rtype].inlined: |
861 for fromeid, toeid in eids: |
864 for fromeid, toeid in eids: |
862 if fromeid not in edited_entities: |
865 if fromeid not in edited_entities: |
863 entity = self.entity_from_eid(fromeid) |
866 entity = self.entity_from_eid(fromeid) |
882 |
885 |
883 without read security check but also all the burden of rql execution. |
886 without read security check but also all the burden of rql execution. |
884 You may use this in hooks when you know both eids of the relation you |
887 You may use this in hooks when you know both eids of the relation you |
885 want to delete. |
888 want to delete. |
886 """ |
889 """ |
887 with security_enabled(self, False, False): |
890 with self.security_enabled(False, False): |
888 if self.vreg.schema[rtype].inlined: |
891 if self.vreg.schema[rtype].inlined: |
889 entity = self.entity_from_eid(fromeid) |
892 entity = self.entity_from_eid(fromeid) |
890 entity.cw_attr_cache[rtype] = None |
893 entity.cw_attr_cache[rtype] = None |
891 self.repo.glob_update_entity(self, entity, set((rtype,))) |
894 self.repo.glob_update_entity(self, entity, set((rtype,))) |
892 else: |
895 else: |
987 |
990 |
988 # security control ######################################################### |
991 # security control ######################################################### |
989 |
992 |
990 |
993 |
991 def security_enabled(self, read=None, write=None): |
994 def security_enabled(self, read=None, write=None): |
992 return security_enabled(self, read=read, write=write) |
995 return _security_enabled(self, read=read, write=write) |
993 |
996 |
994 read_security = tx_attr('read_security', writable=True) |
997 read_security = tx_attr('read_security', writable=True) |
995 write_security = tx_attr('write_security', writable=True) |
998 write_security = tx_attr('write_security', writable=True) |
996 running_dbapi_query = tx_attr('running_dbapi_query') |
999 running_dbapi_query = tx_attr('running_dbapi_query') |
997 |
1000 |
1210 # - processed by the precommit/commit event or not |
1213 # - processed by the precommit/commit event or not |
1211 # - if processed, is it the failed operation |
1214 # - if processed, is it the failed operation |
1212 debug = server.DEBUG & server.DBG_OPS |
1215 debug = server.DEBUG & server.DBG_OPS |
1213 try: |
1216 try: |
1214 # by default, operations are executed with security turned off |
1217 # by default, operations are executed with security turned off |
1215 with security_enabled(self, False, False): |
1218 with self.security_enabled(False, False): |
1216 processed = [] |
1219 processed = [] |
1217 self.commit_state = 'precommit' |
1220 self.commit_state = 'precommit' |
1218 if debug: |
1221 if debug: |
1219 print self.commit_state, '*' * 20 |
1222 print self.commit_state, '*' * 20 |
1220 try: |
1223 try: |
1289 self._touch() |
1292 self._touch() |
1290 self.debug('rollback session %s done (no db activity)', self.id) |
1293 self.debug('rollback session %s done (no db activity)', self.id) |
1291 return |
1294 return |
1292 try: |
1295 try: |
1293 # by default, operations are executed with security turned off |
1296 # by default, operations are executed with security turned off |
1294 with security_enabled(self, False, False): |
1297 with self.security_enabled(False, False): |
1295 while self.pending_operations: |
1298 while self.pending_operations: |
1296 try: |
1299 try: |
1297 operation = self.pending_operations.pop(0) |
1300 operation = self.pending_operations.pop(0) |
1298 operation.handle_event('rollback_event') |
1301 operation.handle_event('rollback_event') |
1299 except BaseException: |
1302 except BaseException: |