Skip to content

Commit

Permalink
CM-858: added possibility to configure default resolution times for e…
Browse files Browse the repository at this point in the history
…ach type of grievance
  • Loading branch information
sniedzielski committed Apr 16, 2024
1 parent 52ad87a commit 49546fe
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`.
43 changes: 42 additions & 1 deletion grievance_social_protection/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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},
}


Expand All @@ -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
Expand All @@ -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):
"""
Expand Down

0 comments on commit 49546fe

Please sign in to comment.