From e2c2faaff1261bdaf2f72cca2b19d6c88b3994a3 Mon Sep 17 00:00:00 2001 From: Tore Brede <Tore.Brede@uib.no> Date: Sun, 24 Oct 2021 14:27:45 +0200 Subject: [PATCH] Adding Feide ID to guest registation page if available --- frontend/public/locales/en/common.json | 3 +- frontend/public/locales/nb/common.json | 3 +- frontend/public/locales/nn/common.json | 3 +- .../routes/guest/register/guestDataForm.ts | 2 ++ frontend/src/routes/guest/register/index.tsx | 1 + .../routes/guest/register/registerPage.tsx | 10 +++++++ gregui/api/views/invitation.py | 29 ++++++++++--------- gregui/authentication/auth_backends.py | 1 + 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/frontend/public/locales/en/common.json b/frontend/public/locales/en/common.json index 26c3f0a8..99cb2eb4 100644 --- a/frontend/public/locales/en/common.json +++ b/frontend/public/locales/en/common.json @@ -97,5 +97,6 @@ "yourGuestPeriod": "Your guest period", "guestPeriodDescription": "Period registered for your guest role." }, - "yourGuestAccount": "Your guest account" + "yourGuestAccount": "Your guest account", + "feideId": "Feide ID" } diff --git a/frontend/public/locales/nb/common.json b/frontend/public/locales/nb/common.json index 82dea3fa..d00ca77e 100644 --- a/frontend/public/locales/nb/common.json +++ b/frontend/public/locales/nb/common.json @@ -96,5 +96,6 @@ "yourGuestPeriod": "Din gjesteperiode", "guestPeriodDescription": "Registrert periode for din gjesterolle." }, - "yourGuestAccount": "Din gjestekonto" + "yourGuestAccount": "Din gjestekonto", + "feideId": "Feide ID" } diff --git a/frontend/public/locales/nn/common.json b/frontend/public/locales/nn/common.json index 1d6b0f8f..b82e4f09 100644 --- a/frontend/public/locales/nn/common.json +++ b/frontend/public/locales/nn/common.json @@ -97,5 +97,6 @@ "yourGuestPeriod": "Din gjesteperiode", "guestPeriodDescription": "Registrert periode for di gjesterolle." }, - "yourGuestAccount": "Din gjestekonto" + "yourGuestAccount": "Din gjestekonto", + "feideId": "Feide ID" } diff --git a/frontend/src/routes/guest/register/guestDataForm.ts b/frontend/src/routes/guest/register/guestDataForm.ts index f4f37436..09e7da42 100644 --- a/frontend/src/routes/guest/register/guestDataForm.ts +++ b/frontend/src/routes/guest/register/guestDataForm.ts @@ -16,6 +16,8 @@ export type GuestInviteInformation = { role_end: string comment?: string + feide_id?: string + // These fields are in the form, but it is not expected that // they are set, with the exception of e-mail, when the guest // first follows the invite link diff --git a/frontend/src/routes/guest/register/index.tsx b/frontend/src/routes/guest/register/index.tsx index 6cdc89b0..be010f6e 100644 --- a/frontend/src/routes/guest/register/index.tsx +++ b/frontend/src/routes/guest/register/index.tsx @@ -103,6 +103,7 @@ export default function GuestRegister() { comment: jsonResponse.role.comments, email: jsonResponse.person.email, + feide_id: jsonResponse.person.feide_id, mobile_phone_country_code: countryCode, mobile_phone: nationalNumber, fnr: jsonResponse.fnr, diff --git a/frontend/src/routes/guest/register/registerPage.tsx b/frontend/src/routes/guest/register/registerPage.tsx index f21ca131..8ce656e0 100644 --- a/frontend/src/routes/guest/register/registerPage.tsx +++ b/frontend/src/routes/guest/register/registerPage.tsx @@ -158,6 +158,16 @@ const GuestRegisterStep = forwardRef( disabled /> + {/* Only show the Feide ID field if the value is present */} + {guestData.feide_id && ( + <TextField + id="feide_id" + label={t('feideId')} + value={guestData.feide_id} + disabled + /> + )} + <Box sx={{ display: 'flex', diff --git a/gregui/api/views/invitation.py b/gregui/api/views/invitation.py index 2432ba0d..1eca446e 100644 --- a/gregui/api/views/invitation.py +++ b/gregui/api/views/invitation.py @@ -1,4 +1,5 @@ from enum import Enum +from typing import Optional from django.core import exceptions from django.db import transaction @@ -12,7 +13,7 @@ from rest_framework.permissions import AllowAny from rest_framework.response import Response from rest_framework.views import APIView -from greg.models import Identity, InvitationLink +from greg.models import Identity, InvitationLink, Person from greg.permissions import IsSponsor from gregui.api.serializers.guest import GuestRegisterSerializer from gregui.api.serializers.invitation import InviteGuestSerializer @@ -141,19 +142,9 @@ class InvitedGuestView(GenericAPIView): else SessionType.FEIDE.value ) - try: - fnr = person.identities.get( - type=Identity.IdentityType.NORWEGIAN_NATIONAL_ID_NUMBER - ).value - except Identity.DoesNotExist: - fnr = None - - try: - passport = person.identities.get( - type=Identity.IdentityType.PASSPORT_NUMBER - ).value - except Identity.DoesNotExist: - passport = None + fnr = self._get_identity_or_none(person, Identity.IdentityType.NORWEGIAN_NATIONAL_ID_NUMBER) + passport = self._get_identity_or_none(person, Identity.IdentityType.PASSPORT_NUMBER) + feide_id = self._get_identity_or_none(person, Identity.IdentityType.FEIDE_ID) data = { "person": { @@ -163,6 +154,7 @@ class InvitedGuestView(GenericAPIView): "mobile_phone": person.private_mobile and person.private_mobile.value, "fnr": fnr, "passport": passport, + "feide_id": feide_id }, "sponsor": { "first_name": sponsor.first_name, @@ -247,3 +239,12 @@ class InvitedGuestView(GenericAPIView): ) # Check that there are no other fields filled in return number_of_fields_filled_in == len(person_data.keys()) + + @staticmethod + def _get_identity_or_none(person: Person, identity_type: Identity.IdentityType) -> Optional[str]: + try: + return person.identities.get( + type=identity_type + ).value + except Identity.DoesNotExist: + return None diff --git a/gregui/authentication/auth_backends.py b/gregui/authentication/auth_backends.py index 74b897c1..6d8514e4 100644 --- a/gregui/authentication/auth_backends.py +++ b/gregui/authentication/auth_backends.py @@ -244,6 +244,7 @@ class GregOIDCBackend(ValidatingOIDCBackend): person=person, source=settings.FEIDE_SOURCE, verified=Identity.Verified.AUTOMATIC, + # TODO Should this be set at this stage or when the sponsor approves the identity? verified_at=timezone.now(), ) identity.save() -- GitLab