Skip to content

Commit

Permalink
Check if user uploading External results is from same district (#1747)
Browse files Browse the repository at this point in the history
* check if user is from same district

* fix logic order

* refactor

* refactor

Co-authored-by: Aakash Singh <mail@singhaakash.dev>

---------

Co-authored-by: Aakash Singh <mail@singhaakash.dev>
  • Loading branch information
Pranshu1902 and sainak authored Dec 7, 2023
1 parent 84ead2a commit 5563b48
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions care/facility/api/viewsets/patient_external_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def bulk_upsert(self, request, *args, **kwargs):
raise ValidationError({"sample_tests": "No Data was provided"})
if not isinstance(request.data["sample_tests"], list):
raise ValidationError({"sample_tests": "Data should be provided as a list"})

# check if the user is from same district
for data in request.data["sample_tests"]:
if request.user.district != data["district"]:
raise ValidationError({"Error": "User must belong to same district"})

errors = []
counter = 0
ser_objects = []
Expand Down

0 comments on commit 5563b48

Please sign in to comment.