Skip to content

Commit

Permalink
CM-856: add default responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Apr 8, 2024
1 parent d325bcd commit 98c4d15
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions grievance_social_protection/apps.py
Original file line number Diff line number Diff line change
@@ -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"],
Expand All @@ -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}
}


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

0 comments on commit 98c4d15

Please sign in to comment.