@@ -20,6 +20,10 @@ class MultitenantAdminMixin(object):
2020
2121 multitenant_shared_relations = None
2222 multitenant_parent = None
23+ sensitive_fields = []
24+
25+ def get_sensitive_fields (self , request , obj = None ):
26+ return self .sensitive_fields
2327
2428 def __init__ (self , * args , ** kwargs ):
2529 super ().__init__ (* args , ** kwargs )
@@ -37,6 +41,21 @@ def get_repr(self, obj):
3741
3842 get_repr .short_description = _ ("name" )
3943
44+ def get_fields (self , request , obj = None ):
45+ """
46+ Return the list of fields to be displayed in the admin.
47+
48+ If the user is not a superuser, it will remove sensitive fields.
49+ """
50+ fields = super ().get_fields (request , obj )
51+ if obj and not request .user .is_superuser :
52+ if self .multitenant_parent :
53+ obj = getattr (obj , self .multitenant_parent )
54+ if getattr (obj , "organization_id" , None ) is None :
55+ sensitive_fields = self .get_sensitive_fields (request , obj )
56+ return [f for f in fields if f not in sensitive_fields ]
57+ return fields
58+
4059 def get_queryset (self , request ):
4160 """
4261 If current user is not superuser, show only the
0 commit comments