Skip to content
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
3 changes: 2 additions & 1 deletion Documentation/ConfigurationManagement.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ android:
- **WHATS_NEW_ENABLED:** Enables the "What's New" feature to present the latest changes to the user.
- **SOCIAL_AUTH_ENABLED:** Enables SSO buttons on the SignIn and SignUp screens.
- **COURSE_DROPDOWN_NAVIGATION_ENABLED:** Enables an alternative navigation through units.
- **COURSE_UNIT_PROGRESS_ENABLED:** Enables the display of the unit progress within the courseware.
- **COURSE_UNIT_PROGRESS_ENABLED:** Enables the display of the unit progress within the courseware.
- **REGISTRATION_ENABLED:** Enables user registration from the app.

## Future Support
- To add config related to some other service, create a class, e.g. `ServiceNameConfig.kt`, to be able to populate related fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class LogistrationFragment : Fragment() {
},
onSearchClick = { querySearch ->
viewModel.navigateToDiscovery(parentFragmentManager, querySearch)
}
},
isRegistrationEnabled = viewModel.isRegistrationEnabled
)
}
}
Expand All @@ -98,6 +99,7 @@ private fun LogistrationScreen(
onSearchClick: (String) -> Unit,
onRegisterClick: () -> Unit,
onSignInClick: () -> Unit,
isRegistrationEnabled: Boolean,
) {

var textFieldValue by rememberSaveable(stateSaver = TextFieldValue.Saver) {
Expand Down Expand Up @@ -183,7 +185,11 @@ private fun LogistrationScreen(

Spacer(modifier = Modifier.weight(1f))

AuthButtonsPanel(onRegisterClick = onRegisterClick, onSignInClick = onSignInClick)
AuthButtonsPanel(
onRegisterClick = onRegisterClick,
onSignInClick = onSignInClick,
showRegisterButton = isRegistrationEnabled
)
}
}
}
Expand All @@ -199,7 +205,24 @@ private fun LogistrationPreview() {
LogistrationScreen(
onSearchClick = {},
onSignInClick = {},
onRegisterClick = {}
onRegisterClick = {},
isRegistrationEnabled = true,
)
}
}

@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(name = "NEXUS_9_Light", device = Devices.NEXUS_9, uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(name = "NEXUS_9_Night", device = Devices.NEXUS_9, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun LogistrationRegistrationDisabledPreview() {
OpenEdXTheme {
LogistrationScreen(
onSearchClick = {},
onSignInClick = {},
onRegisterClick = {},
isRegistrationEnabled = false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class LogistrationViewModel(
) : BaseViewModel() {

private val discoveryTypeWebView get() = config.getDiscoveryConfig().isViewTypeWebView()
val isRegistrationEnabled get() = config.isRegistrationEnabled()

init {
logLogistrationScreenEvent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal data class SignInUIState(
val isMicrosoftAuthEnabled: Boolean = false,
val isSocialAuthEnabled: Boolean = false,
val isLogistrationEnabled: Boolean = false,
val isRegistrationEnabled: Boolean = true,
val showProgress: Boolean = false,
val loginSuccess: Boolean = false,
val agreement: RegistrationField? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SignInViewModel(
isMicrosoftAuthEnabled = config.getMicrosoftConfig().isEnabled(),
isSocialAuthEnabled = config.isSocialAuthEnabled(),
isLogistrationEnabled = config.isPreLoginExperienceEnabled(),
isRegistrationEnabled = config.isRegistrationEnabled(),
agreement = agreementProvider.getAgreement(isSignIn = true)?.createHonorCodeField(),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private fun AuthForm(
.fillMaxWidth()
.padding(top = 20.dp, bottom = 36.dp)
) {
if (state.isLogistrationEnabled.not()) {
if (state.isLogistrationEnabled.not() && state.isRegistrationEnabled) {
Text(
modifier = Modifier
.testTag("txt_register")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class SignInViewModelTest {
every { calendarPreferences.clearCalendarPreferences() } returns Unit
coEvery { calendarInteractor.clearCalendarCachedData() } returns Unit
every { analytics.logScreenEvent(any(), any()) } returns Unit
every { config.isRegistrationEnabled() } returns true
}

@After
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/openedx/core/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class Config(context: Context) {
return getObjectOrNewInstance(UI_COMPONENTS, UIConfig::class.java)
}

fun isRegistrationEnabled(): Boolean {
return getBoolean(REGISTRATION_ENABLED, true)
}

private fun getString(key: String, defaultValue: String = ""): String {
val element = getObject(key)
return if (element != null) {
Expand Down Expand Up @@ -168,6 +172,7 @@ class Config(context: Context) {
private const val GOOGLE = "GOOGLE"
private const val MICROSOFT = "MICROSOFT"
private const val PRE_LOGIN_EXPERIENCE_ENABLED = "PRE_LOGIN_EXPERIENCE_ENABLED"
private const val REGISTRATION_ENABLED = "REGISTRATION_ENABLED"
private const val DISCOVERY = "DISCOVERY"
private const val PROGRAM = "PROGRAM"
private const val DASHBOARD = "DASHBOARD"
Expand Down
34 changes: 21 additions & 13 deletions core/src/main/java/org/openedx/core/ui/ComposeCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1183,24 +1183,32 @@ fun ConnectionErrorView(
fun AuthButtonsPanel(
onRegisterClick: () -> Unit,
onSignInClick: () -> Unit,
showRegisterButton: Boolean,
) {
Row {
OpenEdXButton(
modifier = Modifier
.testTag("btn_register")
.width(0.dp)
.weight(1f),
text = stringResource(id = R.string.core_register),
textColor = MaterialTheme.appColors.primaryButtonText,
backgroundColor = MaterialTheme.appColors.secondaryButtonBackground,
onClick = { onRegisterClick() }
)
if (showRegisterButton) {
OpenEdXButton(
modifier = Modifier
.testTag("btn_register")
.width(0.dp)
.weight(1f),
text = stringResource(id = R.string.core_register),
textColor = MaterialTheme.appColors.primaryButtonText,
backgroundColor = MaterialTheme.appColors.secondaryButtonBackground,
onClick = { onRegisterClick() }
)
}

OpenEdXOutlinedButton(
modifier = Modifier
.testTag("btn_sign_in")
.width(100.dp)
.padding(start = 16.dp),
.then(
if (showRegisterButton) {
Modifier.width(100.dp).padding(start = 16.dp)
} else {
Modifier.weight(1f)
}
),
text = stringResource(id = R.string.core_sign_in),
onClick = { onSignInClick() },
textColor = MaterialTheme.appColors.secondaryButtonBorderedText,
Expand Down Expand Up @@ -1333,7 +1341,7 @@ private fun ToolbarPreview() {
@Preview
@Composable
private fun AuthButtonsPanelPreview() {
AuthButtonsPanel(onRegisterClick = {}, onSignInClick = {})
AuthButtonsPanel(onRegisterClick = {}, onSignInClick = {}, showRegisterButton = true)
}

@Preview
Expand Down
2 changes: 2 additions & 0 deletions default_config/dev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ TOKEN_TYPE: "JWT"
WHATS_NEW_ENABLED: false
#feature flag enable Social Login buttons
SOCIAL_AUTH_ENABLED: false
#feature flag to enable registration from app
REGISTRATION_ENABLED: true
#Course navigation feature flags
UI_COMPONENTS:
COURSE_DROPDOWN_NAVIGATION_ENABLED: false
Expand Down
2 changes: 2 additions & 0 deletions default_config/prod/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ TOKEN_TYPE: "JWT"
WHATS_NEW_ENABLED: false
#feature flag enable Social Login buttons
SOCIAL_AUTH_ENABLED: false
#feature flag to enable registration from app
REGISTRATION_ENABLED: true
#Course navigation feature flags
UI_COMPONENTS:
COURSE_DROPDOWN_NAVIGATION_ENABLED: false
Expand Down
2 changes: 2 additions & 0 deletions default_config/stage/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ TOKEN_TYPE: "JWT"
WHATS_NEW_ENABLED: false
#feature flag enable Social Login buttons
SOCIAL_AUTH_ENABLED: false
#feature flag to enable registration from app
REGISTRATION_ENABLED: true
#Course navigation feature flags
UI_COMPONENTS:
COURSE_DROPDOWN_NAVIGATION_ENABLED: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class NativeDiscoveryFragment : Fragment() {
hasInternetConnection = viewModel.hasInternetConnection,
canShowBackButton = viewModel.canShowBackButton,
isUserLoggedIn = viewModel.isUserLoggedIn,
isRegistrationEnabled = viewModel.isRegistrationEnabled,
appUpgradeParameters = AppUpdateState.AppUpgradeParameters(
appUpgradeEvent = appUpgradeEvent,
wasUpdateDialogClosed = wasUpdateDialogClosed,
Expand Down Expand Up @@ -209,6 +210,7 @@ internal fun DiscoveryScreen(
hasInternetConnection: Boolean,
canShowBackButton: Boolean,
isUserLoggedIn: Boolean,
isRegistrationEnabled: Boolean,
appUpgradeParameters: AppUpdateState.AppUpgradeParameters,
onSearchClick: () -> Unit,
onSwipeRefresh: () -> Unit,
Expand Down Expand Up @@ -252,7 +254,8 @@ internal fun DiscoveryScreen(
) {
AuthButtonsPanel(
onRegisterClick = onRegisterClick,
onSignInClick = onSignInClick
onSignInClick = onSignInClick,
showRegisterButton = isRegistrationEnabled
)
}
}
Expand Down Expand Up @@ -517,6 +520,7 @@ private fun DiscoveryScreenPreview() {
refreshing = false,
hasInternetConnection = true,
isUserLoggedIn = false,
isRegistrationEnabled = true,
appUpgradeParameters = AppUpdateState.AppUpgradeParameters(),
onSignInClick = {},
onRegisterClick = {},
Expand Down Expand Up @@ -558,6 +562,7 @@ private fun DiscoveryScreenTabletPreview() {
refreshing = false,
hasInternetConnection = true,
isUserLoggedIn = true,
isRegistrationEnabled = true,
appUpgradeParameters = AppUpdateState.AppUpgradeParameters(),
onSignInClick = {},
onRegisterClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class NativeDiscoveryViewModel(
val apiHostUrl get() = config.getApiHostURL()
val isUserLoggedIn get() = corePreferences.user != null
val canShowBackButton get() = config.isPreLoginExperienceEnabled() && !isUserLoggedIn
val isRegistrationEnabled: Boolean get() = config.isRegistrationEnabled()

private val _uiState = MutableLiveData<DiscoveryUIState>(DiscoveryUIState.Loading)
val uiState: LiveData<DiscoveryUIState>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class WebViewDiscoveryFragment : Fragment() {
isPreLogin = viewModel.isPreLogin,
contentUrl = viewModel.discoveryUrl,
uriScheme = viewModel.uriScheme,
isRegistrationEnabled = viewModel.isRegistrationEnabled,
hasInternetConnection = hasInternetConnection,
checkInternetConnection = {
hasInternetConnection = viewModel.hasInternetConnection
Expand Down Expand Up @@ -173,6 +174,7 @@ private fun WebViewDiscoveryScreen(
isPreLogin: Boolean,
contentUrl: String,
uriScheme: String,
isRegistrationEnabled: Boolean,
hasInternetConnection: Boolean,
checkInternetConnection: () -> Unit,
onWebPageUpdated: (String) -> Unit,
Expand Down Expand Up @@ -206,7 +208,8 @@ private fun WebViewDiscoveryScreen(
) {
AuthButtonsPanel(
onRegisterClick = onRegisterClick,
onSignInClick = onSignInClick
onSignInClick = onSignInClick,
showRegisterButton = isRegistrationEnabled
)
}
}
Expand Down Expand Up @@ -363,6 +366,7 @@ private fun WebViewDiscoveryScreenPreview() {
contentUrl = "https://www.example.com/",
isPreLogin = false,
uriScheme = "",
isRegistrationEnabled = true,
hasInternetConnection = false,
checkInternetConnection = {},
onWebPageUpdated = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class WebViewDiscoveryViewModel(
private val webViewConfig get() = config.getDiscoveryConfig().webViewConfig

val isPreLogin get() = config.isPreLoginExperienceEnabled() && corePreferences.user == null
val isRegistrationEnabled: Boolean get() = config.isRegistrationEnabled()

private var _discoveryUrl = webViewConfig.baseUrl
val discoveryUrl: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class CourseDetailsFragment : Fragment() {
),
hasInternetConnection = viewModel.hasInternetConnection,
isUserLoggedIn = viewModel.isUserLoggedIn,
isRegistrationEnabled = viewModel.isRegistrationEnabled,
onReloadClick = {
viewModel.getCourseDetail()
},
Expand Down Expand Up @@ -211,6 +212,7 @@ internal fun CourseDetailsScreen(
htmlBody: String,
hasInternetConnection: Boolean,
isUserLoggedIn: Boolean,
isRegistrationEnabled: Boolean,
onReloadClick: () -> Unit,
onBackClick: () -> Unit,
onButtonClick: () -> Unit,
Expand Down Expand Up @@ -238,7 +240,8 @@ internal fun CourseDetailsScreen(
Box(modifier = Modifier.padding(horizontal = 16.dp, vertical = 32.dp)) {
AuthButtonsPanel(
onRegisterClick = onRegisterClick,
onSignInClick = onSignInClick
onSignInClick = onSignInClick,
showRegisterButton = isRegistrationEnabled
)
}
}
Expand Down Expand Up @@ -694,6 +697,7 @@ private fun CourseDetailNativeContentPreview() {
apiHostUrl = "http://localhost:8000",
hasInternetConnection = false,
isUserLoggedIn = true,
isRegistrationEnabled = true,
htmlBody = "<b>Preview text</b>",
onReloadClick = {},
onBackClick = {},
Expand All @@ -716,6 +720,7 @@ private fun CourseDetailNativeContentTabletPreview() {
apiHostUrl = "http://localhost:8000",
hasInternetConnection = false,
isUserLoggedIn = true,
isRegistrationEnabled = true,
htmlBody = "<b>Preview text</b>",
onReloadClick = {},
onBackClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CourseDetailsViewModel(
) : BaseViewModel() {
val apiHostUrl get() = config.getApiHostURL()
val isUserLoggedIn get() = corePreferences.user != null
val isRegistrationEnabled: Boolean get() = config.isRegistrationEnabled()

private val _uiState = MutableLiveData<CourseDetailsUIState>(CourseDetailsUIState.Loading)
val uiState: LiveData<CourseDetailsUIState>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class CourseInfoFragment : Fragment() {
uiMessage = uiMessage,
uriScheme = viewModel.uriScheme,
hasInternetConnection = hasInternetConnection,
isRegistrationEnabled = viewModel.isRegistrationEnabled,
checkInternetConnection = {
hasInternetConnection = viewModel.hasInternetConnection
},
Expand Down Expand Up @@ -222,6 +223,7 @@ private fun CourseInfoScreen(
uiState: CourseInfoUIState,
uiMessage: UIMessage?,
uriScheme: String,
isRegistrationEnabled: Boolean,
hasInternetConnection: Boolean,
checkInternetConnection: () -> Unit,
onRegisterClick: () -> Unit,
Expand Down Expand Up @@ -250,7 +252,8 @@ private fun CourseInfoScreen(
) {
AuthButtonsPanel(
onRegisterClick = onRegisterClick,
onSignInClick = onSignInClick
onSignInClick = onSignInClick,
showRegisterButton = isRegistrationEnabled
)
}
}
Expand Down Expand Up @@ -364,6 +367,7 @@ fun CourseInfoScreenPreview() {
),
uiMessage = null,
uriScheme = "",
isRegistrationEnabled = true,
hasInternetConnection = false,
checkInternetConnection = {},
onRegisterClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class CourseInfoViewModel(
val hasInternetConnection: Boolean
get() = networkConnection.isOnline()

val isRegistrationEnabled: Boolean get() = config.isRegistrationEnabled()

val uriScheme: String get() = config.getUriScheme()

private val webViewConfig get() = config.getDiscoveryConfig().webViewConfig
Expand Down
Loading