Compare commits
5 Commits
62e426c38d
...
5b83b7209b
Author | SHA1 | Date | |
---|---|---|---|
5b83b7209b | |||
9dc692394d | |||
a79969f88a | |||
2c4782b5c6 | |||
fae123d8e7 |
@ -60,10 +60,7 @@ android {
|
||||
isShrinkResources = true
|
||||
|
||||
signingConfig = signingConfigs.getByName(BuildType.RELEASE.name)
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
@ -95,9 +92,6 @@ dependencies {
|
||||
ksp(libs.hilt.compiler)
|
||||
implementation(libs.hilt.navigation.compose)
|
||||
implementation(libs.matomo)
|
||||
implementation(libs.clarity)
|
||||
implementation(libs.ga4)
|
||||
|
||||
|
||||
// Compose
|
||||
implementation(platform(libs.compose.bom))
|
||||
|
@ -15,17 +15,12 @@ plugins {
|
||||
// Agp
|
||||
alias(libs.plugins.android.library) apply false
|
||||
|
||||
// Hilt
|
||||
//Hilt
|
||||
alias(libs.plugins.hilt) apply false
|
||||
|
||||
// Kotlin serialization
|
||||
|
||||
//Kotlin serialization
|
||||
alias(libs.plugins.serialization) apply false
|
||||
|
||||
// Firebase crashlytics
|
||||
alias(libs.plugins.firebaseCrashlytics) apply false
|
||||
|
||||
// Google services
|
||||
alias(libs.plugins.googleServices) apply false
|
||||
|
||||
|
||||
}
|
@ -45,7 +45,7 @@ dependencies {
|
||||
ksp(libs.hilt.compiler)
|
||||
|
||||
// Serialization
|
||||
implementation(libs.kotlin.serialization)
|
||||
implementation(libs.serializationJson)
|
||||
|
||||
// Retrofit
|
||||
api(libs.retrofit)
|
||||
|
@ -0,0 +1,98 @@
|
||||
package fr.openium.consentium.api
|
||||
|
||||
import android.content.Context
|
||||
import dagger.hilt.android.EntryPointAccessors
|
||||
import fr.openium.consentium.api.model.PurposeChoice
|
||||
import fr.openium.consentium.api.model.PurposeIdentifier
|
||||
import fr.openium.consentium.api.model.PurposeStatus
|
||||
import fr.openium.consentium.api.model.VendorIdentifier
|
||||
import fr.openium.consentium.api.model.VendorStatus
|
||||
import fr.openium.consentium.api.state.FetchConsentiumState
|
||||
import fr.openium.consentium.api.state.SetConsentiumState
|
||||
import fr.openium.consentium.data.di.RepositoryEntryPoint
|
||||
import fr.openium.consentium.data.repository.ConsentiumRepository
|
||||
import fr.openium.consentium.data.repository.ConsentiumRepositoryGetResponse
|
||||
import fr.openium.consentium.data.repository.ConsentiumRepositorySetResponse
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
class Consentium(
|
||||
context: Context,
|
||||
val applicationId: String,
|
||||
) {
|
||||
private val _fetchConsentState = MutableStateFlow<FetchConsentiumState>(FetchConsentiumState.Idle)
|
||||
val fetchConsentState by lazy { _fetchConsentState.asStateFlow() }
|
||||
|
||||
private val _setConsentState = MutableStateFlow<SetConsentiumState>(SetConsentiumState.Idle)
|
||||
val setConsentState by lazy { _setConsentState.asStateFlow() }
|
||||
|
||||
private val consentiumRepository: ConsentiumRepository by lazy {
|
||||
val appContext = context.applicationContext
|
||||
val entryPoint = EntryPointAccessors.fromApplication(appContext, RepositoryEntryPoint::class.java)
|
||||
entryPoint.provideConsentiumRepository()
|
||||
}
|
||||
|
||||
fun getConsentStatus(purpose: PurposeIdentifier): PurposeStatus {
|
||||
return when (val state = fetchConsentState.value) {
|
||||
is FetchConsentiumState.Valid -> {
|
||||
val purposeChoice = state.purposes.find { it.identifier == purpose }
|
||||
purposeChoice?.isAccepted ?: PurposeStatus.UNKNOWN
|
||||
}
|
||||
|
||||
else -> PurposeStatus.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
fun getConsentStatus(purpose: PurposeIdentifier, vendorIdentifier: VendorIdentifier): VendorStatus {
|
||||
return when (val state = fetchConsentState.value) {
|
||||
is FetchConsentiumState.Valid -> {
|
||||
val vendorChoice = state.purposes.find { it.identifier == purpose }
|
||||
?.vendors?.find { it.identifier == vendorIdentifier }
|
||||
|
||||
when (vendorChoice?.isAccepted) {
|
||||
true -> VendorStatus.ACCEPTED
|
||||
false -> VendorStatus.REJECTED
|
||||
else -> VendorStatus.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
else -> VendorStatus.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun fetchConsents() {
|
||||
_fetchConsentState.value = FetchConsentiumState.Loading
|
||||
try {
|
||||
when (val consentResponse = consentiumRepository.getConsents(applicationId)) {
|
||||
ConsentiumRepositoryGetResponse.Error -> _fetchConsentState.value = FetchConsentiumState.Error
|
||||
|
||||
is ConsentiumRepositoryGetResponse.GetConsentsSuccess -> {
|
||||
val areConsentsValid = consentResponse.isValid
|
||||
if (areConsentsValid) {
|
||||
_fetchConsentState.value = FetchConsentiumState.Valid(purposes = consentResponse.purposes)
|
||||
} else {
|
||||
_fetchConsentState.value = FetchConsentiumState.Invalid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
_fetchConsentState.value = FetchConsentiumState.Error
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun setConsents(
|
||||
consent: List<PurposeChoice>,
|
||||
) {
|
||||
_setConsentState.value = SetConsentiumState.Loading
|
||||
try {
|
||||
when (consentiumRepository.setConsents(applicationId, consent)) {
|
||||
ConsentiumRepositorySetResponse.Error -> _setConsentState.value = SetConsentiumState.Error
|
||||
ConsentiumRepositorySetResponse.SetConsentsSuccess -> _setConsentState.value = SetConsentiumState.Success
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
_setConsentState.value = SetConsentiumState.Error
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package fr.openium.consentium.api.adapter
|
||||
|
||||
import fr.openium.consentium.api.model.Purpose
|
||||
import fr.openium.consentium.api.model.PurposeIdentifier
|
||||
import fr.openium.consentium.data.remote.model.GetConsent
|
||||
|
||||
internal fun GetConsent.PurposeDTO.toPurpose() = Purpose(
|
||||
identifier = PurposeIdentifier.fromString(identifier),
|
||||
isRequired = isRequired,
|
||||
isAccepted = isAccepted.toPurposeStatus(),
|
||||
vendors = vendors?.map { it.toVendor() } ?: emptyList(),
|
||||
)
|
@ -0,0 +1,10 @@
|
||||
package fr.openium.consentium.api.adapter
|
||||
|
||||
import fr.openium.consentium.api.model.PurposeChoice
|
||||
import fr.openium.consentium.data.remote.model.PatchConsent
|
||||
|
||||
internal fun PurposeChoice.toPatchConsentPurposeDTO() = PatchConsent.PurposeDTO(
|
||||
identifier = purposeIdentifier.toString(),
|
||||
isAccepted = isAccepted,
|
||||
vendors = vendors.map { it.toPatchConsentVendorDTO() }
|
||||
)
|
@ -0,0 +1,10 @@
|
||||
package fr.openium.consentium.api.adapter
|
||||
|
||||
import fr.openium.consentium.api.model.PurposeStatus
|
||||
import fr.openium.consentium.data.remote.model.GetConsent
|
||||
|
||||
internal fun GetConsent.PurposeStatusDTO.toPurposeStatus() = when (this) {
|
||||
GetConsent.PurposeStatusDTO.ACCEPTED -> PurposeStatus.ACCEPTED
|
||||
GetConsent.PurposeStatusDTO.REJECTED -> PurposeStatus.REJECTED
|
||||
GetConsent.PurposeStatusDTO.NOT_DEFINED -> PurposeStatus.NOT_DEFINED
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package fr.openium.consentium.api.adapter
|
||||
|
||||
import fr.openium.consentium.api.model.Vendor
|
||||
import fr.openium.consentium.api.model.VendorIdentifier
|
||||
import fr.openium.consentium.data.remote.model.GetConsent
|
||||
|
||||
internal fun GetConsent.VendorDTO.toVendor() = Vendor(
|
||||
identifier = VendorIdentifier.fromString(identifier),
|
||||
isAccepted = isAccepted,
|
||||
isRequired = isRequired,
|
||||
)
|
@ -0,0 +1,9 @@
|
||||
package fr.openium.consentium.api.adapter
|
||||
|
||||
import fr.openium.consentium.api.model.VendorChoice
|
||||
import fr.openium.consentium.data.remote.model.PatchConsent
|
||||
|
||||
internal fun VendorChoice.toPatchConsentVendorDTO() = PatchConsent.VendorDTO(
|
||||
identifier = vendorIdentifier.toString(),
|
||||
isAccepted = isAccepted,
|
||||
)
|
@ -0,0 +1,8 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
data class Purpose(
|
||||
val identifier: PurposeIdentifier,
|
||||
val isRequired: Boolean,
|
||||
val isAccepted: PurposeStatus,
|
||||
val vendors: List<Vendor>,
|
||||
)
|
@ -0,0 +1,7 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
data class PurposeChoice(
|
||||
val purposeIdentifier: PurposeIdentifier,
|
||||
val isAccepted: Boolean,
|
||||
val vendors: List<VendorChoice>,
|
||||
)
|
@ -0,0 +1,24 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
enum class PurposeIdentifier {
|
||||
REQUIRED,
|
||||
AUDIENCE,
|
||||
ADS,
|
||||
UNKNOWN;
|
||||
|
||||
companion object {
|
||||
fun fromString(string: String): PurposeIdentifier = when (string) {
|
||||
"purpose-required" -> REQUIRED
|
||||
"purpose-audience" -> AUDIENCE
|
||||
"purpose-ads" -> ADS
|
||||
else -> UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = when (this) {
|
||||
REQUIRED -> "purpose-required"
|
||||
AUDIENCE -> "purpose-audience"
|
||||
ADS -> "purpose-ads"
|
||||
else -> "purpose-unknown"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
enum class PurposeStatus {
|
||||
ACCEPTED,
|
||||
REJECTED,
|
||||
NOT_DEFINED,
|
||||
UNKNOWN,
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
data class Vendor(
|
||||
val identifier: VendorIdentifier,
|
||||
val isAccepted: Boolean,
|
||||
val isRequired: Boolean,
|
||||
)
|
@ -0,0 +1,6 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
data class VendorChoice(
|
||||
val vendorIdentifier: VendorIdentifier,
|
||||
val isAccepted: Boolean,
|
||||
)
|
@ -0,0 +1,27 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
enum class VendorIdentifier {
|
||||
CRASHLYTICS,
|
||||
MATOMO,
|
||||
GA4,
|
||||
CLARITY,
|
||||
UNKNOWN;
|
||||
|
||||
companion object {
|
||||
fun fromString(string: String): VendorIdentifier = when (string) {
|
||||
"vendor-clarity" -> CLARITY
|
||||
"vendor-crashlytics" -> CRASHLYTICS
|
||||
"vendor-matomo" -> MATOMO
|
||||
"vendor-ga4" -> GA4
|
||||
else -> UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = when (this) {
|
||||
CLARITY -> "vendor-clarity"
|
||||
CRASHLYTICS -> "vendor-crashlytics"
|
||||
MATOMO -> "vendor-matomo"
|
||||
GA4 -> "vendor-ga4"
|
||||
else -> "vendor-unknown"
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package fr.openium.consentium.api.model
|
||||
|
||||
enum class VendorStatus {
|
||||
ACCEPTED,
|
||||
REJECTED,
|
||||
UNKNOWN,
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package fr.openium.consentium.api.state
|
||||
|
||||
import fr.openium.consentium.api.model.Purpose
|
||||
|
||||
sealed interface FetchConsentiumState {
|
||||
|
||||
data object Idle : FetchConsentiumState
|
||||
|
||||
data object Loading : FetchConsentiumState
|
||||
|
||||
data object Invalid : FetchConsentiumState
|
||||
|
||||
data class Valid(val purposes: List<Purpose>) : FetchConsentiumState
|
||||
|
||||
data object Error : FetchConsentiumState
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package fr.openium.consentium.api.state
|
||||
|
||||
sealed interface SetConsentiumState {
|
||||
|
||||
data object Idle : SetConsentiumState
|
||||
|
||||
data object Loading : SetConsentiumState
|
||||
|
||||
data object Success : SetConsentiumState
|
||||
|
||||
data object Error : SetConsentiumState
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package fr.openium.consentium.data.di
|
||||
|
||||
import dagger.hilt.EntryPoint
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import fr.openium.consentium.data.repository.ConsentiumRepository
|
||||
|
||||
@EntryPoint
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal interface RepositoryEntryPoint {
|
||||
fun provideConsentiumRepository(): ConsentiumRepository
|
||||
}
|
@ -2,6 +2,7 @@ package fr.openium.consentium.data.remote
|
||||
|
||||
import fr.openium.consentium.data.remote.model.GetConsent
|
||||
import fr.openium.consentium.data.remote.model.PatchConsent
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.PATCH
|
||||
@ -13,13 +14,12 @@ internal interface ConsentiumApi {
|
||||
suspend fun getConsents(
|
||||
applicationId: String,
|
||||
installationId: String,
|
||||
): GetConsent.GetConsentPayloadDTO
|
||||
): Response<GetConsent.GetConsentPayloadDTO>
|
||||
|
||||
@PATCH("/consents")
|
||||
suspend fun setConsents(
|
||||
applicationId: String,
|
||||
installationId: String,
|
||||
@Body patchConsent: PatchConsent.PatchConsentPayloadDTO,
|
||||
): Any
|
||||
): Response<Any>
|
||||
|
||||
}
|
@ -16,7 +16,7 @@ internal sealed interface GetConsent {
|
||||
data class PurposeDTO(
|
||||
@SerialName("identifier") val identifier: String,
|
||||
@SerialName("isRequired") val isRequired: Boolean,
|
||||
@SerialName("isAccepted") val isAccepted: PurposeStatus,
|
||||
@SerialName("isAccepted") val isAccepted: PurposeStatusDTO,
|
||||
@SerialName("vendors") val vendors: List<VendorDTO>? = null,
|
||||
)
|
||||
|
||||
@ -28,7 +28,7 @@ internal sealed interface GetConsent {
|
||||
)
|
||||
|
||||
@Serializable
|
||||
enum class PurposeStatus {
|
||||
enum class PurposeStatusDTO {
|
||||
@SerialName("ACCEPTED")
|
||||
ACCEPTED,
|
||||
|
||||
|
@ -1,7 +1,12 @@
|
||||
package fr.openium.consentium.data.repository
|
||||
|
||||
import fr.openium.consentium.api.adapter.toPatchConsentPurposeDTO
|
||||
import fr.openium.consentium.api.adapter.toPurpose
|
||||
import fr.openium.consentium.api.model.Purpose
|
||||
import fr.openium.consentium.api.model.PurposeChoice
|
||||
import fr.openium.consentium.data.local.ConsentiumDataStore
|
||||
import fr.openium.consentium.data.remote.ConsentiumApi
|
||||
import fr.openium.consentium.data.remote.model.PatchConsent
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class ConsentiumRepository @Inject constructor(
|
||||
@ -9,5 +14,63 @@ internal class ConsentiumRepository @Inject constructor(
|
||||
private val consentiumDataStore: ConsentiumDataStore,
|
||||
) {
|
||||
|
||||
suspend fun getConsents(applicationId: String): ConsentiumRepositoryGetResponse {
|
||||
val installationId = consentiumDataStore.getInstallationUniqueId()
|
||||
val consentsResponse = consentiumApi.getConsents(applicationId, installationId)
|
||||
return try {
|
||||
val consentsBody = if (consentsResponse.isSuccessful) {
|
||||
consentsResponse.body() ?: throw Exception()
|
||||
} else {
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
return ConsentiumRepositoryGetResponse.GetConsentsSuccess(
|
||||
isValid = consentsBody.isValid,
|
||||
purposes = consentsBody.purposes?.map { purpose -> purpose.toPurpose() } ?: emptyList()
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
ConsentiumRepositoryGetResponse.Error
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun setConsents(
|
||||
applicationId: String,
|
||||
consents: List<PurposeChoice>,
|
||||
): ConsentiumRepositorySetResponse {
|
||||
val installationId = consentiumDataStore.getInstallationUniqueId()
|
||||
|
||||
val setConsentResponse = consentiumApi.setConsents(
|
||||
applicationId = applicationId,
|
||||
patchConsent = PatchConsent.PatchConsentPayloadDTO(
|
||||
installationId = installationId,
|
||||
purposes = consents.map { it.toPatchConsentPurposeDTO() },
|
||||
)
|
||||
)
|
||||
|
||||
return if (setConsentResponse.isSuccessful) {
|
||||
ConsentiumRepositorySetResponse.SetConsentsSuccess
|
||||
} else {
|
||||
ConsentiumRepositorySetResponse.Error
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal interface ConsentiumRepositoryGetResponse {
|
||||
|
||||
data object Error : ConsentiumRepositoryGetResponse
|
||||
|
||||
data class GetConsentsSuccess(
|
||||
val isValid: Boolean,
|
||||
val purposes: List<Purpose>,
|
||||
) : ConsentiumRepositoryGetResponse
|
||||
|
||||
}
|
||||
|
||||
internal interface ConsentiumRepositorySetResponse {
|
||||
|
||||
data object Error : ConsentiumRepositorySetResponse
|
||||
|
||||
data object SetConsentsSuccess : ConsentiumRepositorySetResponse
|
||||
|
||||
}
|
@ -50,24 +50,11 @@ agp = "8.7.3"
|
||||
kotlin = "2.0.0"
|
||||
ksp = "2.0.0-1.0.23"
|
||||
junitVersion = "1.2.1"
|
||||
googleServicesPlugin = "4.4.2"
|
||||
|
||||
# Matomo
|
||||
matomo = "4.3"
|
||||
|
||||
# Compose navigation
|
||||
navigationCompose = "2.8.2"
|
||||
|
||||
# Crashlytics
|
||||
firebaseCrashlyticsPlugin = "3.0.2"
|
||||
firebaseCrashlyticsKtx = "19.2.0"
|
||||
|
||||
# Clarity
|
||||
clarityVersion = "1.3.2"
|
||||
|
||||
# GA4
|
||||
ga4 = "22.1.2"
|
||||
|
||||
[libraries]
|
||||
|
||||
# AndroidX
|
||||
@ -98,6 +85,9 @@ compose-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||
# Material
|
||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||
|
||||
# Matomo
|
||||
matomo = { module = "com.github.matomo-org:matomo-sdk-android", version.ref = "matomo" }
|
||||
|
||||
# Kotlin serizalization
|
||||
kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
|
||||
|
||||
@ -109,6 +99,9 @@ androidx-navigation-compose = { group = "androidx.navigation", name = "navigatio
|
||||
# Preferences DataStore
|
||||
preferencesDataStore = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "preferencesDataStore" }
|
||||
|
||||
# Json serialization
|
||||
serializationJson = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "jsonSerialization" }
|
||||
|
||||
# Retrofit
|
||||
retrofit = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
|
||||
retrofitConverter = { group = "com.squareup.retrofit2", name = "converter-kotlinx-serialization", version.ref = "retrofit" }
|
||||
@ -124,15 +117,6 @@ test-androidx-junit = { group = "androidx.test.ext", name = "junit-ktx", version
|
||||
test-espresso = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
||||
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||
|
||||
# Matomo
|
||||
matomo = { module = "com.github.matomo-org:matomo-sdk-android", version.ref = "matomo" }
|
||||
|
||||
# Clarity
|
||||
clarity = { group = "com.microsoft.clarity", name = "clarity", version.ref = "clarityVersion" }
|
||||
|
||||
# GA4 (Firebase Analytics)
|
||||
ga4 = { module = "com.google.firebase:firebase-analytics", version.ref = "ga4" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||
@ -141,8 +125,6 @@ ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
||||
android-library = { id = "com.android.library", version.ref = "agp" }
|
||||
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
|
||||
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "serialization" }
|
||||
firebaseCrashlytics = { id = "com.google.firebase.crashlytics", version.ref = "firebaseCrashlyticsPlugin" }
|
||||
googleServices = { id = "com.google.gms.google-services", version.ref = "googleServicesPlugin" }
|
||||
|
||||
[bundles]
|
||||
androidx = ["androidx-core-ktx", "androidx-activity-compose"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user