Skip to content

Commit c8fa5f9

Browse files
committed
[fix] Made requested changes by coderabbitai
1 parent cb3c96c commit c8fa5f9

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

docs/user/rest-api.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,18 @@ GET (detail)
10201020

10211021
Returns a single RADIUS user group assignment by its UUID.
10221022

1023+
PUT
1024+
^^^
1025+
1026+
Fully updates the RADIUS user group assignment.
1027+
1028+
======== ==============================================
1029+
Param Description
1030+
======== ==============================================
1031+
group UUID of the RADIUS group to assign (optional)
1032+
priority Priority of the assignment (optional, integer)
1033+
======== ==============================================
1034+
10231035
PATCH
10241036
^^^^^
10251037

openwisp_radius/api/serializers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,10 @@ class Meta:
373373

374374
def __init__(self, *args, **kwargs):
375375
super().__init__(*args, **kwargs)
376-
if self.context.get("view") and getattr(
377-
self.context["view"], "get_parent_queryset", None
376+
if (
377+
self.context.get("view")
378+
and getattr(self.context["view"], "get_parent_queryset", None)
379+
and not getattr(self.context["view"], "swagger_fake_view", False)
378380
):
379381
self._user = self.context["view"].get_parent_queryset().first()
380382
else:

openwisp_radius/api/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,9 +961,9 @@ class BaseRadiusUserGroupView(ProtectedAPIMixin, FilterByParentManaged):
961961
)
962962

963963
def get_queryset(self):
964-
qs = super().get_queryset()
965964
if getattr(self, "swagger_fake_view", False):
966-
return qs
965+
return self.queryset.none()
966+
qs = super().get_queryset()
967967
return qs.filter(user_id=self.kwargs["user_pk"])
968968

969969
def get_parent_queryset(self):

openwisp_radius/tests/test_api/test_api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from openwisp_radius import settings as app_settings
2828
from openwisp_radius.api.serializers import (
29+
RadiusUserGroupSerializer,
2930
RadiusUserSerializer,
3031
UserGroupCheckSerializer,
3132
)
@@ -1397,7 +1398,7 @@ def test_radius_user_group_list(self):
13971398
OrganizationUser.objects.filter(
13981399
user=target_user, organization=org2
13991400
).delete()
1400-
self._create_org_user(user=target_user, organization=org2, is_admin=True)
1401+
self._create_org_user(user=admin_user, organization=org2, is_admin=True)
14011402
response = self.client.post(
14021403
url,
14031404
{"group": str(org2_group.pk)},
@@ -1519,6 +1520,11 @@ def test_radius_user_group_detail(self):
15191520
org2_rug.refresh_from_db()
15201521
self.assertEqual(org2_rug.priority, 7)
15211522

1523+
def test_radius_user_group_serializer_without_view_context(self):
1524+
serializer = RadiusUserGroupSerializer(context={})
1525+
self.assertEqual(serializer._user, None)
1526+
self.assertEqual(serializer.fields["group"].queryset.count(), 0)
1527+
15221528

15231529
class TestTransactionApi(AcctMixin, ApiTokenMixin, BaseTransactionTestCase):
15241530
def test_user_radius_usage_view(self):

0 commit comments

Comments
 (0)