Skip to content

Commit 783bf35

Browse files
committed
[fix] Added comments
1 parent 33f5548 commit 783bf35

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

openwisp_radius/api/serializers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,12 @@ def __init__(self, *args, **kwargs):
383383
else:
384384
self._user = None
385385
if self._user and view and getattr(view.request, "user", None):
386-
orgs = view.request.user.organizations_managed
387-
self.fields["group"].queryset = (
388-
self.fields["group"]
389-
.queryset.filter(organization__in=orgs)
390-
.filter(organization__in=self._user.organizations_dict.keys())
386+
# Restrict available groups to organizations that the request user manages
387+
# and that the edited user belongs to. This prevents assigning groups from
388+
# organizations outside the request user's management scope.
389+
self.fields["group"].queryset = self.fields["group"].queryset.filter(
390+
Q(organization__in=view.request.user.organizations_managed)
391+
& Q(organization__in=self._user.organizations_dict.keys())
391392
)
392393
else:
393394
self.fields["group"].queryset = self.fields["group"].queryset.none()

0 commit comments

Comments
 (0)