Skip to content

Commit

Permalink
Fixed bug with cyclic read/save current privacy mode after its expira…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
DeKaN committed Nov 13, 2023
1 parent 3bd991d commit 1a6aa2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v3.3.5-SNAPSHOT
* Decreased default offline storage lifetime for events
* Fixed bug with cyclic read/save current privacy mode after its expiration

## v3.3.4
* Added limit for event storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@ class PrivacyModesStorage internal constructor(
prefsStorage.privacyStorageFilter = ::isFeatureAllowed
}
private fun isFeatureAllowed(privacyStorageFeature: PrivacyStorageFeature): Boolean {
val isNotForbidden = PrivacyStorageFeature.ALL !in currentMode.forbiddenStorageFeatures ||
privacyStorageFeature !in currentMode.forbiddenStorageFeatures
val isAllowed = PrivacyStorageFeature.ALL in currentMode.allowedStorageFeatures ||
privacyStorageFeature in currentMode.allowedStorageFeatures
val isNotForbidden = PrivacyStorageFeature.ALL !in cachedMode.forbiddenStorageFeatures ||
privacyStorageFeature !in cachedMode.forbiddenStorageFeatures
val isAllowed = PrivacyStorageFeature.ALL in cachedMode.allowedStorageFeatures ||
privacyStorageFeature in cachedMode.allowedStorageFeatures
return isNotForbidden && isAllowed
}

/**
* All registered privacy modes. Add a [PrivacyMode] instance into [allModes] for registering it
*/
@Suppress("unused", "MemberVisibilityCanBePrivate") // Public API.
val allModes = mutableSetOf(
PrivacyMode.NO_CONSENT,
PrivacyMode.NO_STORAGE,
PrivacyMode.OPTIN,
PrivacyMode.OPTOUT,
PrivacyMode.EXEMPT
)

/**
* Current privacy visitor mode
*/
Expand All @@ -37,27 +49,19 @@ class PrivacyModesStorage internal constructor(
} ?: configuration.defaultPrivacyMode
}
}
cachedMode = field
return field
}
set(value) {
require(value in allModes) {
"Privacy mode ${value.visitorMode} is not registered."
}
cachedMode = value
field = value
updatePrefs(value)
}

/**
* All registered privacy modes. Add a [PrivacyMode] instance into [allModes] for registering it
*/
@Suppress("unused", "MemberVisibilityCanBePrivate") // Public API.
val allModes = mutableSetOf(
PrivacyMode.NO_CONSENT,
PrivacyMode.NO_STORAGE,
PrivacyMode.OPTIN,
PrivacyMode.OPTOUT,
PrivacyMode.EXEMPT
)
private var cachedMode: PrivacyMode = currentMode

// for mocking in tests
@Suppress("NOTHING_TO_INLINE")
Expand Down

0 comments on commit 1a6aa2f

Please sign in to comment.