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

feat: agreement urls #174

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions app/src/main/java/org/openedx/app/AnalyticsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ class AnalyticsManager(
logEvent(Event.COOKIE_POLICY_CLICKED)
}

override fun dataSellClickedEvent() {
logEvent(Event.DATE_SELL_CLICKED)
}

override fun faqClickedEvent() {
logEvent(Event.FAQ_CLICKED)
}

override fun emailSupportClickedEvent() {
logEvent(Event.EMAIL_SUPPORT_CLICKED)
}
Expand Down Expand Up @@ -421,6 +429,8 @@ private enum class Event(val eventName: String) {
PRIVACY_POLICY_CLICKED("Privacy_Policy_Clicked"),
TERMS_OF_USE_CLICKED("Terms_Of_Use_Clicked"),
COOKIE_POLICY_CLICKED("Cookie_Policy_Clicked"),
DATE_SELL_CLICKED("Data_Sell_Clicked"),
FAQ_CLICKED("FAQ_Clicked"),
EMAIL_SUPPORT_CLICKED("Email_Support_Clicked"),
COURSE_ENROLL_CLICKED("Course_Enroll_Clicked"),
COURSE_ENROLL_SUCCESS("Course_Enroll_Success"),
Expand Down
10 changes: 1 addition & 9 deletions app/src/main/java/org/openedx/app/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,7 @@ val appModule = module {
DownloadWorkerController(get(), get(), get())
}

single {
val config = get<Config>()
AppData(
BuildConfig.VERSION_NAME,
config.getFeedbackEmailAddress(),
config.getAgreementUrlsConfig().tosUrl,
config.getAgreementUrlsConfig().privacyPolicyUrl
)
}
single { AppData(versionName = BuildConfig.VERSION_NAME) }
factory { (activity: AppCompatActivity) -> AppReviewManager(activity, get(), get()) }

single { TranscriptManager(get()) }
Expand Down
57 changes: 50 additions & 7 deletions core/src/main/java/org/openedx/core/config/AgreementUrlsConfig.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,57 @@
package org.openedx.core.config

import android.net.Uri
import com.google.gson.annotations.SerializedName
import org.openedx.core.domain.model.Agreement
import org.openedx.core.domain.model.AgreementUrls

data class AgreementUrlsConfig(
internal data class AgreementUrlsConfig(
@SerializedName("PRIVACY_POLICY_URL")
val privacyPolicyUrl: String = "",

private val privacyPolicyUrl: String = "",
@SerializedName("COOKIE_POLICY_URL")
private val cookiePolicyUrl: String = "",
@SerializedName("DATA_SELL_CONSENT_URL")
private val dataSellConsentUrl: String = "",
@SerializedName("TOS_URL")
val tosUrl: String = "",
private val tosUrl: String = "",
@SerializedName("EULA_URL")
private val eulaUrl: String = "",
@SerializedName("SUPPORTED_LANGUAGES")
private val supportedLanguages: List<String> = emptyList(),
) {
fun mapToDomain(): Agreement {
val defaultAgreementUrls = AgreementUrls(
privacyPolicyUrl = privacyPolicyUrl,
cookiePolicyUrl = cookiePolicyUrl,
dataSellConsentUrl = dataSellConsentUrl,
tosUrl = tosUrl,
eulaUrl = eulaUrl,
supportedLanguages = supportedLanguages,
)
val agreementUrls = if (supportedLanguages.isNotEmpty()) {
supportedLanguages.associateWith {
AgreementUrls(
privacyPolicyUrl = privacyPolicyUrl.appendLocale(it),
cookiePolicyUrl = cookiePolicyUrl.appendLocale(it),
dataSellConsentUrl = dataSellConsentUrl.appendLocale(it),
tosUrl = tosUrl.appendLocale(it),
eulaUrl = eulaUrl.appendLocale(it),
supportedLanguages = supportedLanguages,
)
}
} else {
mapOf()
}
return Agreement(agreementUrls, defaultAgreementUrls)
}

@SerializedName("CONTACT_US_URL")
val contactUsUrl: String = "",
)
private fun String.appendLocale(locale: String): String {
if (this.isBlank()) return this
val uri = Uri.parse(this)
return Uri.Builder().scheme(uri.scheme)
.authority(uri.authority)
.appendPath(locale + uri.encodedPath)
.build()
.toString()
}
}
12 changes: 10 additions & 2 deletions core/src/main/java/org/openedx/core/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.google.gson.Gson
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import org.openedx.core.domain.model.AgreementUrls
import java.io.InputStreamReader

class Config(context: Context) {
Expand Down Expand Up @@ -34,12 +35,18 @@ class Config(context: Context) {
return getString(TOKEN_TYPE, "")
}

fun getFaqUrl(): String {
return getString(FAQ_URL, "")
}

fun getFeedbackEmailAddress(): String {
return getString(FEEDBACK_EMAIL_ADDRESS, "")
}

fun getAgreementUrlsConfig(): AgreementUrlsConfig {
return getObjectOrNewInstance(AGREEMENT_URLS, AgreementUrlsConfig::class.java)
fun getAgreement(locale: String): AgreementUrls {
val agreement =
getObjectOrNewInstance(AGREEMENT_URLS, AgreementUrlsConfig::class.java).mapToDomain()
return agreement.getAgreementForLocale(locale)
}

fun getFirebaseConfig(): FirebaseConfig {
Expand Down Expand Up @@ -106,6 +113,7 @@ class Config(context: Context) {
private const val API_HOST_URL = "API_HOST_URL"
private const val OAUTH_CLIENT_ID = "OAUTH_CLIENT_ID"
private const val TOKEN_TYPE = "TOKEN_TYPE"
private const val FAQ_URL = "FAQ_URL"
private const val FEEDBACK_EMAIL_ADDRESS = "FEEDBACK_EMAIL_ADDRESS"
private const val AGREEMENT_URLS = "AGREEMENT_URLS"
private const val WHATS_NEW_ENABLED = "WHATS_NEW_ENABLED"
Expand Down
25 changes: 25 additions & 0 deletions core/src/main/java/org/openedx/core/domain/model/AgreementUrls.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.openedx.core.domain.model

/**
* Data class with information about user agreements URLs
*
* @param agreementUrls Map with keys from SUPPORTED_LANGUAGES config
* @param defaultAgreementUrls AgreementUrls for default language ('en')
*/
internal data class Agreement(
private val agreementUrls: Map<String, AgreementUrls> = mapOf(),
private val defaultAgreementUrls: AgreementUrls
) {
fun getAgreementForLocale(locale: String): AgreementUrls {
return agreementUrls.getOrDefault(locale, defaultAgreementUrls)
}
}

data class AgreementUrls(
val privacyPolicyUrl: String = "",
val cookiePolicyUrl: String = "",
val dataSellConsentUrl: String = "",
val tosUrl: String = "",
val eulaUrl: String = "",
val supportedLanguages: List<String> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ package org.openedx.core.presentation.global

data class AppData(
val versionName: String,
val feedbackEmailAddress: String,
val tosUrl: String,
val privacyPolicyUrl: String,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ package org.openedx.core.presentation.global.webview
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import android.webkit.CookieManager
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import org.koin.android.ext.android.inject
import org.openedx.core.config.Config
import org.openedx.core.ui.WebContentScreen
import org.openedx.core.ui.rememberWindowSize
import org.openedx.core.ui.theme.OpenEdXTheme

class WebContentFragment : Fragment() {

private val config: Config by inject()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -22,6 +28,7 @@ class WebContentFragment : Fragment() {
OpenEdXTheme {
val windowSize = rememberWindowSize()
WebContentScreen(
apiHostUrl = config.getApiHostURL(),
windowSize = windowSize,
title = requireArguments().getString(ARG_TITLE, ""),
contentUrl = requireArguments().getString(ARG_URL, ""),
Expand All @@ -32,6 +39,11 @@ class WebContentFragment : Fragment() {
}
}

override fun onDestroy() {
super.onDestroy()
CookieManager.getInstance().flush()
}

companion object {
private const val ARG_TITLE = "argTitle"
private const val ARG_URL = "argUrl"
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<string name="core_error_unknown_error">Something went wrong</string>
<string name="core_error_try_again">Try again</string>
<string name="core_privacy_policy">Privacy policy</string>
<string name="core_cookie_policy" translatable="false">Cookie policy</string>
k1rill marked this conversation as resolved.
Show resolved Hide resolved
<string name="core_data_sell" translatable="false">Do Not Sell My Personal Information</string>
<string name="core_faq" translatable="false">View FAQ</string>
<string name="core_terms_of_use">Terms of use</string>
<string name="core_profile">Profile</string>
<string name="core_cancel">Cancel</string>
Expand Down
11 changes: 8 additions & 3 deletions default_config/dev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ API_HOST_URL: 'http://localhost:8000'
APPLICATION_ID: 'org.openedx.app'
ENVIRONMENT_DISPLAY_NAME: 'Localhost'
FEEDBACK_EMAIL_ADDRESS: 'support@example.com'
FAQ_URL: ''
OAUTH_CLIENT_ID: 'OAUTH_CLIENT_ID'

# Keep empty to hide setting
AGREEMENT_URLS:
PRIVACY_POLICY_URL: 'https://example.com/privacy'
TOS_URL: 'https://example.com/tos'
CONTACT_US_URL: 'https://example.com/contact'
PRIVACY_POLICY_URL: ''
COOKIE_POLICY_URL: ''
DATA_SELL_CONSENT_URL: ''
TOS_URL: ''
EULA_URL: ''
SUPPORTED_LANGUAGES: [ ] #en is defalut language

GOOGLE:
ENABLED: false
Expand Down
11 changes: 8 additions & 3 deletions default_config/prod/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ API_HOST_URL: 'http://localhost:8000'
APPLICATION_ID: 'org.openedx.app'
ENVIRONMENT_DISPLAY_NAME: 'Localhost'
FEEDBACK_EMAIL_ADDRESS: 'support@example.com'
FAQ_URL: ''
OAUTH_CLIENT_ID: 'OAUTH_CLIENT_ID'

# Keep empty to hide setting
AGREEMENT_URLS:
PRIVACY_POLICY_URL: 'https://example.com/privacy'
TOS_URL: 'https://example.com/tos'
CONTACT_US_URL: 'https://example.com/contact'
PRIVACY_POLICY_URL: ''
COOKIE_POLICY_URL: ''
DATA_SELL_CONSENT_URL: ''
TOS_URL: ''
EULA_URL: ''
SUPPORTED_LANGUAGES: [ ] #en is defalut language

GOOGLE:
ENABLED: false
Expand Down
11 changes: 8 additions & 3 deletions default_config/stage/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ API_HOST_URL: 'http://localhost:8000'
APPLICATION_ID: 'org.openedx.app'
ENVIRONMENT_DISPLAY_NAME: 'Localhost'
FEEDBACK_EMAIL_ADDRESS: 'support@example.com'
FAQ_URL: ''
OAUTH_CLIENT_ID: 'OAUTH_CLIENT_ID'

# Keep empty to hide setting
AGREEMENT_URLS:
PRIVACY_POLICY_URL: 'https://example.com/privacy'
TOS_URL: 'https://example.com/tos'
CONTACT_US_URL: 'https://example.com/contact'
PRIVACY_POLICY_URL: ''
COOKIE_POLICY_URL: ''
DATA_SELL_CONSENT_URL: ''
TOS_URL: ''
EULA_URL: ''
SUPPORTED_LANGUAGES: [ ] #en is defalut language

GOOGLE:
ENABLED: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.openedx.profile.domain.model

import org.openedx.core.domain.model.AgreementUrls

/**
* @param agreementUrls User agreement urls
* @param faqUrl FAQ url
* @param supportEmail Email address of support
* @param versionName Version of the application (1.0.0)
*/
data class Configuration(
val agreementUrls: AgreementUrls,
val faqUrl: String,
val supportEmail: String,
val versionName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface ProfileAnalytics {
fun privacyPolicyClickedEvent()
fun termsOfUseClickedEvent()
fun cookiePolicyClickedEvent()
fun dataSellClickedEvent()
fun faqClickedEvent()
fun emailSupportClickedEvent()
fun logoutEvent(force: Boolean)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ class ProfileFragment : Fragment() {
)
}

ProfileViewAction.CookiePolicyClick -> {
viewModel.cookiePolicyClicked(
requireParentFragment().parentFragmentManager
)
}

ProfileViewAction.DataSellClick -> {
viewModel.dataSellClicked(
requireParentFragment().parentFragmentManager
)
}

ProfileViewAction.FaqClick -> viewModel.faqClicked()

ProfileViewAction.SupportClick -> {
viewModel.emailSupportClicked(requireContext())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.openedx.profile.presentation.profile

import org.openedx.profile.domain.model.Account
import org.openedx.profile.domain.model.Configuration

sealed class ProfileUIState {
/**
* @param account User account data
* @param versionName Version of the application (1.0.0)
* @param configuration Configuration data
*/
data class Data(
val account: Account,
val versionName: String,
val configuration: Configuration,
) : ProfileUIState()

object Loading : ProfileUIState()
Expand Down
Loading