web/admin: fix error when importing duo devices

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-11-21 21:36:10 +01:00
parent c30aa90888
commit 14f341f504
2 changed files with 8 additions and 8 deletions

View File

@ -118,12 +118,12 @@ class AuthenticatorDuoStageViewSet(UsedByMixin, ModelViewSet):
.first() .first()
) )
if not user: if not user:
return Response(data={"non_field_errors": ["user does not exist"]}, status=400) return Response(data={"non_field_errors": ["User does not exist."]}, status=400)
device = DuoDevice.objects.filter( device = DuoDevice.objects.filter(
duo_user_id=request.data.get("duo_user_id"), user=user, stage=stage duo_user_id=request.data.get("duo_user_id"), user=user, stage=stage
).first() ).first()
if device: if device:
return Response(data={"non_field_errors": ["device exists already"]}, status=400) return Response(data={"non_field_errors": ["Device exists already."]}, status=400)
DuoDevice.objects.create( DuoDevice.objects.create(
duo_user_id=request.data.get("duo_user_id"), duo_user_id=request.data.get("duo_user_id"),
user=user, user=user,

View File

@ -16,9 +16,9 @@ import { until } from "lit/directives/until.js";
import { import {
AuthenticatorDuoStage, AuthenticatorDuoStage,
AuthenticatorDuoStageManualDeviceImportRequest,
CoreApi, CoreApi,
StagesApi, StagesApi,
StagesAuthenticatorDuoImportDeviceManualCreateRequest,
} from "@goauthentik/api"; } from "@goauthentik/api";
@customElement("ak-stage-authenticator-duo-device-import-form") @customElement("ak-stage-authenticator-duo-device-import-form")
@ -34,11 +34,11 @@ export class DuoDeviceImportForm extends ModelForm<AuthenticatorDuoStage, string
} }
send = (data: AuthenticatorDuoStage): Promise<void> => { send = (data: AuthenticatorDuoStage): Promise<void> => {
const importData = data as unknown as StagesAuthenticatorDuoImportDeviceManualCreateRequest; const importData = data as unknown as AuthenticatorDuoStageManualDeviceImportRequest;
importData.stageUuid = this.instancePk; return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorDuoImportDeviceManualCreate({
return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorDuoImportDeviceManualCreate( stageUuid: this.instance?.pk || "",
importData, authenticatorDuoStageManualDeviceImportRequest: importData,
); });
}; };
renderForm(): TemplateResult { renderForm(): TemplateResult {