diff --git a/grievance_social_protection/apps.py b/grievance_social_protection/apps.py index e43de98..d7e3348 100644 --- a/grievance_social_protection/apps.py +++ b/grievance_social_protection/apps.py @@ -1,7 +1,13 @@ +import logging + from django.apps import AppConfig +logger = logging.getLogger(__name__) + MODULE_NAME = "grievance_social_protection" +DEFAULT_STRING = 'Default' + DEFAULT_CFG = { "default_validations_disabled": False, "gql_query_tickets_perms": ["123000"], @@ -14,9 +20,10 @@ "gql_mutation_delete_categorys_perms": ["123007"], "tickets_attachments_root_path": None, - "grievance_types": ["Default"], - "grievance_flags": ["Default"], - "grievance_channels": ["Default"], + "grievance_types": [DEFAULT_STRING], + "grievance_flags": [DEFAULT_STRING], + "grievance_channels": [DEFAULT_STRING], + "default_responses": {'eloo': DEFAULT_STRING} } @@ -32,15 +39,41 @@ class TicketConfig(AppConfig): gql_mutation_update_categorys_perms = [] gql_mutation_delete_categorys_perms = [] tickets_attachments_root_path = None + grievance_types = [] grievance_flags = [] grievance_channels = [] + default_responses = {} def ready(self): from core.models import ModuleConfiguration cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG) + self.__validate_grievance_responses(cfg) self.__load_config(cfg) + @classmethod + def __validate_grievance_responses(cls, cfg): + def get_grievance_type_options_msg(types): + types_string = ", ".join(types) + return logger.info(f'Available grievance types: %s', types_string) + + default_responses = cfg.get('default_responses', {}) + if not default_responses: + return + + grievance_types = cfg.get('grievance_types', []) + if not grievance_types: + logger.warning('Please specify grievance_types if you want to setup default responses.') + + if not isinstance(default_responses, dict): + get_grievance_type_options_msg(grievance_types) + return + + for grievance_type_key in default_responses.keys(): + if grievance_type_key not in grievance_types: + logger.warning(f'%s not in grievance_types', grievance_type_key) + get_grievance_type_options_msg(grievance_types) + @classmethod def __load_config(cls, cfg): """