Skip to content

Commit

Permalink
[Quest/Malawi Core] Feature Request: Disable users from logging in wi…
Browse files Browse the repository at this point in the history
…thout a complete practitioner details response (#97)
  • Loading branch information
calmwalija authored Aug 14, 2024
1 parent 736b887 commit 98f87c7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ enum class LoginErrorState {
INVALID_CREDENTIALS,
MULTI_USER_LOGIN_ATTEMPT,
ERROR_FETCHING_USER,
ACCOUNT_NOT_CONFIGURED_PROPERLY,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 (
Expand All @@ -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<Resource>() +
organizations.toTypedArray() +
Expand Down Expand Up @@ -330,6 +335,7 @@ constructor(
),
)
}
return true
}

fun loadLastLoggedInUsername() {
Expand Down
1 change: 1 addition & 0 deletions android/engine/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<string name="invalid_form_id">"Invalid form id attached"</string>
<string name="multi_user_login_attempt">Attempted to login with a different provider</string>
<string name="error_fetching_user_details">Failed to fetch user details</string>
<string name="error_account_not_configured_properly">Account not configured properly</string>
<string name="no">No</string>
<string name="yes">Yes</string>
<string name="required_constraint_validation_error_msg">There is no response to the required field.</string>
Expand Down

0 comments on commit 98f87c7

Please sign in to comment.