From ad6ff4b64ec9536fcf8b69624986f7c312c80742 Mon Sep 17 00:00:00 2001
From: Philippe Larose <philippe.larose@savoirfairelinux.com>
Date: Tue, 2 Apr 2024 11:03:41 -0400
Subject: [PATCH] jams-react-client: Handle revoked contact

Fixes holes in the contact list where contact that are revoked user where still attempted to be
displayed
Ticket: https://redmine.savoirfairelinux.com/issues/7449

Change-Id: Ib3fddf6c4b24bbd90e30d15b00c45cb306443bec
---
 .../src/views/Contacts/Contacts.tsx           | 39 ++++++++++++-------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/jams-react-client/src/views/Contacts/Contacts.tsx b/jams-react-client/src/views/Contacts/Contacts.tsx
index a94688c3..a28bc0c6 100644
--- a/jams-react-client/src/views/Contacts/Contacts.tsx
+++ b/jams-react-client/src/views/Contacts/Contacts.tsx
@@ -193,22 +193,33 @@ export default function Users(props: UsersProps) {
               null,
               null
             )
-          ).then((response) => {
-            contact.username = response.data.name;
-            axios(
-              configApiCall(
-                api_path_get_user_profile + contact.username,
-                "GET",
-                null,
-                null
+          )
+            .then((response) => {
+              contact.username = response.data.name;
+              axios(
+                configApiCall(
+                  api_path_get_user_profile + contact.username,
+                  "GET",
+                  null,
+                  null
+                )
               )
-            ).then((response) => {
-              contact.profilePicture = response.data.profilePicture;
-              contact.firstName = response.data.firstName;
-              contact.lastName = response.data.lastName;
-              contact.organization = response.data.organization;
+                .then((response) => {
+                  contact.profilePicture = response.data.profilePicture;
+                  contact.firstName = response.data.firstName;
+                  contact.lastName = response.data.lastName;
+                  contact.organization = response.data.organization;
+                })
+                .catch(() => {
+                  // If this point is reached, it means we have a contact that no longer has a profile
+                  // This can happen if the user is removed from the LDAP/AD server
+                  originalContacts.splice(originalContacts.indexOf(contact), 1);
+                });
+            })
+            .catch(() => {
+              // If this point is reached, it means we have a contact that is no longer part of the nameserver
+              originalContacts.splice(originalContacts.indexOf(contact), 1);
             });
-          });
         }
         setContacts(originalContacts);
         setLoading(false);
-- 
GitLab