-
Notifications
You must be signed in to change notification settings - Fork 146
Introduce typed age eligibility decisions #16374
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
120a009
81f3642
1fc25e6
47474be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package com.woocommerce.android.ui.ageeligibility | ||
|
|
||
| import javax.inject.Inject | ||
|
|
||
| class AgeEligibilityEvaluator @Inject constructor() { | ||
| fun evaluateLegacyResult( | ||
| result: AgeCheckResult, | ||
| priorRestriction: AgeRestrictionReason? | ||
| ): AgeEligibilityEvaluation = when (result.verificationStatus) { | ||
| LegacyAgeVerificationStatus.VERIFIED -> authoritativeAllowed() | ||
| LegacyAgeVerificationStatus.SUPERVISED, | ||
| LegacyAgeVerificationStatus.SUPERVISED_APPROVAL_PENDING -> evaluateAgeUpper( | ||
| ageUpper = result.ageUpper, | ||
| priorRestriction = priorRestriction | ||
| ) | ||
|
|
||
| LegacyAgeVerificationStatus.SUPERVISED_APPROVAL_DENIED -> authoritativeRestriction( | ||
| AgeRestrictionReason.SUPERVISED_APPROVAL_DENIED | ||
| ) | ||
|
|
||
| LegacyAgeVerificationStatus.UNKNOWN, | ||
| LegacyAgeVerificationStatus.UNEXPECTED -> nonAuthoritative(priorRestriction) | ||
| } | ||
|
|
||
| fun preservePriorRestriction(priorRestriction: AgeRestrictionReason?): AgeEligibilityEvaluation = | ||
| nonAuthoritative(priorRestriction) | ||
|
|
||
| private fun evaluateAgeUpper( | ||
| ageUpper: Int?, | ||
| priorRestriction: AgeRestrictionReason? | ||
| ): AgeEligibilityEvaluation = when { | ||
| ageUpper == null -> nonAuthoritative(priorRestriction) | ||
| ageUpper < WOOCOMMERCE_TOS_MINIMUM_AGE_FOR_APP_USE -> authoritativeRestriction( | ||
| AgeRestrictionReason.BELOW_MINIMUM_AGE | ||
| ) | ||
|
|
||
| else -> authoritativeAllowed() | ||
| } | ||
|
|
||
| private fun authoritativeAllowed() = AgeEligibilityEvaluation( | ||
| decision = AgeEligibilityDecision.Allowed, | ||
| isAuthoritative = true | ||
| ) | ||
|
|
||
| private fun authoritativeRestriction(reason: AgeRestrictionReason) = AgeEligibilityEvaluation( | ||
| decision = AgeEligibilityDecision.Restricted(reason), | ||
| isAuthoritative = true | ||
| ) | ||
|
|
||
| private fun nonAuthoritative(priorRestriction: AgeRestrictionReason?) = AgeEligibilityEvaluation( | ||
| decision = priorRestriction?.let(AgeEligibilityDecision::Restricted) ?: AgeEligibilityDecision.Allowed, | ||
| isAuthoritative = false | ||
| ) | ||
|
|
||
| companion object { | ||
| private const val WOOCOMMERCE_TOS_MINIMUM_AGE_FOR_APP_USE = 13 | ||
| } | ||
| } | ||
|
|
||
| sealed interface AgeEligibilityDecision { | ||
| data object Allowed : AgeEligibilityDecision | ||
|
|
||
| data object VerificationRequired : AgeEligibilityDecision | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI Code Review [nit] Issue: Suggestion: Remove the unused variant, or wire it up (evaluator output + message mapping + UI handling) if it's intended for an upcoming step.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping it. It is temporary dormant scaffolding wired immediately in the next PR |
||
|
|
||
| data class Restricted(val reason: AgeRestrictionReason) : AgeEligibilityDecision | ||
| } | ||
|
|
||
| enum class AgeRestrictionReason { | ||
| BELOW_MINIMUM_AGE, | ||
| LEGACY_RESTRICTION_UNKNOWN_REASON, | ||
| SUPERVISED_APPROVAL_DENIED | ||
| } | ||
|
|
||
| enum class AgeCheckTrigger { | ||
| STARTUP, | ||
| MANUAL_RETRY, | ||
| RETURN_FROM_PLAY_STORE | ||
| } | ||
|
|
||
| data class AgeEligibilityEvaluation( | ||
| val decision: AgeEligibilityDecision, | ||
| val isAuthoritative: Boolean | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.