def post(self, request, pk): """ Adds a document to the specified case """ data = request.data for document in data: document["case"] = pk document["user"] = request.user.pk document["visible_to_exporter"] = False serializer = CaseDocumentCreateSerializer(data=data, many=True) if serializer.is_valid(): serializer.save() for document in serializer.data: audit_trail_service.create( actor=request.user, verb=AuditType.UPLOAD_CASE_DOCUMENT, target=get_case(pk), payload={"file_name": document["name"]}, ) return JsonResponse(data={"documents": serializer.data}, status=status.HTTP_201_CREATED) delete_documents_on_bad_request(data) return JsonResponse(data={"errors": serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): """ Create a new organisation. """ data = request.data.copy() validate_only = request.data.get("validate_only", False) data["status"] = (OrganisationStatus.ACTIVE if getattr( request.user, "type", None) == UserType.INTERNAL else OrganisationStatus.IN_REVIEW) serializer = OrganisationCreateUpdateSerializer( data=data, context={"validate_only": validate_only}) if serializer.is_valid(raise_exception=True): if not validate_only: serializer.save() # Audit the creation of the organisation if not request.user.is_anonymous: audit_trail_service.create( actor=request.user, verb=AuditType.CREATED_ORGANISATION, target=get_organisation_by_pk(serializer.data.get("id")), payload={"organisation_name": serializer.data.get("name")}, ) else: audit_trail_service.create_system_user_audit( verb=AuditType.REGISTER_ORGANISATION, target=get_organisation_by_pk(serializer.data.get("id")), payload={ "email": request.data["user"]["email"], "organisation_name": serializer.data.get("name") }, ) return JsonResponse(data=serializer.data, status=status.HTTP_201_CREATED)
def get(self, request, pk): """ Concatenates all advice for a case """ if self.team_advice.filter( team=request.user.govuser.team).count() == 0: user_cannot_manage_team_advice = check_if_user_cannot_manage_team_advice( pk, request.user.govuser) if user_cannot_manage_team_advice: return user_cannot_manage_team_advice team = self.request.user.govuser.team_id advice = self.advice.filter(user__team_id=team) group_advice(self.case, advice, request.user, AdviceLevel.TEAM) case_advice_contains_refusal(pk) audit_trail_service.create( actor=request.user, verb=AuditType.CREATED_TEAM_ADVICE, target=self.case, ) team_advice = Advice.objects.filter( case=self.case, team_id=team).order_by("-created_at") else: team_advice = self.team_advice serializer = AdviceViewSerializer(team_advice, many=True) return JsonResponse(data={"advice": serializer.data}, status=status.HTTP_200_OK)
def post(self, request, pk): """ Post a goodstype """ application = get_application(pk) if (hasattr(application, "goodstype_category") and application.goodstype_category in GoodsTypeCategory.IMMUTABLE_GOODS): raise BadRequestError( detail= "You cannot do this action for this type of open application") request.data["application"] = application serializer = GoodsTypeSerializer(data=request.data) if serializer.is_valid(raise_exception=True): serializer.save() audit_trail_service.create( actor=request.user, verb=AuditType.ADD_GOOD_TYPE_TO_APPLICATION, action_object=serializer.instance, target=application.get_case(), payload={"good_type_name": serializer.instance.description}, ) return JsonResponse(data={"good": serializer.data}, status=status.HTTP_201_CREATED)
def delete(self, request, pk): """ Removes the case officer currently assigned to a case off of it. """ case = get_case(pk) if not case.case_officer: return HttpResponse(status=status.HTTP_400_BAD_REQUEST) data = {"case_officer": None} serializer = CaseOfficerUpdateSerializer(instance=case, data=data) if serializer.is_valid(raise_exception=True): user = case.case_officer serializer.save() audit_trail_service.create( actor=request.user, verb=AuditType.REMOVE_CASE_OFFICER_FROM_CASE, target=case, payload={ "case_officer": user.email if not user.first_name else f"{user.first_name} {user.last_name}" }, ) return JsonResponse(data={}, status=status.HTTP_200_OK)
def put(self, request, pk): """ Assigns a gov user to be the case officer for a case """ case = get_case(pk) gov_user_pk = request.data.get("gov_user_pk") if not gov_user_pk: return JsonResponse( data={"errors": { "user": [Cases.CaseOfficerPage.NONE] }}, status=status.HTTP_400_BAD_REQUEST) data = {"case_officer": gov_user_pk} serializer = CaseOfficerUpdateSerializer(instance=case, data=data) if serializer.is_valid(raise_exception=True): user = get_user_by_pk(gov_user_pk) serializer.save() audit_trail_service.create( actor=request.user, verb=AuditType.ADD_CASE_OFFICER_TO_CASE, target=case, payload={ "case_officer": user.email if not user.first_name else f"{user.first_name} {user.last_name}" }, ) return JsonResponse(data={}, status=status.HTTP_200_OK)
def post(self, request): """ Create a new End User Advisory Enquiry query case instance """ data = JSONParser().parse(request) if not data.get("end_user"): data["end_user"] = {} organisation_id = get_request_user_organisation_id(request) data["organisation"] = organisation_id data["end_user"]["organisation"] = organisation_id data["end_user"]["type"] = PartyType.END_USER data["submitted_by"] = request.user serializer = EndUserAdvisoryViewSerializer(data=data) try: if serializer.is_valid(): if "validate_only" not in data or data["validate_only"] == "False": eua = serializer.save() audit_trail_service.create( actor=request.user, verb=AuditType.CREATED, action_object=eua.get_case(), payload={"status": {"new": eua.status.status}}, ) apply_flagging_rules_to_case(eua) return JsonResponse(data={"end_user_advisory": serializer.data}, status=status.HTTP_201_CREATED) else: return JsonResponse(data={}, status=status.HTTP_200_OK) return JsonResponse(data={"errors": serializer.errors}, status=status.HTTP_400_BAD_REQUEST) except serializers.ValidationError as e: return JsonResponse(data={"errors": e}, status=status.HTTP_400_BAD_REQUEST)
def audit_reviewed_organisation(user, organisation, decision): if decision == OrganisationStatus.ACTIVE: audit_trail_service.create( actor=user, verb=AuditType.APPROVED_ORGANISATION, target=organisation, payload={ "organisation_name": organisation.name, }, ) else: audit_trail_service.create( actor=user, verb=AuditType.REJECTED_ORGANISATION, target=organisation, payload={ "organisation_name": organisation.name, }, ) for email in organisation.users.annotate( email=F("user__baseuser_ptr__email")).values_list("email", flat=True): gov_notify_service.send_email( email_address=email, template_type=TemplateType.ORGANISATION_STATUS, data=OrganisationStatusEmailData( organisation_name=organisation.name), )
def submit_application(application: BaseApplication, user: ExporterUser = None): if not user: user = UserOrganisationRelationship.objects.filter( organisation_id=application.organisation_id).first().user application.submitted_at = timezone.localtime() application.sla_remaining_days = get_application_target_sla( application.case_type.sub_type) application.status = get_case_status_by_status( CaseStatusEnum.SUBMITTED) application.save() if application.case_type.sub_type in [ CaseTypeSubTypeEnum.STANDARD, CaseTypeSubTypeEnum.OPEN ]: set_case_flags_on_submitted_standard_or_open_application( application) add_goods_flags_to_submitted_application(application) apply_flagging_rules_to_case(application) audit_trail_service.create( actor=user.baseuser_ptr, verb=AuditType.UPDATED_STATUS, target=application.get_case(), payload={ "status": { "new": CaseStatusEnum.get_text(CaseStatusEnum.SUBMITTED), "old": CaseStatusEnum.get_text(CaseStatusEnum.DRAFT), } }, ) return application
def save(self, *args, **kwargs): from api.audit_trail import service as audit_trail_service audit_user = None user = None audit_note = None if "audit_user" in kwargs: audit_user = kwargs.pop("audit_user") if "user" in kwargs: user = kwargs.pop("user") if "audit_note" in kwargs: audit_note = kwargs.pop("audit_note") super().save(*args, **kwargs) if audit_user and user: audit_trail_service.create( actor=audit_user, verb=AuditType.ASSIGN_USER_TO_CASE, action_object=self.case, payload={ "user": user.first_name + " " + user.last_name, "queue": self.queue.name, "additional_text": audit_note, }, )
def delete(self, request, pk, party_pk): """ Removes a party from application. """ application = get_application(pk) try: poa = application.active_parties.all().get(party__pk=party_pk) except PartyOnApplication.DoesNotExist: return HttpResponse(status=status.HTTP_404_NOT_FOUND) if not application.party_is_editable(poa.party): return JsonResponse( data={"errors": [strings.Applications.Generic.INVALID_OPERATION_FOR_READ_ONLY_CASE_ERROR]}, status=status.HTTP_400_BAD_REQUEST, ) # Delete party application.delete_party(poa) # Audit audit_trail_service.create( actor=request.user, verb=AuditType.REMOVE_PARTY, target=application.get_case(), payload={"party_type": poa.party.type.replace("_", " "), "party_name": poa.party.name,}, ) return JsonResponse(data={"party": PartySerializer(poa.party).data}, status=status.HTTP_200_OK)
def delete(self, request, pk, goodstype_pk): """ Deletes a goodstype """ application = get_application(pk) if (hasattr(application, "goodstype_category") and application.goodstype_category in GoodsTypeCategory.IMMUTABLE_GOODS): raise BadRequestError( detail= "You cannot do this action for this type of open application") goods_type = get_goods_type(goodstype_pk) if application.case_type.sub_type == CaseTypeSubTypeEnum.HMRC: delete_goods_type_document_if_exists(goods_type) goods_type.delete() audit_trail_service.create( actor=request.user, verb=AuditType.REMOVE_GOOD_TYPE_FROM_APPLICATION, action_object=goods_type, target=Case.objects.get(id=application.id), payload={"good_type_name": goods_type.description}, ) return JsonResponse(data={}, status=status.HTTP_200_OK)
def get(self, request, pk): """ Concatenates all advice for a case and returns it or just returns if final advice already exists """ if len(self.final_advice) == 0: assert_user_has_permission( request.user.govuser, constants.GovPermissions.MANAGE_LICENCE_FINAL_ADVICE) group_advice(self.case, self.team_advice, request.user, AdviceLevel.FINAL) audit_trail_service.create( actor=request.user, verb=AuditType.CREATED_FINAL_ADVICE, target=self.case, ) final_advice = Advice.objects.filter( case=self.case).order_by("-created_at") else: final_advice = self.final_advice serializer = AdviceViewSerializer(final_advice, many=True) return JsonResponse(data={"advice": serializer.data}, status=status.HTTP_200_OK)
def test_retrieve_audit_trail(self): service.create(actor=self.exporter_user, verb=AuditType.CREATED_FINAL_ADVICE, target=self.case) audit_trail_qs = service.get_activity_for_user_and_model( user=self.exporter_user.baseuser_ptr, object_type=self.case ) self.assertEqual(audit_trail_qs.count(), 1)
def put(self, request, pk): application = get_application(pk) if application.goodstype_category in GoodsTypeCategory.IMMUTABLE_DESTINATIONS: raise BadRequestError( detail= "You cannot do this action for this type of open application") data = request.data for good, countries in data.items(): good = get_goods_type(good) # Validate that at least one country has been selected per good if not countries: return JsonResponse( {"errors": "Select at least one country for each good"}, status=status.HTTP_400_BAD_REQUEST) # Validate that the countries given are valid countries if not Country.objects.filter( pk__in=countries).count() == len(countries): return HttpResponse(status=status.HTTP_404_NOT_FOUND) initial_countries = list(good.countries.all()) good.countries.set(countries) removed_countries = [ country.name for country in initial_countries if country not in good.countries.all() ] added_countries = [ country.name for country in good.countries.all() if country not in initial_countries ] if removed_countries: audit_trail_service.create( actor=request.user, verb=AuditType.REMOVED_COUNTRIES_FROM_GOOD, action_object=good, target=Case.objects.get(id=application.id), payload={ "good_type_name": good.description, "countries": ", ".join(removed_countries), }, ) if added_countries: audit_trail_service.create( actor=request.user, verb=AuditType.ASSIGNED_COUNTRIES_TO_GOOD, action_object=good, target=Case.objects.get(id=application.id), payload={ "good_type_name": good.description, "countries": ", ".join(added_countries), }, ) return JsonResponse(data=data, status=status.HTTP_200_OK)
def perform_destroy(self, instance): instance.delete() case = get_case(instance.visit_case_id) audit_trail_service.create( actor=self.request.user, verb=AuditType.COMPLIANCE_PEOPLE_PRESENT_DELETED, action_object=case, payload={}, )
def perform_create(self, serializer): assert_user_has_permission(self.request.user.govuser, constants.GovPermissions.MAINTAIN_OGL) if not self.request.data.get("validate_only", False): instance = serializer.save() audit_trail_service.create( actor=self.request.user, verb=AuditType.OGL_CREATED, action_object=instance, )
def test_audit_not_cascade_deleted(self): audit_qs = Audit.objects.all() self.assertEqual(audit_qs.count(), 1) service.create(actor=self.exporter_user, verb=AuditType.ADD_FLAGS, target=self.case) self.assertEqual(audit_qs.count(), 2) self.case.delete() self.assertEqual(audit_qs.count(), 2)
def perform_create(self, serializer): party = serializer.save() case = get_case(self.kwargs["pk"]) case.additional_contacts.add(party) audit_trail_service.create( actor=self.request.user, verb=AuditType.ADD_ADDITIONAL_CONTACT_TO_CASE, target=case, payload={"contact": serializer.data["name"]}, )
def change_status(self, user, status: CaseStatus, note: Optional[str] = ""): """ Sets the status for the case, runs validation on various parameters, creates audit entries and also runs flagging and automation rules """ from api.cases.helpers import can_set_status from api.audit_trail import service as audit_trail_service from api.applications.libraries.application_helpers import can_status_be_set_by_gov_user from api.workflow.automation import run_routing_rules from api.workflow.flagging_rules_automation import apply_flagging_rules_to_case from api.licences.helpers import update_licence_status old_status = self.status.status # Only allow the final decision if the user has the MANAGE_FINAL_ADVICE permission if status.status == CaseStatusEnum.FINALISED: assert_user_has_permission( user.govuser, GovPermissions.MANAGE_LICENCE_FINAL_ADVICE) if not can_set_status(self, status.status): raise ValidationError({"status": [strings.Statuses.BAD_STATUS]}) if not can_status_be_set_by_gov_user( user.govuser, old_status, status.status, is_mod=False): raise ValidationError({"status": ["Status cannot be set by user"]}) self.status = status self.save() # Update licence status if applicable case status change update_licence_status(self, status.status) if CaseStatusEnum.is_terminal( old_status) and not CaseStatusEnum.is_terminal( self.status.status): apply_flagging_rules_to_case(self) audit_trail_service.create( actor=user, verb=AuditType.UPDATED_STATUS, target=self, payload={ "status": { "new": CaseStatusEnum.get_text(self.status.status), "old": old_status }, "additional_text": note, }, ) if old_status != self.status.status: run_routing_rules(case=self, keep_status=True)
class SetQueues(APIView): authentication_classes = (GovAuthentication, ) @transaction.atomic def put(self, request, pk): case = get_case(pk) request_queues = set(request.data.get("queues", [])) queues = Queue.objects.filter(id__in=request_queues) note = request.data.get("note") if len(request_queues) > len(queues): queues_not_found = list(request_queues - set( str(id) for id in queues.values_list("id", flat=True))) return JsonResponse( data={ "errors": { "queues": [Cases.Queue.NOT_FOUND + str(queues_not_found)] } }, status=status.HTTP_400_BAD_REQUEST, ) initial_queues = set(case.queues.all()) queues = set(queues) case.queues.set(request_queues) removed_queues = initial_queues - queues new_queues = queues - initial_queues if removed_queues: # Remove case assignments when the case is remove from the queue CaseAssignment.objects.filter(case=case, queue__in=removed_queues).delete() audit_trail_service.create( actor=request.user, verb=AuditType.REMOVE_CASE, target=case, payload={ "queues": sorted([queue.name for queue in removed_queues]), "additional_text": note }, ) if new_queues: audit_trail_service.create( actor=request.user, verb=AuditType.MOVE_CASE, target=case, payload={ "queues": sorted([queue.name for queue in new_queues]), "additional_text": note }, ) return JsonResponse(data={"queues": list(request_queues)}, status=status.HTTP_200_OK)
def post(self, request): """ Create a new GoodsQuery case instance """ data = request.data good = get_good(data["good_id"]) data["organisation"] = get_request_user_organisation_id(request) is_clc_required = good.is_good_controlled is None is_pv_grading_required = good.is_pv_graded == GoodPvGraded.GRADING_REQUIRED errors = self._check_request_for_errors(good, is_clc_required, is_pv_grading_required) if errors: return JsonResponse(data={"errors": errors}, status=status.HTTP_400_BAD_REQUEST) good.status = GoodStatus.QUERY goods_query = GoodsQuery.objects.create( clc_control_list_entry=data.get("clc_control_list_entry"), clc_raised_reasons=data.get("clc_raised_reasons"), pv_grading_raised_reasons=data.get("pv_grading_raised_reasons"), good=good, organisation_id=data["organisation"], case_type_id=CaseTypeEnum.GOODS.id, status=get_starting_status(is_clc_required), submitted_at=django.utils.timezone.now(), submitted_by=request.user.exporteruser, ) # attach flags based on what's required if is_clc_required: flag = Flag.objects.get(id=SystemFlags.GOOD_CLC_QUERY_ID) goods_query.flags.add(flag) goods_query.clc_responded = False if is_pv_grading_required: flag = Flag.objects.get(id=SystemFlags.GOOD_PV_GRADING_QUERY_ID) goods_query.flags.add(flag) goods_query.pv_grading_responded = False good.save() goods_query.save() audit_trail_service.create( actor=request.user, verb=AuditType.CREATED, action_object=goods_query.get_case(), payload={"status": {"new": goods_query.status.status}}, ) apply_flagging_rules_to_case(goods_query) return JsonResponse(data={"id": goods_query.id}, status=status.HTTP_201_CREATED)
def post(self, request, pk): data = request.data data["application"] = pk if "validate_only" in data and not isinstance(data["validate_only"], bool): return JsonResponse( data={"error": strings.Goods.VALIDATE_ONLY_ERROR}, status=status.HTTP_400_BAD_REQUEST, ) if "validate_only" in data and data["validate_only"] is True: # validate the value, quantity, and units relating to a good on an application. # note: Goods attached to applications also need documents. This is validated at a later stage. serializer = GoodOnApplicationCreateSerializer(data=data, partial=True) if serializer.is_valid(): return JsonResponse(status=status.HTTP_200_OK, data={}) else: if "good_id" not in data: return JsonResponse( data={"error": strings.Goods.GOOD_ID_ERROR}, status=status.HTTP_400_BAD_REQUEST, ) data["good"] = data["good_id"] good = get_good_with_organisation( data.get("good"), get_request_user_organisation_id(request)) if not good.missing_document_reason and GoodDocument.objects.filter( good=good).count() == 0: return JsonResponse( data={"error": strings.Goods.DOCUMENT_ERROR}, status=status.HTTP_400_BAD_REQUEST, ) serializer = GoodOnApplicationCreateSerializer(data=data) if serializer.is_valid(): serializer.save() audit_trail_service.create( actor=request.user, verb=AuditType.ADD_GOOD_TO_APPLICATION, action_object=good, target=Case.objects.get(id=pk), payload={"good_name": good.description}, ) return JsonResponse(data={"good": serializer.data}, status=status.HTTP_201_CREATED) return JsonResponse(data={"errors": serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, pk): assert_user_has_permission( request.user.govuser, constants.GovPermissions.MANAGE_LICENCE_FINAL_ADVICE) data = {k: v for k, v in request.data.items() if v is not None} # Get list of all required item id's required_decisions = get_required_good_type_to_country_combinations(pk) required_decision_ids = set() for goods_type, country_list in required_decisions.items(): for country in country_list: required_decision_ids.add(f"{goods_type}.{country}") if not required_decision_ids.issubset(data): missing_ids = required_decision_ids.difference(request.data) raise ParseError({ missing_id: [Cases.GoodCountryMatrix.MISSING_ITEM] for missing_id in missing_ids }) # Delete existing decision documents if decision changes existing_decisions = get_existing_good_type_to_country_decisions(pk) for decision_id in required_decision_ids: if (data.get(decision_id) != AdviceType.REFUSE) != existing_decisions.get(decision_id): # Proviso N/A as there is no proviso document type GeneratedCaseDocument.objects.filter( case_id=pk, advice_type__in=[AdviceType.APPROVE, AdviceType.REFUSE], visible_to_exporter=False).delete() break # Update or create GoodCountryDecisions for id in required_decision_ids: goods_type_id, country_id = id.split(".") value = data[id] == AdviceType.APPROVE GoodCountryDecision.objects.update_or_create( case_id=pk, goods_type_id=goods_type_id, country_id=country_id, defaults={"approve": value}) audit_trail_service.create( actor=request.user, verb=AuditType.UPDATED_GOOD_ON_DESTINATION_MATRIX, target=get_case(pk), ) return JsonResponse( data={"good_country_decisions": list(required_decision_ids)}, status=status.HTTP_201_CREATED)
def delete(self, request, pk, ext_loc_pk): application = get_application(pk) if not is_case_status_draft( application.status.status ) and application.status.status in get_case_statuses(read_only=True): return JsonResponse( data={ "error": f"Application status {application.status.status} is read-only." }, status=status.HTTP_400_BAD_REQUEST, ) if (not is_case_status_draft(application.status.status) and application.status.status != CaseStatusEnum.APPLICANT_EDITING): if ExternalLocationOnApplication.objects.filter( application=application).count() == 1: return JsonResponse( data={ "errors": { "external_locations": [ "Go back and change your answer from ‘Change a site, or delete a good, " "third party or country’ to ’Change something else’." ] } }, status=status.HTTP_400_BAD_REQUEST, ) removed_locations = ExternalLocationOnApplication.objects.filter( application=application, external_location__pk=ext_loc_pk) if removed_locations: audit_trail_service.create( actor=request.user, verb=AuditType.REMOVED_EXTERNAL_LOCATIONS_FROM_APPLICATION, target=application.get_case(), payload={ "locations": [ location.external_location.name + " " + location.external_location.country.name if location.external_location.country else location.external_location.name for location in removed_locations ] }, ) removed_locations.delete() return HttpResponse(status=status.HTTP_204_NO_CONTENT)
def generate_audit_trail(self, user, query): grading = ( f"{query.good.pv_grading_details.prefix} " f"{get_pv_grading_value_from_key(query.good.pv_grading_details.grading)} " f"{query.good.pv_grading_details.suffix}" ) audit_trail_service.create( actor=user, verb=AuditType.PV_GRADING_RESPONSE, action_object=query.good, target=query.get_case(), payload={"grading": grading}, )
def post(self, request, org_pk): if hasattr(request.user, "exporteruser"): assert_user_has_permission(request.user.exporteruser, ExporterPermissions.ADMINISTER_SITES, org_pk) data = request.data if "records_located_step" in data: if "site_records_stored_here" not in data: return JsonResponse( data={ "errors": { "site_records_stored_here": [strings.Site.NO_RECORDS_LOCATED_AT] } }, status=status.HTTP_400_BAD_REQUEST, ) if not str_to_bool(data["site_records_stored_here"] ) and "site_records_located_at" not in data: return JsonResponse( data={ "errors": { "site_records_located_at": [strings.Site.NO_SITE_SELECTED] } }, status=status.HTTP_400_BAD_REQUEST, ) data["organisation"] = org_pk serializer = SiteCreateUpdateSerializer(data=data) if serializer.is_valid(raise_exception=True): if "validate_only" not in data or data["validate_only"] == "False": site = serializer.save() audit_trail_service.create( actor=request.user, verb=AuditType.CREATED_SITE, target=site, payload={ "site_name": site.name, }, ) return JsonResponse( data={"site": SiteViewSerializer(site).data}, status=status.HTTP_201_CREATED) return JsonResponse(data={})
def perform_update(self, serializer): person = serializer.save() case = get_case(person.visit_case_id) audit_trail_service.create( actor=self.request.user, verb=AuditType.COMPLIANCE_PEOPLE_PRESENT_UPDATED, action_object=case, payload={ "name": person.name, "job_title": person.job_title, }, )
def test_exporter_cannot_retrieve_internal_audit_trail_for_draft(self): # Create an audit entry on draft service.create( actor=self.gov_user, verb=AuditType.CREATED_CASE_NOTE, target=self.case, payload={"additional_text": "note"} ) gov_audit_trail_qs = service.get_activity_for_user_and_model( user=self.gov_user.baseuser_ptr, object_type=self.case ) exp_audit_trail_qs = service.get_activity_for_user_and_model( user=self.exporter_user.baseuser_ptr, object_type=self.case ) self.assertEqual(gov_audit_trail_qs.count(), 1) self.assertEqual(exp_audit_trail_qs.count(), 0)
def create_submitted_audit(request: Request, application: HmrcQuery, old_status: str) -> None: audit_trail_service.create( actor=request.user, verb=AuditType.UPDATED_STATUS, target=application.get_case(), payload={ "status": { "new": CaseStatusEnum.get_text(CaseStatusEnum.SUBMITTED), "old": CaseStatusEnum.get_text(old_status), } }, ignore_case_status=True, send_notification=False, )