Skip to content

Commit 91cbf0c

Browse files
committed
[fix] Added handling for multitenant parent
1 parent f071cf3 commit 91cbf0c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

openwisp_users/multitenancy.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,21 @@ def get_queryset(self, request):
5757
elif not self.multitenant_parent:
5858
return qs
5959
else:
60-
qsarg = "{0}__organization__in".format(self.multitenant_parent)
61-
return qs.filter(**{qsarg: user.organizations_managed})
60+
qsarg = f"{self.multitenant_parent}__organization"
61+
return qs.filter(
62+
Q(**{f"{qsarg}__in": user.organizations_managed}) | Q(**{qsarg: None})
63+
)
6264

6365
def _has_org_permission(self, request, obj, perm_func):
6466
"""
6567
Helper method to check object-level permissions for users
6668
associated with specific organizations.
6769
"""
6870
perm = perm_func(request, obj)
71+
if obj and self.multitenant_parent:
72+
# In case of a multitenant parent, we need to check if the
73+
# user has permission on the parent object.
74+
obj = getattr(obj, self.multitenant_parent)
6975
if not request.user.is_superuser and obj and hasattr(obj, "organization_id"):
7076
perm = perm and (
7177
obj.organization_id

0 commit comments

Comments
 (0)