diff --git a/frontend/public/locales/en/common.json b/frontend/public/locales/en/common.json index 26c3f0a8f2ed9fe251e2970efe78734030ec6e0c..99cb2eb41242339956b588973be835ec17bd8154 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 82dea3fab69a8396b24ed7ee83ae2d3cdbbaad7b..d00ca77e4d637c2f547173f36138962675a8adae 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 1d6b0f8f743dbad1a2820b16389643c84f3083e8..b82e4f093177a54e5f8084af6ed6bf77312f9175 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 f4f3743601db92a13c93f96bab60c06ee25410a9..09e7da4288e247fdf95e43dce5e164bd20956daa 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 6cdc89b0638ac43865a3f5b89c14f8550501a55c..be010f6e8977b9f656ddf88e6fa5a5beda2683e3 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 f21ca1311f67f2e13bd146159567a25b79d109fb..8ce656e09a49cf9859cf06d8342ca142dd77e119 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 2432ba0dede5c942bf325f90ee38f35656299ad8..1eca446e5a7694f7118c63ba33328b84240b4e87 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 74b897c1de1035368d5977430e2aa4224348273d..6d8514e4f3dbbf9335ad7639de8842b3bd213f8c 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()