From d0fa8dbea8576587f03903a44e4d7f48d5929064 Mon Sep 17 00:00:00 2001 From: kououken Date: Fri, 1 Mar 2019 14:11:05 -0800 Subject: [PATCH 1/2] Added error-checking when accessing policy file to catch changes. --- back/.env | 4 --- back/backend/views.py | 58 +++++++++++++++++++++++------------------- back/db.sqlite3 | Bin 197632 -> 197632 bytes 3 files changed, 32 insertions(+), 30 deletions(-) delete mode 100644 back/.env diff --git a/back/.env b/back/.env deleted file mode 100644 index b47f7a4..0000000 --- a/back/.env +++ /dev/null @@ -1,4 +0,0 @@ -EMAIL_HOST_USER=accountemail@yourmail.com -EMAIL_HOST_PASSWORD=accountpasswordhere -SUBMIT_REPORT_DESTINATION_EMAIL=to-address@yourmail.com -SUBMIT_REPORT_FROM_EMAIL=from-address@yourmail.com diff --git a/back/backend/views.py b/back/backend/views.py index 1d55aec..3d62b6b 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -52,19 +52,22 @@ def get_sections(r_id): data.update(get_fields(i.id)) # process rules from the policy file if the section is completed if i.completed: - rules = pol.sections[index].rules - for rule in rules: - try: - named_fields = generate_named_fields_for_section(data['fields']) - result = rule['rule'](data, named_fields) - if not result is None: - info = { - "label": rule['title'], - "rule_break_text": result, - } - data['rule_violations'].append(info) - except Exception as e: - print('Rule "{}" encountered an error. {}'.format(rule['title'], e)) + try: + rules = pol.sections[index].rules + for rule in rules: + try: + named_fields = generate_named_fields_for_section(data['fields']) + result = rule['rule'](data, named_fields) + if not result is None: + info = { + "label": rule['title'], + "rule_break_text": result, + } + data['rule_violations'].append(info) + except Exception as e: + print('Rule "{}" encountered an error. {}'.format(rule['title'], e)) + except Exception as e: + print('Error accessing policy section {}. Policy file may have changed.'.format(index)) # append section to the array section_set["sections"].append(data.copy()) @@ -339,19 +342,22 @@ def section(request, report_pk, section_pk): data.update(get_fields(s.id)) # process rules from the policy file if the section is completed if s.completed: - rules = pol.sections[s.number].rules - for rule in rules: - try: - named_fields = generate_named_fields_for_section(data['fields']) - result = rule['rule'](data, named_fields) - if not result is None: - info = { - "label": rule['title'], - "rule_break_text": result, - } - data['rule_violations'].append(info) - except Exception as e: - print('Rule "{}" encountered an error. {}'.format(rule['title'], e)) + try: + rules = pol.sections[s.number].rules + for rule in rules: + try: + named_fields = generate_named_fields_for_section(data['fields']) + result = rule['rule'](data, named_fields) + if not result is None: + info = { + "label": rule['title'], + "rule_break_text": result, + } + data['rule_violations'].append(info) + except Exception as e: + print('Rule "{}" encountered an error. {}'.format(rule['title'], e)) + except Exception as e: + print('Error accessing policy section {}. Policy file may have been changed.'.format(s.number)) return JsonResponse(data) def section_complete(section_pk): diff --git a/back/db.sqlite3 b/back/db.sqlite3 index e1d41596d7922b7a3494ee4a62a36f8929456c47..96f3158f2c75f42a40a8a0769a1214b25d2ea375 100644 GIT binary patch delta 2422 zcmeH|Sxi({7=Z8j{{e@QMHaQnHUlCcgWh4-MPyLWTBbysZpJ!ZhD#j5nPFzAV%x~L zocLl2!Fc*WV==`V^+BBkn%1=P!Xhw88ck}`HYV0SG&R4(CK0cK9cZJ z$nep9G{ztyU^egs#^I=hf8qoD1@GYZcoS!F0!RB74Xg;&4je{jEb@s`Si_8lX$?~v zu4$OmFri^w!&m}8Vj&?Ceu-^Z29IGDdcaC%$pG2P%@?HoQf;4YIabgD<~;xfDHE-# zSMde9e5#{W38)sD&ys$Eyrc=A%8l-*aT{I9Y;{mYCRp<+@)Fu<9; zbOoF1gqoyrztg9xZvSpi0A!lWuD=JSl=0_JP-qV8ISGwqoRK(Kj$5dS)zxz!$623B zmS7V#GMf|1`Saj+eDhT_n>BYrR?_%09+lH9*6W14v}aC?x{9l5COcjarbXi&o_(r6 z;Am5Ps%{(2U{`lQ4c|1|0E@Anrn9UnsK^{s+5)Q25%9UZF+6mL_qdjZ@DV=5d;KY& zp21zg&8+VW;)pRHst;}o83%17&U`pM*l3XS`jG4NQIf$|c!PGXJ;5zp?+9*+q=Dd= zgkvGY*()elniohWtDab!J6eretCq-?s$$t%EL)6nWwk8x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ted '.env' file. Whoops! --- back/.env | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 back/.env diff --git a/back/.env b/back/.env new file mode 100644 index 0000000..b47f7a4 --- /dev/null +++ b/back/.env @@ -0,0 +1,4 @@ +EMAIL_HOST_USER=accountemail@yourmail.com +EMAIL_HOST_PASSWORD=accountpasswordhere +SUBMIT_REPORT_DESTINATION_EMAIL=to-address@yourmail.com +SUBMIT_REPORT_FROM_EMAIL=from-address@yourmail.com