Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Quest/Malawi Core] Feature Request: Disable users from logging in without a complete practitioner details response #97

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading