From 5209ea762b0813f88979fe0fbb8cee92d7f5cebd Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Thu, 5 Jun 2014 16:30:38 -0600 Subject: [PATCH] Add a way to disable a backend alltogether. Fixes fedora-infra/fmn.consumer#3. --- fmn/lib/__init__.py | 6 +++++- fmn/lib/tests/__init__.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fmn/lib/__init__.py b/fmn/lib/__init__.py index 7a9078d..f70715e 100644 --- a/fmn/lib/__init__.py +++ b/fmn/lib/__init__.py @@ -90,10 +90,14 @@ def matches(filter, message, valid_paths, config): def load_preferences(session, config, valid_paths): """ Every rule for every filter for every context for every user. + Any preferences in the DB that are for contexts that are disabled in the + config are omitted here. + This is an expensive query that loads, practically, the whole database. """ preferences = session.query(fmn.lib.models.Preference).all() - return [preference.__json__() for preference in preferences] + return [preference.__json__() for preference in preferences + if preference.context.name in config['fmn.backends']] def load_rules(root='fmn.rules'): diff --git a/fmn/lib/tests/__init__.py b/fmn/lib/tests/__init__.py index a43cbe8..4f91a67 100644 --- a/fmn/lib/tests/__init__.py +++ b/fmn/lib/tests/__init__.py @@ -11,7 +11,9 @@ def setUp(self): os.unlink(dbfile) self.sess = fmn.lib.models.init(DB_PATH, debug=False, create=True) - self.config = {} + self.config = { + 'fmn.backends': ['irc', 'email', 'android'], + } self.valid_paths = fmn.lib.load_rules( root='fmn.lib.tests.example_rules')