From 49546fe5c9f63d0ce85168dd6aa6b40a4f6d1a5c Mon Sep 17 00:00:00 2001 From: sniedzielski Date: Tue, 16 Apr 2024 14:58:22 +0200 Subject: [PATCH] CM-858: added possibility to configure default resolution times for each type of grievance --- README.md | 13 +++++++++ grievance_social_protection/apps.py | 43 ++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e69de29..a60f0ae 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,13 @@ +# openIMIS Backend Grievance Social Protection reference module +This repository holds the files of the openIMIS Backend grievance social protection reference module. +It is dedicated to be deployed as a module of [openimis-be_py](https://github.com/openimis/openimis-be_py). + +## Configuration options (can be changed via core.ModuleConfiguration) +Rights required: +* `resolution_times`: time to resolution in form of CRON timedelta: {days},{hours} where days are values between <0, 99) and hours are between 0 and 24. +(default: `5,0`) +* `default_resolution`: The field will be in form of the JSON dictionary with pairs like: +Key - type of the grievance, +Value - time to resolution in form of CRON timedelta: `{days},{hours}` where days are values between <0, 99) and hours are between 0 and 24. +(default: `{Default: '5,0'}`) +Note: If for given type of the grievance time is not provided then default value is used from `resolution_times`. diff --git a/grievance_social_protection/apps.py b/grievance_social_protection/apps.py index a3f8c33..73e8b45 100644 --- a/grievance_social_protection/apps.py +++ b/grievance_social_protection/apps.py @@ -7,6 +7,9 @@ MODULE_NAME = "grievance_social_protection" DEFAULT_STRING = 'Default' +# CRON timedelta: {days},{hours} +DEFAULT_TIME_RESOLUTION = '5,0' + DEFAULT_CFG = { "default_validations_disabled": False, @@ -24,7 +27,10 @@ "grievance_flags": [DEFAULT_STRING], "grievance_channels": [DEFAULT_STRING], "default_responses": {DEFAULT_STRING: DEFAULT_STRING}, - "grievance_anonymized_fields": {DEFAULT_STRING: []} + "grievance_anonymized_fields": {DEFAULT_STRING: []}, + # CRON timedelta: {days},{hours} + "resolution_times": DEFAULT_TIME_RESOLUTION, + "default_resolution": {DEFAULT_STRING: DEFAULT_TIME_RESOLUTION}, } @@ -46,12 +52,16 @@ class TicketConfig(AppConfig): grievance_channels = [] default_responses = {} grievance_anonymized_fields = {} + resolution_times = {} + default_resolution = {} def ready(self): from core.models import ModuleConfiguration cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG) self.__validate_grievance_dict_fields(cfg, 'default_responses') self.__validate_grievance_dict_fields(cfg, 'grievance_anonymized_fields') + self.__validate_grievance_dict_fields(cfg, 'default_resolution') + self.__validate_grievance_default_resolution_time(cfg) self.__load_config(cfg) @classmethod @@ -77,6 +87,37 @@ def get_grievance_type_options_msg(types): logger.warning('%s in %s not in grievance_types', field_key, field_name) get_grievance_type_options_msg(grievance_types) + @classmethod + def __validate_grievance_default_resolution_time(cls, cfg): + dict_field = cfg.get("default_resolution", {}) + if not dict_field: + return + for key in dict_field: + value = dict_field[key] + if value in ['', None]: + resolution_times = cfg.get("resolution_times", DEFAULT_TIME_RESOLUTION) + logger.warning( + '"%s" has no value for resolution. The default one is taken as "%s".', + key, + resolution_times + ) + dict_field[key] = resolution_times + else: + if ',' not in value: + logger.warning("Invalid input. Configuration should contain two integers " + "representing days and hours, separated by a comma.") + else: + parts = value.split(',') + # Parse days and hours + days = int(parts[0]) + hours = int(parts[1]) + # Validate days and hours + if 0 <= days < 99 and 0 <= hours < 24: + logger.info(f"Days: {days}, Hours: {hours}") + else: + logger.warning("Invalid input. Days must be between 0 and 99, " + "and hours must be between 0 and 24.") + @classmethod def __load_config(cls, cfg): """