Skip to content

Commit

Permalink
Merge pull request #908 from uktrade/LTD-1676-notes-timeline-updates
Browse files Browse the repository at this point in the history
Update timeline text for Advice 2.0
  • Loading branch information
wkeeling authored Jan 25, 2022
2 parents cc40218 + 2acfbe7 commit 1a95567
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 12 deletions.
1 change: 1 addition & 0 deletions api/audit_trail/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class AuditType(LiteEnum):
CLEARED_FINAL_ADVICE = autostr()
CREATED_TEAM_ADVICE = autostr()
CLEARED_TEAM_ADVICE = autostr()
REVIEW_COMBINE_ADVICE = autostr()
CREATED_USER_ADVICE = autostr()
CLEARED_USER_ADVICE = autostr()
ADD_PARTY = autostr()
Expand Down
247 changes: 247 additions & 0 deletions api/audit_trail/migrations/0005_auto_20220124_1538.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
# Generated by Django 3.1.13 on 2022-01-24 15:38

import api.audit_trail.enums
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("audit_trail", "0004_auto_20211101_1242"),
]

operations = [
migrations.AlterField(
model_name="audit",
name="verb",
field=models.CharField(
choices=[
(api.audit_trail.enums.AuditType["CREATED"], "created"),
(api.audit_trail.enums.AuditType["OGL_CREATED"], "ogl_created"),
(api.audit_trail.enums.AuditType["OGL_FIELD_EDITED"], "ogl_field_edited"),
(api.audit_trail.enums.AuditType["OGL_MULTI_FIELD_EDITED"], "ogl_multi_field_edited"),
(api.audit_trail.enums.AuditType["ADD_FLAGS"], "add_flags"),
(api.audit_trail.enums.AuditType["REMOVE_FLAGS"], "remove_flags"),
(api.audit_trail.enums.AuditType["GOOD_REVIEWED"], "good_reviewed"),
(api.audit_trail.enums.AuditType["GOOD_ADD_FLAGS"], "good_add_flags"),
(api.audit_trail.enums.AuditType["GOOD_REMOVE_FLAGS"], "good_remove_flags"),
(api.audit_trail.enums.AuditType["GOOD_ADD_REMOVE_FLAGS"], "good_add_remove_flags"),
(api.audit_trail.enums.AuditType["DESTINATION_ADD_FLAGS"], "destination_add_flags"),
(api.audit_trail.enums.AuditType["DESTINATION_REMOVE_FLAGS"], "destination_remove_flags"),
(api.audit_trail.enums.AuditType["ADD_GOOD_TO_APPLICATION"], "add_good_to_application"),
(api.audit_trail.enums.AuditType["REMOVE_GOOD_FROM_APPLICATION"], "remove_good_from_application"),
(api.audit_trail.enums.AuditType["ADD_GOOD_TYPE_TO_APPLICATION"], "add_good_type_to_application"),
(
api.audit_trail.enums.AuditType["REMOVE_GOOD_TYPE_FROM_APPLICATION"],
"remove_good_type_from_application",
),
(
api.audit_trail.enums.AuditType["UPDATE_APPLICATION_END_USE_DETAIL"],
"update_application_end_use_detail",
),
(
api.audit_trail.enums.AuditType["UPDATE_APPLICATION_TEMPORARY_EXPORT"],
"update_application_temporary_export",
),
(
api.audit_trail.enums.AuditType["REMOVED_SITES_FROM_APPLICATION"],
"removed_sites_from_application",
),
(api.audit_trail.enums.AuditType["ADD_SITES_TO_APPLICATION"], "add_sites_to_application"),
(
api.audit_trail.enums.AuditType["REMOVED_EXTERNAL_LOCATIONS_FROM_APPLICATION"],
"removed_external_locations_from_application",
),
(
api.audit_trail.enums.AuditType["ADD_EXTERNAL_LOCATIONS_TO_APPLICATION"],
"add_external_locations_to_application",
),
(
api.audit_trail.enums.AuditType["REMOVED_COUNTRIES_FROM_APPLICATION"],
"removed_countries_from_application",
),
(api.audit_trail.enums.AuditType["ADD_COUNTRIES_TO_APPLICATION"], "add_countries_to_application"),
(
api.audit_trail.enums.AuditType["ADD_ADDITIONAL_CONTACT_TO_CASE"],
"add_additional_contact_to_case",
),
(api.audit_trail.enums.AuditType["MOVE_CASE"], "move_case"),
(api.audit_trail.enums.AuditType["ASSIGN_CASE"], "assign_case"),
(api.audit_trail.enums.AuditType["ASSIGN_USER_TO_CASE"], "assign_user_to_case"),
(api.audit_trail.enums.AuditType["REMOVE_CASE"], "remove_case"),
(api.audit_trail.enums.AuditType["REMOVE_CASE_FROM_ALL_QUEUES"], "remove_case_from_all_queues"),
(
api.audit_trail.enums.AuditType["REMOVE_CASE_FROM_ALL_USER_ASSIGNMENTS"],
"remove_case_from_all_user_assignments",
),
(api.audit_trail.enums.AuditType["CLC_RESPONSE"], "clc_response"),
(api.audit_trail.enums.AuditType["PV_GRADING_RESPONSE"], "pv_grading_response"),
(api.audit_trail.enums.AuditType["CREATED_CASE_NOTE"], "created_case_note"),
(api.audit_trail.enums.AuditType["ECJU_QUERY"], "ecju_query"),
(api.audit_trail.enums.AuditType["UPDATED_STATUS"], "updated_status"),
(api.audit_trail.enums.AuditType["UPDATED_APPLICATION_NAME"], "updated_application_name"),
(
api.audit_trail.enums.AuditType["UPDATE_APPLICATION_LETTER_REFERENCE"],
"update_application_letter_reference",
),
(
api.audit_trail.enums.AuditType["UPDATE_APPLICATION_F680_CLEARANCE_TYPES"],
"update_application_f680_clearance_types",
),
(
api.audit_trail.enums.AuditType["ADDED_APPLICATION_LETTER_REFERENCE"],
"added_application_letter_reference",
),
(
api.audit_trail.enums.AuditType["REMOVED_APPLICATION_LETTER_REFERENCE"],
"removed_application_letter_reference",
),
(api.audit_trail.enums.AuditType["ASSIGNED_COUNTRIES_TO_GOOD"], "assigned_countries_to_good"),
(api.audit_trail.enums.AuditType["REMOVED_COUNTRIES_FROM_GOOD"], "removed_countries_from_good"),
(api.audit_trail.enums.AuditType["CREATED_FINAL_ADVICE"], "created_final_advice"),
(api.audit_trail.enums.AuditType["CLEARED_FINAL_ADVICE"], "cleared_final_advice"),
(api.audit_trail.enums.AuditType["CREATED_TEAM_ADVICE"], "created_team_advice"),
(api.audit_trail.enums.AuditType["CLEARED_TEAM_ADVICE"], "cleared_team_advice"),
(api.audit_trail.enums.AuditType["REVIEW_COMBINE_ADVICE"], "review_combine_advice"),
(api.audit_trail.enums.AuditType["CREATED_USER_ADVICE"], "created_user_advice"),
(api.audit_trail.enums.AuditType["CLEARED_USER_ADVICE"], "cleared_user_advice"),
(api.audit_trail.enums.AuditType["ADD_PARTY"], "add_party"),
(api.audit_trail.enums.AuditType["REMOVE_PARTY"], "remove_party"),
(api.audit_trail.enums.AuditType["UPLOAD_PARTY_DOCUMENT"], "upload_party_document"),
(api.audit_trail.enums.AuditType["DELETE_PARTY_DOCUMENT"], "delete_party_document"),
(api.audit_trail.enums.AuditType["UPLOAD_APPLICATION_DOCUMENT"], "upload_application_document"),
(api.audit_trail.enums.AuditType["DELETE_APPLICATION_DOCUMENT"], "delete_application_document"),
(api.audit_trail.enums.AuditType["UPLOAD_CASE_DOCUMENT"], "upload_case_document"),
(api.audit_trail.enums.AuditType["GENERATE_CASE_DOCUMENT"], "generate_case_document"),
(api.audit_trail.enums.AuditType["ADD_CASE_OFFICER_TO_CASE"], "add_case_officer_to_case"),
(api.audit_trail.enums.AuditType["REMOVE_CASE_OFFICER_FROM_CASE"], "remove_case_officer_from_case"),
(api.audit_trail.enums.AuditType["GRANTED_APPLICATION"], "granted_application"),
(api.audit_trail.enums.AuditType["REINSTATED_APPLICATION"], "reinstated_application"),
(api.audit_trail.enums.AuditType["FINALISED_APPLICATION"], "finalised_application"),
(api.audit_trail.enums.AuditType["UNASSIGNED_QUEUES"], "unassigned_queues"),
(api.audit_trail.enums.AuditType["UNASSIGNED"], "unassigned"),
(api.audit_trail.enums.AuditType["CREATED_DOCUMENT_TEMPLATE"], "created_document_template"),
(api.audit_trail.enums.AuditType["UPDATED_LETTER_TEMPLATE_NAME"], "updated_letter_template_name"),
(
api.audit_trail.enums.AuditType["ADDED_LETTER_TEMPLATE_CASE_TYPES"],
"added_letter_template_case_types",
),
(
api.audit_trail.enums.AuditType["UPDATED_LETTER_TEMPLATE_CASE_TYPES"],
"updated_letter_template_case_types",
),
(
api.audit_trail.enums.AuditType["REMOVED_LETTER_TEMPLATE_CASE_TYPES"],
"removed_letter_template_case_types",
),
(
api.audit_trail.enums.AuditType["ADDED_LETTER_TEMPLATE_DECISIONS"],
"added_letter_template_decisions",
),
(
api.audit_trail.enums.AuditType["UPDATED_LETTER_TEMPLATE_DECISIONS"],
"updated_letter_template_decisions",
),
(
api.audit_trail.enums.AuditType["REMOVED_LETTER_TEMPLATE_DECISIONS"],
"removed_letter_template_decisions",
),
(
api.audit_trail.enums.AuditType["UPDATED_LETTER_TEMPLATE_PARAGRAPHS"],
"updated_letter_template_paragraphs",
),
(
api.audit_trail.enums.AuditType["REMOVED_LETTER_TEMPLATE_PARAGRAPHS"],
"removed_letter_template_paragraphs",
),
(
api.audit_trail.enums.AuditType["ADDED_LETTER_TEMPLATE_PARAGRAPHS"],
"added_letter_template_paragraphs",
),
(
api.audit_trail.enums.AuditType["UPDATED_LETTER_TEMPLATE_LAYOUT"],
"updated_letter_template_layout",
),
(
api.audit_trail.enums.AuditType["UPDATED_LETTER_TEMPLATE_PARAGRAPHS_ORDERING"],
"updated_letter_template_paragraphs_ordering",
),
(
api.audit_trail.enums.AuditType["UPDATED_LETTER_TEMPLATE_INCLUDE_DIGITAL_SIGNATURE"],
"updated_letter_template_include_digital_signature",
),
(api.audit_trail.enums.AuditType["CREATED_PICKLIST"], "created_picklist"),
(api.audit_trail.enums.AuditType["UPDATED_PICKLIST_TEXT"], "updated_picklist_text"),
(api.audit_trail.enums.AuditType["UPDATED_PICKLIST_NAME"], "updated_picklist_name"),
(api.audit_trail.enums.AuditType["DEACTIVATE_PICKLIST"], "deactivate_picklist"),
(api.audit_trail.enums.AuditType["REACTIVATE_PICKLIST"], "reactivate_picklist"),
(
api.audit_trail.enums.AuditType["UPDATED_EXHIBITION_DETAILS_TITLE"],
"updated_exhibition_details_title",
),
(
api.audit_trail.enums.AuditType["UPDATED_EXHIBITION_DETAILS_START_DATE"],
"updated_exhibition_details_start_date",
),
(
api.audit_trail.enums.AuditType["UPDATED_EXHIBITION_DETAILS_REQUIRED_BY_DATE"],
"updated_exhibition_details_required_by_date",
),
(
api.audit_trail.enums.AuditType["UPDATED_EXHIBITION_DETAILS_REASON_FOR_CLEARANCE"],
"updated_exhibition_details_reason_for_clearance",
),
(api.audit_trail.enums.AuditType["UPDATED_ROUTE_OF_GOODS"], "updated_route_of_goods"),
(api.audit_trail.enums.AuditType["UPDATED_ORGANISATION"], "updated_organisation"),
(api.audit_trail.enums.AuditType["CREATED_ORGANISATION"], "created_organisation"),
(api.audit_trail.enums.AuditType["REGISTER_ORGANISATION"], "register_organisation"),
(api.audit_trail.enums.AuditType["REJECTED_ORGANISATION"], "rejected_organisation"),
(api.audit_trail.enums.AuditType["APPROVED_ORGANISATION"], "approved_organisation"),
(api.audit_trail.enums.AuditType["REMOVED_FLAG_ON_ORGANISATION"], "removed_flag_on_organisation"),
(api.audit_trail.enums.AuditType["ADDED_FLAG_ON_ORGANISATION"], "added_flag_on_organisation"),
(api.audit_trail.enums.AuditType["RERUN_ROUTING_RULES"], "rerun_routing_rules"),
(api.audit_trail.enums.AuditType["ENFORCEMENT_CHECK"], "enforcement_check"),
(api.audit_trail.enums.AuditType["UPDATED_SITE"], "updated_site"),
(api.audit_trail.enums.AuditType["CREATED_SITE"], "created_site"),
(api.audit_trail.enums.AuditType["UPDATED_SITE_NAME"], "updated_site_name"),
(api.audit_trail.enums.AuditType["COMPLIANCE_SITE_CASE_CREATE"], "compliance_site_case_create"),
(
api.audit_trail.enums.AuditType["COMPLIANCE_SITE_CASE_NEW_LICENCE"],
"compliance_site_case_new_licence",
),
(api.audit_trail.enums.AuditType["ADDED_NEXT_REVIEW_DATE"], "added_next_review_date"),
(api.audit_trail.enums.AuditType["EDITED_NEXT_REVIEW_DATE"], "edited_next_review_date"),
(api.audit_trail.enums.AuditType["REMOVED_NEXT_REVIEW_DATE"], "removed_next_review_date"),
(api.audit_trail.enums.AuditType["COMPLIANCE_VISIT_CASE_CREATED"], "compliance_visit_case_created"),
(api.audit_trail.enums.AuditType["COMPLIANCE_VISIT_CASE_UPDATED"], "compliance_visit_case_updated"),
(
api.audit_trail.enums.AuditType["COMPLIANCE_PEOPLE_PRESENT_CREATED"],
"compliance_people_present_created",
),
(
api.audit_trail.enums.AuditType["COMPLIANCE_PEOPLE_PRESENT_UPDATED"],
"compliance_people_present_updated",
),
(
api.audit_trail.enums.AuditType["COMPLIANCE_PEOPLE_PRESENT_DELETED"],
"compliance_people_present_deleted",
),
(
api.audit_trail.enums.AuditType["UPDATED_GOOD_ON_DESTINATION_MATRIX"],
"updated_good_on_destination_matrix",
),
(api.audit_trail.enums.AuditType["LICENCE_UPDATED_GOOD_USAGE"], "licence_updated_good_usage"),
(api.audit_trail.enums.AuditType["OGEL_REISSUED"], "ogel_reissued"),
(api.audit_trail.enums.AuditType["LICENCE_UPDATED_STATUS"], "licence_updated_status"),
(
api.audit_trail.enums.AuditType["DOCUMENT_ON_ORGANISATION_CREATE"],
"document_on_organisation_create",
),
(api.audit_trail.enums.AuditType["REPORT_SUMMARY_UPDATED"], "report_summary_updated"),
(api.audit_trail.enums.AuditType["COUNTERSIGN_ADVICE"], "countersign_advice"),
],
db_index=True,
max_length=255,
),
),
]
11 changes: 6 additions & 5 deletions api/audit_trail/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ def format_payload(audit_type, payload):
AuditType.REMOVED_APPLICATION_LETTER_REFERENCE: strings.Audit.REMOVED_APPLICATION_LETTER_REFERENCE,
AuditType.ASSIGNED_COUNTRIES_TO_GOOD: strings.Audit.ASSIGNED_COUNTRIES_TO_GOOD,
AuditType.REMOVED_COUNTRIES_FROM_GOOD: strings.Audit.REMOVED_COUNTRIES_FROM_GOOD,
AuditType.CREATED_FINAL_ADVICE: strings.Audit.CREATED_FINAL_ADVICE,
AuditType.CLEARED_FINAL_ADVICE: strings.Audit.CLEARED_FINAL_ADVICE,
AuditType.CREATED_FINAL_ADVICE: "added a decision",
AuditType.CLEARED_FINAL_ADVICE: "cleared their decision",
AuditType.CREATED_TEAM_ADVICE: strings.Audit.CREATED_TEAM_ADVICE,
AuditType.CLEARED_TEAM_ADVICE: strings.Audit.CLEARED_TEAM_ADVICE,
AuditType.CREATED_USER_ADVICE: strings.Audit.CREATED_USER_ADVICE,
AuditType.CLEARED_USER_ADVICE: "cleared user advice",
AuditType.REVIEW_COMBINE_ADVICE: "reviewed and combined {department} recommendations",
AuditType.CREATED_USER_ADVICE: "added a recommendation",
AuditType.CLEARED_USER_ADVICE: "cleared their recommendation",
AuditType.ADD_PARTY: strings.Audit.ADD_PARTY,
AuditType.REMOVE_PARTY: strings.Audit.REMOVE_PARTY,
AuditType.UPLOAD_PARTY_DOCUMENT: strings.Audit.UPLOAD_PARTY_DOCUMENT,
Expand Down Expand Up @@ -127,5 +128,5 @@ def format_payload(audit_type, payload):
AuditType.LICENCE_UPDATED_STATUS: strings.Audit.LICENCE_UPDATED_STATUS,
AuditType.DOCUMENT_ON_ORGANISATION_CREATE: "added {document_type} '{file_name}' to organization",
AuditType.REPORT_SUMMARY_UPDATED: "updated ARS for {good_name} from {old_report_summary} to {report_summary}",
AuditType.COUNTERSIGN_ADVICE: "countersigned advice ids: {advice_ids}",
AuditType.COUNTERSIGN_ADVICE: "countersigned all {department} recommendations",
}
23 changes: 18 additions & 5 deletions api/cases/libraries/post_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,24 @@ def post_advice(request, case, level, team=False):

if serializer.is_valid() and not refusal_error:
serializer.save()
if not team:
# Only applies at user level advice
audit_trail_service.create(
actor=request.user, verb=AuditType.CREATED_USER_ADVICE, target=case,
)

audit_verbs = {
AdviceLevel.USER: AuditType.CREATED_USER_ADVICE,
AdviceLevel.TEAM: AuditType.REVIEW_COMBINE_ADVICE,
AdviceLevel.FINAL: AuditType.CREATED_FINAL_ADVICE,
}

department = request.user.govuser.team.department

if department is not None:
department = department.name
else:
department = "department"

audit_trail_service.create(
actor=request.user, verb=audit_verbs[level], target=case, payload={"department": department}
)

if level == AdviceLevel.FINAL:
# Remove GoodCountryDecision if changing approve decision for applicable country/goods type
update_good_country_decisions(data)
Expand Down
2 changes: 1 addition & 1 deletion api/cases/tests/test_delete_user_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ def test_creates_audit_trail(self):
response = self.client.get(reverse("cases:activity", kwargs={"pk": self.application.id}), **self.gov_headers)
audit_entries = response.json()["activity"]
self.assertEqual(len(audit_entries), 2) # one entry for case creation, one entry for advice deletion
self.assertEqual(len([a for a in audit_entries if a["text"] == "cleared user advice."]), 1)
self.assertEqual(len([a for a in audit_entries if a["text"] == "cleared their recommendation."]), 1)
Loading

0 comments on commit 1a95567

Please sign in to comment.