[session] Kill support for a 'session_open' hook event
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 10 Mar 2017 18:25:35 +0100
changeset 12036 4c2c731f9190
parent 12035 2fcb9339f69a
child 12037 88bf0ec257b2
[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.
cubicweb/devtools/testlib.py
cubicweb/pyramid/core.py
cubicweb/server/hook.py
cubicweb/server/repository.py
cubicweb/server/test/data/hooks.py
cubicweb/server/test/unittest_hook.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
--- 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
 
 
--- 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
 
--- 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 ########################################################
--- 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
--- 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()