Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CM-857: add grievance_anonymized_fields #7

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions grievance_social_protection/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"grievance_types": [DEFAULT_STRING],
"grievance_flags": [DEFAULT_STRING],
"grievance_channels": [DEFAULT_STRING],
"default_responses": {'eloo': DEFAULT_STRING}
"default_responses": {DEFAULT_STRING: DEFAULT_STRING},
"grievance_anonymized_fields": {DEFAULT_STRING: []}
}


Expand All @@ -44,34 +45,36 @@ class TicketConfig(AppConfig):
grievance_flags = []
grievance_channels = []
default_responses = {}
grievance_anonymized_fields = {}

def ready(self):
from core.models import ModuleConfiguration
cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG)
self.__validate_grievance_responses(cfg)
self.__validate_grievance_dict_fields(cfg, 'default_responses')
self.__validate_grievance_dict_fields(cfg, 'grievance_anonymized_fields')
self.__load_config(cfg)

@classmethod
def __validate_grievance_responses(cls, cfg):
def __validate_grievance_dict_fields(cls, cfg, field_name):
def get_grievance_type_options_msg(types):
types_string = ", ".join(types)
return logger.info(f'Available grievance types: %s', types_string)
return logger.info(f'Available grievance types: {types_string}')

default_responses = cfg.get('default_responses', {})
if not default_responses:
dict_field = cfg.get(field_name, {})
if not dict_field:
return

grievance_types = cfg.get('grievance_types', [])
if not grievance_types:
logger.warning('Please specify grievance_types if you want to setup default responses.')
logger.warning('Please specify grievance_types if you want to setup %s.', field_name)

if not isinstance(default_responses, dict):
if not isinstance(dict_field, 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)
for field_key in dict_field.keys():
if field_key not in grievance_types:
logger.warning('%s in %s not in grievance_types', field_key, field_name)
get_grievance_type_options_msg(grievance_types)

@classmethod
Expand Down
Loading