[repo] make it clear in internal_cnx that security is disabled
as explained in its docstring. It was previously relying on internal
connection's fake user (InternalManager) for read security and on disabling
security hooks for write security. Using the security_enabled context manager is
more readable and more reliable: while the older implementation works thanks to
the InternalManager associated to the session, custom hooks should rely
on session.[read|write]_security being correctly set. This change also
allows selecting Password attributes in internal connections without
explicitly disabling read security.
--- a/server/repository.py Fri Apr 04 18:23:02 2014 +0200
+++ b/server/repository.py Wed Apr 09 17:15:25 2014 +0200
@@ -909,24 +909,18 @@
@contextmanager
def internal_cnx(self):
- """return a Connection using internal user which have
- every rights on the repository. The `safe` argument is dropped. all
- hook are enabled by default.
+ """Context manager returning a Connection using internal user which have
+ every access rights on the repository.
- /!\ IN OPPOSITE OF THE OLDER INTERNAL_SESSION,
- /!\ INTERNAL CONNECTION HAVE ALL HOOKS ENABLED.
-
- This is to be used a context manager.
+ Beware that unlike the older :meth:`internal_session`, internal
+ connections have all hooks beside security enabled.
"""
with InternalSession(self) as session:
with session.new_cnx() as cnx:
- # equivalent to cnx.security_enabled(False, False) because
- # InternalSession gives full read access
- with cnx.allow_all_hooks_but('security'):
+ with cnx.security_enabled(read=False, write=False):
with cnx.ensure_cnx_set:
yield cnx
-
def _get_session(self, sessionid, setcnxset=False, txid=None,
checkshuttingdown=True):
"""return the session associated with the given session identifier"""