From 948f37afd451f4ca580b96fc00cdba4d3892da8b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 7 Apr 2022 01:04:06 +0200 Subject: [PATCH] Filter by configured/enabled plugins when returning the entity/plugin registry --- platypush/entities/_registry.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/platypush/entities/_registry.py b/platypush/entities/_registry.py index 53d87234c..162a1a2f5 100644 --- a/platypush/entities/_registry.py +++ b/platypush/entities/_registry.py @@ -2,6 +2,7 @@ import json from datetime import datetime from typing import Optional, Dict, Collection, Type +from platypush.config import Config from platypush.plugins import Plugin from platypush.utils import get_plugin_name_by_class, get_redis @@ -30,10 +31,24 @@ def get_plugin_entity_registry() -> Dict[str, Dict[str, Collection[str]]]: redis = get_redis() registry = redis.mget([_entity_registry_varname])[0] try: - return json.loads((registry or b'').decode()) + registry = json.loads((registry or b'').decode()) except (TypeError, ValueError): return {'by_plugin': {}, 'by_entity_type': {}} + enabled_plugins = set(Config.get_plugins().keys()) + + return { + 'by_plugin': { + plugin_name: entity_types + for plugin_name, entity_types in registry['by_plugin'].items() + if plugin_name in enabled_plugins + }, + 'by_entity_type': { + entity_type: [p for p in plugins if p in enabled_plugins] + for entity_type, plugins in registry['by_entity_type'].items() + }, + } + class EntityManagerMixin: def transform_entities(self, entities):