Skip to content

Commit 363e40d

Browse files
committed
Fix permission issues
1 parent 7d3a6a5 commit 363e40d

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

care/emr/api/viewsets/patient.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,12 @@ class PatientViewSet(EMRModelViewSet):
3838

3939
def authorize_update(self, request_obj, model_instance):
4040
if not AuthorizationController.call(
41-
"can_write_patient_obj", self.request.user , model_instance
41+
"can_write_patient_obj", self.request.user, model_instance
4242
):
4343
raise PermissionDenied("Cannot Create Patient")
4444

45-
4645
def authorize_create(self, request_obj):
47-
if not AuthorizationController.call(
48-
"can_create_patient", self.request.user
49-
):
46+
if not AuthorizationController.call("can_create_patient", self.request.user):
5047
raise PermissionDenied("Cannot Create Patient")
5148

5249
def authorize_delete(self, instance):
@@ -154,4 +151,4 @@ def delete_user(self, request, *args, **kwargs):
154151
if not PatientUser.objects.filter(user=user, patient=patient).exists():
155152
raise ValidationError("User does not exist")
156153
PatientUser.objects.filter(user=user, patient=patient).delete()
157-
return Response({}, status=204)
154+
return Response({})

care/emr/models/patient.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def rebuild_users_cache(self):
6363

6464
def save(self, *args, **kwargs) -> None:
6565
self.rebuild_organization_cache()
66+
self.rebuild_users_cache()
6667
if self.date_of_birth and not self.year_of_birth:
6768
self.year_of_birth = self.date_of_birth.year
6869
super().save(*args, **kwargs)

care/security/authorization/patient.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ def find_roles_on_patient(self, user, patient):
3535
)
3636
return role_ids.union(set(roles))
3737

38-
39-
4038
def can_view_patient_obj(self, user, patient):
4139
if user.is_superuser:
4240
return True
@@ -57,11 +55,9 @@ def can_write_patient_obj(self, user, patient):
5755

5856
def can_create_patient(self, user):
5957
return self.check_permission_in_facility_organization(
60-
[PatientPermissions.can_create_patient.name],
61-
user
58+
[PatientPermissions.can_create_patient.name], user
6259
)
6360

64-
6561
def can_view_clinical_data(self, user, patient):
6662
if user.is_superuser:
6763
return True

0 commit comments

Comments
 (0)