From 98f87c76263aa3053b7657cdfa6137e12751fc59 Mon Sep 17 00:00:00 2001 From: Comfort Mwalija <42068747+calmwalija@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:46:41 +0200 Subject: [PATCH] [Quest/Malawi Core] Feature Request: Disable users from logging in without a complete practitioner details response (#97) --- .../fhircore/engine/ui/login/LoginErrorState.kt | 1 + .../fhircore/engine/ui/login/LoginScreen.kt | 5 +++++ .../fhircore/engine/ui/login/LoginViewModel.kt | 14 ++++++++++---- android/engine/src/main/res/values/strings.xml | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginErrorState.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginErrorState.kt index 5a0066b527..6f83b21d02 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginErrorState.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginErrorState.kt @@ -21,4 +21,5 @@ enum class LoginErrorState { INVALID_CREDENTIALS, MULTI_USER_LOGIN_ATTEMPT, ERROR_FETCHING_USER, + ACCOUNT_NOT_CONFIGURED_PROPERLY, } diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginScreen.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginScreen.kt index f359e2dee6..4abdac2a4d 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginScreen.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginScreen.kt @@ -277,6 +277,11 @@ fun LoginPage( id = R.string.login_error, stringResource(R.string.error_fetching_user_details), ) + LoginErrorState.ACCOUNT_NOT_CONFIGURED_PROPERLY -> + stringResource( + id = R.string.login_error, + stringResource(R.string.error_account_not_configured_properly), + ) }, modifier = modifier diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginViewModel.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginViewModel.kt index 176ed1efbf..294b49f8f1 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginViewModel.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginViewModel.kt @@ -204,10 +204,13 @@ constructor( val practitionerDetailsResult = fetchPractitioner(userInfo.keycloakUuid) if (practitionerDetailsResult.isFailure) return - savePractitionerDetails(practitionerDetailsResult.getOrDefault(Bundle()), userInfo) + if (savePractitionerDetails(practitionerDetailsResult.getOrDefault(Bundle()), userInfo)) { + updateNavigateHome(true) + } else { + _loginErrorState.postValue(LoginErrorState.ACCOUNT_NOT_CONFIGURED_PROPERLY) + } _showProgressBar.postValue(false) - updateNavigateHome(true) } } } catch (ex: Exception) { @@ -272,8 +275,8 @@ constructor( _navigateToHome.postValue(navigateHome) } - suspend fun savePractitionerDetails(bundle: Bundle, userClaimInfo: UserClaimInfo) { - if (bundle.entry.isNullOrEmpty()) return + suspend fun savePractitionerDetails(bundle: Bundle, userClaimInfo: UserClaimInfo): Boolean { + if (bundle.entry.isNullOrEmpty()) return false val practitionerDetails = bundle.entry.first().resource as PractitionerDetails if ( @@ -293,6 +296,8 @@ constructor( practitionerDetails.fhirPractitionerDetails?.practitionerRoles ?: emptyList() val practitioners = practitionerDetails.fhirPractitionerDetails?.practitioners ?: emptyList() + if (organizations.isEmpty() || locations.isEmpty() || careTeams.isEmpty()) return false + val remoteResources = careTeams.toTypedArray() + organizations.toTypedArray() + @@ -330,6 +335,7 @@ constructor( ), ) } + return true } fun loadLastLoggedInUsername() { diff --git a/android/engine/src/main/res/values/strings.xml b/android/engine/src/main/res/values/strings.xml index a36eeb485c..fa18589c55 100644 --- a/android/engine/src/main/res/values/strings.xml +++ b/android/engine/src/main/res/values/strings.xml @@ -112,6 +112,7 @@ "Invalid form id attached" Attempted to login with a different provider Failed to fetch user details + Account not configured properly No Yes There is no response to the required field.