# HG changeset patch # User Sylvain Thénault # Date 1489166735 -3600 # Node ID 4c2c731f91909604c7b70337a5b66579de3a1732 # Parent 2fcb9339f69a464297505c821f4e141f6928e3e2 [session] Kill support for a 'session_open' hook event To be consistent with dropping of the 'session_close' event, and also because this is already not called when using pyramid. diff -r 2fcb9339f69a -r 4c2c731f9190 cubicweb/devtools/testlib.py --- a/cubicweb/devtools/testlib.py Fri Mar 10 17:03:28 2017 +0100 +++ b/cubicweb/devtools/testlib.py Fri Mar 10 18:25:35 2017 +0100 @@ -242,11 +242,6 @@ user.login session = Session(user, self._repo) user._cw = user.cw_rset.req = session - with session.new_cnx() as cnx: - self._repo.hm.call_hooks('session_open', cnx) - # commit connection at this point in case write operation has been - # done during `session_open` hooks - cnx.commit() return session @contextmanager diff -r 2fcb9339f69a -r 4c2c731f9190 cubicweb/pyramid/core.py --- a/cubicweb/pyramid/core.py Fri Mar 10 17:03:28 2017 +0100 +++ b/cubicweb/pyramid/core.py Fri Mar 10 18:25:35 2017 +0100 @@ -295,11 +295,6 @@ session = Session(request, user, repo) session._cached_lang = lang tools.cnx_attach_entity(session, user) - # Calling the hooks should be done only once, disabling it completely for - # now - # with session.new_cnx() as cnx: - # repo.hm.call_hooks('session_open', cnx) - # cnx.commit() return session diff -r 2fcb9339f69a -r 4c2c731f9190 cubicweb/server/hook.py --- a/cubicweb/server/hook.py Fri Mar 10 17:03:28 2017 +0100 +++ b/cubicweb/server/hook.py Fri Mar 10 18:25:35 2017 +0100 @@ -189,8 +189,6 @@ `server_restore`) have a `repo` and a `timestamp` attributes, but *their `_cw` attribute is None*. -Hooks called on session event (`session_open`) have no special attribute. - API --- @@ -271,8 +269,7 @@ 'before_delete_relation','after_delete_relation')) SYSTEM_HOOKS = set(('server_backup', 'server_restore', 'server_startup', 'server_maintenance', - 'server_shutdown', 'before_server_shutdown', - 'session_open',)) + 'server_shutdown', 'before_server_shutdown',)) ALL_HOOKS = ENTITIES_HOOKS | RELATIONS_HOOKS | SYSTEM_HOOKS diff -r 2fcb9339f69a -r 4c2c731f9190 cubicweb/server/repository.py --- a/cubicweb/server/repository.py Fri Mar 10 17:03:28 2017 +0100 +++ b/cubicweb/server/repository.py Fri Mar 10 18:25:35 2017 +0100 @@ -656,11 +656,6 @@ user._cw = user.cw_rset.req = session user.cw_clear_relation_cache() self.info('opened session %s for user %s', session, login) - with session.new_cnx() as cnx: - self.hm.call_hooks('session_open', cnx) - # commit connection at this point in case write operation has been - # done during `session_open` hooks - cnx.commit() return session # session handling ######################################################## diff -r 2fcb9339f69a -r 4c2c731f9190 cubicweb/server/test/data/hooks.py --- a/cubicweb/server/test/data/hooks.py Fri Mar 10 17:03:28 2017 +0100 +++ b/cubicweb/server/test/data/hooks.py Fri Mar 10 18:25:35 2017 +0100 @@ -35,11 +35,3 @@ def __call__(self): CALLED_EVENTS['server_shutdown'] = True - - -class LoginHook(Hook): - __regid__ = 'mylogin' - events = ('session_open',) - - def __call__(self): - CALLED_EVENTS['session_open'] = self._cw.user.login diff -r 2fcb9339f69a -r 4c2c731f9190 cubicweb/server/test/unittest_hook.py --- a/cubicweb/server/test/unittest_hook.py Fri Mar 10 17:03:28 2017 +0100 +++ b/cubicweb/server/test/unittest_hook.py Fri Mar 10 18:25:35 2017 +0100 @@ -134,12 +134,6 @@ self.repo.hm.call_hooks('server_shutdown', repo=self.repo) self.assertEqual(hooks.CALLED_EVENTS['server_shutdown'], True) - def test_session_open_close(self): - import hooks # cubicweb/server/test/data/hooks.py - anonaccess = self.new_access('anon') - with anonaccess.repo_cnx() as cnx: - self.assertEqual(hooks.CALLED_EVENTS['session_open'], 'anon') - if __name__ == '__main__': unittest.main()