[saem-devel] [PATCH 04 of 10] [migration] Backport patch for cubicweb's #17049333

saem-devel at lists.cubicweb.org saem-devel at lists.cubicweb.org
Wed Jan 25 10:05:02 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1485268131 -3600
#      Tue Jan 24 15:28:51 2017 +0100
# Node ID c54305d4d23506851abf5a69f2c6f11f0756bb75
# Parent  c74e3dc65e7735fd7e9a56fece49d1d05527d859
[migration] Backport patch for cubicweb's #17049333

Necessary for the 0.14 migration.

diff --git a/site_cubicweb.py b/site_cubicweb.py
--- a/site_cubicweb.py
+++ b/site_cubicweb.py
@@ -161,3 +161,46 @@ def deserialize(cls, value):
             msg = None
         op, boundary = value.split(' ', 1)
         return cls(op, eval(boundary), msg or None)
+
+
+# proper behaviour of hooks control cm (https://www.cubicweb.org/ticket/17049333)
+
+from cubicweb.server import session  # noqa
+
+
+ at monkeypatch(session)
+class _hooks_control(object):
+    def __init__(self, cnx, mode, *categories):
+        assert mode in (session.HOOKS_ALLOW_ALL, session.HOOKS_DENY_ALL)
+        self.cnx = cnx
+        self.mode = mode
+        self.categories = set(categories)
+        self.old_mode = None
+        self.old_categories = None
+
+    def __enter__(self):
+        self.old_mode = self.cnx._hooks_mode
+        self.old_categories = self.cnx._hooks_categories
+        self.cnx._hooks_mode = self.mode
+        self.cnx._hooks_categories = self.categories
+
+    def __exit__(self, exctype, exc, traceback):
+        self.cnx._hooks_mode = self.old_mode
+        self.cnx._hooks_categories = self.old_categories
+
+
+orig_connection_init = session.Connection.__init__
+
+
+ at monkeypatch(session.Connection)
+def __init__(self, *args, **kwargs):
+    orig_connection_init(self, *args, **kwargs)
+    self._hooks_mode = session.HOOKS_ALLOW_ALL
+    self._hooks_categories = set()
+
+
+ at monkeypatch(session.Connection)
+def is_hook_category_activated(self, category):
+    if self._hooks_mode is session.HOOKS_DENY_ALL:
+        return category in self._hooks_categories
+    return category not in self._hooks_categories


More information about the saem-devel mailing list