Skip to content

Commit 341e305

Browse files
committed
limit user details based on user type
1 parent be5711f commit 341e305

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

care/users/api/serializers/user.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,26 @@ class Meta:
432432
"home_facility",
433433
"video_connect_link",
434434
)
435+
436+
def to_representation(self, instance):
437+
representation = super().to_representation(instance)
438+
user = self.context["request"].user
439+
440+
if user.user_type < User.TYPE_VALUE_MAP["Reserved"]:
441+
whitelisted_fields = (
442+
"id",
443+
"first_name",
444+
"last_name",
445+
"username",
446+
"local_body_object",
447+
"district_object",
448+
"state_object",
449+
"user_type",
450+
"created_by",
451+
)
452+
453+
for key in list(representation.keys()):
454+
if key not in whitelisted_fields:
455+
representation.pop(key)
456+
457+
return representation

0 commit comments

Comments
 (0)