365 |
365 |
366 |
366 |
367 ### security control attributes |
367 ### security control attributes |
368 self._read_security = DEFAULT_SECURITY # handled by a property |
368 self._read_security = DEFAULT_SECURITY # handled by a property |
369 self.write_security = DEFAULT_SECURITY |
369 self.write_security = DEFAULT_SECURITY |
|
370 |
|
371 # undo control |
|
372 config = session.repo.config |
|
373 if config.creating or config.repairing or session.is_internal_session: |
|
374 self.undo_actions = False |
|
375 else: |
|
376 self.undo_actions = config['undo-enabled'] |
370 |
377 |
371 # RQLRewriter are not thread safe |
378 # RQLRewriter are not thread safe |
372 self._rewriter = rewriter |
379 self._rewriter = rewriter |
373 |
380 |
374 @property |
381 @property |
542 # also reset running_dbapi_query to true when we go back to |
549 # also reset running_dbapi_query to true when we go back to |
543 # DEFAULT_SECURITY |
550 # DEFAULT_SECURITY |
544 self.running_dbapi_query = (oldmode is DEFAULT_SECURITY |
551 self.running_dbapi_query = (oldmode is DEFAULT_SECURITY |
545 or activated is DEFAULT_SECURITY) |
552 or activated is DEFAULT_SECURITY) |
546 |
553 |
|
554 # undo support ############################################################ |
|
555 |
|
556 def ertype_supports_undo(self, ertype): |
|
557 return self.undo_actions and ertype not in NO_UNDO_TYPES |
|
558 |
|
559 def transaction_uuid(self, set=True): |
|
560 uuid = self.data.get('tx_uuid') |
|
561 if set and uuid is None: |
|
562 raise KeyError |
|
563 return uuid |
|
564 |
|
565 def transaction_inc_action_counter(self): |
|
566 num = self.data.setdefault('tx_action_count', 0) + 1 |
|
567 self.data['tx_action_count'] = num |
|
568 return num |
|
569 |
547 |
570 |
548 def tx_attr(attr_name, writable=False): |
571 def tx_attr(attr_name, writable=False): |
549 """return a property to forward attribute access to transaction. |
572 """return a property to forward attribute access to transaction. |
550 |
573 |
551 This is to be used by session""" |
574 This is to be used by session""" |
690 self.id = _id or make_uid(unormalize(user.login).encode('UTF8')) |
713 self.id = _id or make_uid(unormalize(user.login).encode('UTF8')) |
691 self.user = user |
714 self.user = user |
692 self.repo = repo |
715 self.repo = repo |
693 self.timestamp = time() |
716 self.timestamp = time() |
694 self.default_mode = 'read' |
717 self.default_mode = 'read' |
695 # undo support |
|
696 if repo.config.creating or repo.config.repairing or self.is_internal_session: |
|
697 self.undo_actions = False |
|
698 else: |
|
699 self.undo_actions = repo.config['undo-enabled'] |
|
700 # short cut to querier .execute method |
718 # short cut to querier .execute method |
701 self._execute = repo.querier.execute |
719 self._execute = repo.querier.execute |
702 # shared data, used to communicate extra information between the client |
720 # shared data, used to communicate extra information between the client |
703 # and the rql server |
721 # and the rql server |
704 self.data = {} |
722 self.data = {} |
1348 pruned_hooks_cache = tx_attr('pruned_hooks_cache') |
1366 pruned_hooks_cache = tx_attr('pruned_hooks_cache') |
1349 add_operation = tx_meth('add_operation') |
1367 add_operation = tx_meth('add_operation') |
1350 |
1368 |
1351 # undo support ############################################################ |
1369 # undo support ############################################################ |
1352 |
1370 |
1353 def ertype_supports_undo(self, ertype): |
1371 ertype_supports_undo = tx_meth('ertype_supports_undo') |
1354 return self.undo_actions and ertype not in NO_UNDO_TYPES |
1372 transaction_inc_action_counter = tx_meth('transaction_inc_action_counter') |
1355 |
1373 |
1356 def transaction_uuid(self, set=True): |
1374 def transaction_uuid(self, set=True): |
1357 try: |
1375 try: |
1358 return self._tx.data['tx_uuid'] |
1376 return self._tx.transaction_uuid(set=set) |
1359 except KeyError: |
1377 except KeyError: |
1360 if not set: |
|
1361 return |
|
1362 self._tx.data['tx_uuid'] = uuid = uuid4().hex |
1378 self._tx.data['tx_uuid'] = uuid = uuid4().hex |
1363 self.repo.system_source.start_undoable_transaction(self, uuid) |
1379 self.repo.system_source.start_undoable_transaction(self, uuid) |
1364 return uuid |
1380 return uuid |
1365 |
|
1366 def transaction_inc_action_counter(self): |
|
1367 num = self._tx.data.setdefault('tx_action_count', 0) + 1 |
|
1368 self._tx.data['tx_action_count'] = num |
|
1369 return num |
|
1370 |
1381 |
1371 # querier helpers ######################################################### |
1382 # querier helpers ######################################################### |
1372 |
1383 |
1373 rql_rewriter = tx_attr('_rewriter') |
1384 rql_rewriter = tx_attr('_rewriter') |
1374 |
1385 |