Skip to content

Commit 1d86e50

Browse files
committed
[Quest/Malawi Core] Feature Request: Disable users from logging in without a complete practitioner details response
1 parent 3890584 commit 1d86e50

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginErrorState.kt

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ enum class LoginErrorState {
2121
INVALID_CREDENTIALS,
2222
MULTI_USER_LOGIN_ATTEMPT,
2323
ERROR_FETCHING_USER,
24+
ACCOUNT_NOT_CONFIGURED_PROPERLY,
2425
}

android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginScreen.kt

+5
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ fun LoginPage(
277277
id = R.string.login_error,
278278
stringResource(R.string.error_fetching_user_details),
279279
)
280+
LoginErrorState.ACCOUNT_NOT_CONFIGURED_PROPERLY ->
281+
stringResource(
282+
id = R.string.login_error,
283+
stringResource(R.string.error_account_not_configured_properly),
284+
)
280285
},
281286
modifier =
282287
modifier

android/engine/src/main/java/org/smartregister/fhircore/engine/ui/login/LoginViewModel.kt

+10-4
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,13 @@ constructor(
204204
val practitionerDetailsResult = fetchPractitioner(userInfo.keycloakUuid)
205205
if (practitionerDetailsResult.isFailure) return
206206

207-
savePractitionerDetails(practitionerDetailsResult.getOrDefault(Bundle()), userInfo)
207+
if (savePractitionerDetails(practitionerDetailsResult.getOrDefault(Bundle()), userInfo)) {
208+
updateNavigateHome(true)
209+
} else {
210+
_loginErrorState.postValue(LoginErrorState.ACCOUNT_NOT_CONFIGURED_PROPERLY)
211+
}
208212

209213
_showProgressBar.postValue(false)
210-
updateNavigateHome(true)
211214
}
212215
}
213216
} catch (ex: Exception) {
@@ -272,8 +275,8 @@ constructor(
272275
_navigateToHome.postValue(navigateHome)
273276
}
274277

275-
suspend fun savePractitionerDetails(bundle: Bundle, userClaimInfo: UserClaimInfo) {
276-
if (bundle.entry.isNullOrEmpty()) return
278+
suspend fun savePractitionerDetails(bundle: Bundle, userClaimInfo: UserClaimInfo): Boolean {
279+
if (bundle.entry.isNullOrEmpty()) return false
277280
val practitionerDetails = bundle.entry.first().resource as PractitionerDetails
278281

279282
if (
@@ -293,6 +296,8 @@ constructor(
293296
practitionerDetails.fhirPractitionerDetails?.practitionerRoles ?: emptyList()
294297
val practitioners = practitionerDetails.fhirPractitionerDetails?.practitioners ?: emptyList()
295298

299+
if (organizations.isEmpty() || locations.isEmpty() || careTeams.isEmpty()) return false
300+
296301
val remoteResources =
297302
careTeams.toTypedArray<Resource>() +
298303
organizations.toTypedArray() +
@@ -330,6 +335,7 @@ constructor(
330335
),
331336
)
332337
}
338+
return true
333339
}
334340

335341
fun loadLastLoggedInUsername() {

android/engine/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<string name="invalid_form_id">"Invalid form id attached"</string>
113113
<string name="multi_user_login_attempt">Attempted to login with a different provider</string>
114114
<string name="error_fetching_user_details">Failed to fetch user details</string>
115+
<string name="error_account_not_configured_properly">Account not configured properly</string>
115116
<string name="no">No</string>
116117
<string name="yes">Yes</string>
117118
<string name="required_constraint_validation_error_msg">There is no response to the required field.</string>

0 commit comments

Comments
 (0)