Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Create helper function for resolver of plugin configuration

Maciej Korycinski20a5fd826340
diff --git a/saleor/graphql/extensions/types.py b/saleor/graphql/extensions/types.py
index 662d730e31..8c98b0e03e 100644
--- a/saleor/graphql/extensions/types.py
+++ b/saleor/graphql/extensions/types.py
@@ -5,6 +5,25 @@ from ..core.connection import CountableDjangoObjectType
from .enums import ConfigurationTypeFieldEnum
+def hide_private_configuration_fields(configuration, config_structure):
+ for field in configuration:
+ name = field["name"]
+ value = field["value"]
+ if value is None:
+ continue
+ field_type = config_structure.get(name, {}).get("type")
+ if field_type == ConfigurationTypeField.PASSWORD:
+ field["value"] = "" if value else None
+
+ if field_type == ConfigurationTypeField.SECRET:
+ if not value:
+ field["value"] = None
+ elif len(value) > 4:
+ field["value"] = value[-4:]
+ else:
+ field["value"] = value[-1:]
+
+
class ConfigurationItem(graphene.ObjectType):
name = graphene.String(required=True, description="Name of the field.")
value = graphene.String(required=False, description="Current value of the field.")
@@ -25,24 +44,10 @@ class Plugin(CountableDjangoObjectType):
interfaces = [graphene.relay.Node]
only_fields = ["name", "description", "active", "configuration"]
- def resolve_configuration(self, _info):
- plugin = manager.get_extensions_manager().get_plugin(self.name)
+ @staticmethod
+ def resolve_configuration(root: models.PluginConfiguration, _info):
+ plugin = manager.get_extensions_manager().get_plugin(root.name)
configuration = plugin.get_plugin_configuration().configuration
if plugin.CONFIG_STRUCTURE and configuration:
- for field in configuration:
- name = field["name"]
- value = field["value"]
- if value is None:
- continue
- field_type = plugin.CONFIG_STRUCTURE.get(name, {}).get("type")
- if field_type == ConfigurationTypeField.PASSWORD:
- field["value"] = "" if value else None
-
- if field_type == ConfigurationTypeField.SECRET:
- if not value:
- field["value"] = None
- elif len(value) > 4:
- field["value"] = value[-4:]
- else:
- field["value"] = value[-1:]
+ hide_private_configuration_fields(configuration, plugin.CONFIG_STRUCTURE)
return configuration