From 094594b75ef637966adf25f6c7515aee452a6096 Mon Sep 17 00:00:00 2001
From: Tore Brede <Tore.Brede@uib.no>
Date: Tue, 19 Oct 2021 14:47:46 +0200
Subject: [PATCH] GREG-85: Adding some meta information to be sent to the
 client

---
 frontend/src/routes/guest/register/guestDataForm.ts |  1 +
 frontend/src/routes/guest/register/index.tsx        | 12 +++++++++---
 gregui/api/views/invitation.py                      |  7 +++++--
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/frontend/src/routes/guest/register/guestDataForm.ts b/frontend/src/routes/guest/register/guestDataForm.ts
index 7c7394db..75d0307f 100644
--- a/frontend/src/routes/guest/register/guestDataForm.ts
+++ b/frontend/src/routes/guest/register/guestDataForm.ts
@@ -23,4 +23,5 @@ export type ContactInformationBySponsor = {
   passport?: string
 
   user_information_source: AuthenticationMethod
+  fnr_verified: boolean
 }
diff --git a/frontend/src/routes/guest/register/index.tsx b/frontend/src/routes/guest/register/index.tsx
index 497a7f66..b50611a6 100644
--- a/frontend/src/routes/guest/register/index.tsx
+++ b/frontend/src/routes/guest/register/index.tsx
@@ -52,6 +52,7 @@ export default function GuestRegister() {
       fnr: '',
       passport: '',
       user_information_source: AuthenticationMethod.Feide,
+      fnr_verified: false,
     })
 
   const guestContactInfo = async () => {
@@ -60,8 +61,12 @@ export default function GuestRegister() {
 
       if (response.ok) {
         response.json().then((jsonResponse) => {
-          // TODO Set up so that information about the authentication method is included in the response from the server (if the user is logged in by Feide)
-          const userSource = AuthenticationMethod.NationalIdNumberOrPassport
+          const authenticationMethod =
+            jsonResponse.meta.form_type === 'manual'
+              ? AuthenticationMethod.NationalIdNumberOrPassport
+              : AuthenticationMethod.Feide
+
+          const fnrVerified = jsonResponse.meta.fnr_verified === true
 
           setGuestFormData({
             first_name: jsonResponse.person.first_name,
@@ -79,7 +84,8 @@ export default function GuestRegister() {
             fnr: jsonResponse.fnr,
             passport: jsonResponse.passport,
 
-            user_information_source: userSource,
+            user_information_source: authenticationMethod,
+            fnr_verified: fnrVerified,
           })
         })
       }
diff --git a/gregui/api/views/invitation.py b/gregui/api/views/invitation.py
index c6e893df..f356a035 100644
--- a/gregui/api/views/invitation.py
+++ b/gregui/api/views/invitation.py
@@ -19,7 +19,6 @@ from greg.permissions import IsSponsor
 from gregui.api.serializers.guest import GuestRegisterSerializer
 from gregui.api.serializers.invitation import InviteGuestSerializer
 
-
 from gregui.models import GregUserProfile
 
 
@@ -133,6 +132,9 @@ class InvitedGuestView(GenericAPIView):
         person = role.person
         sponsor = role.sponsor_id
 
+        # If the user is not logged in then tell the client to take him through the manual registration process
+        is_not_logged_in = request.user
+
         fnr_verified = False
         try:
             fnr = person.identities.get(type=Identity.IdentityType.NORWEGIAN_NATIONAL_ID_NUMBER)
@@ -170,7 +172,8 @@ class InvitedGuestView(GenericAPIView):
                 "comments": role.comments,
             },
             "meta": {
-                "fnr_verified": fnr_verified
+                "form_type": is_not_logged_in,
+                "fnr_verified": fnr_verified,
             }
         }
         return JsonResponse(data=data, status=status.HTTP_200_OK)
-- 
GitLab