feat(radius): Add the user to the correct group

When generating the first WiFi password, the user is added to the
`radius_access` group, which will allow them to connect. This also fix a
previous incorrect logic where users without wifi password could not
generate one.
This commit is contained in:
Tom Hubrecht 2024-09-29 20:05:05 +02:00
parent f4428ace59
commit a88d31541c
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc

View file

@ -83,9 +83,12 @@ class GenerateWiFiPasswordView(LoginRequiredMixin, RedirectView):
if user.kanidm is None:
messages.error(self.request, _("Compte DGNum inexistant."))
elif not user.kanidm.radius_secret:
messages.error(self.request, _("Mot de passe WiFi déjà existant."))
else:
# Give access to the wifi network when the user creates its first password
if not user.kanidm.radius_secret:
async_to_sync(klient.group_add_members)(
"radius_access", [user.username]
)
async_to_sync(klient.call_post)(f"/v1/person/{user.username}/_radius")
return super().get(request, *args, **kwargs)