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

Fix onesignalid is local when identity verification off #2242

Open
wants to merge 1 commit into
base: identity_verification_beta
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
)
if (legacyPlayerId == null) {
Logging.debug("initWithContext: creating new device-scoped user")
createAndSwitchToNewUser(suppressBackendOperation = true)
createAndSwitchToNewUser()
} else {
Logging.debug("initWithContext: creating user linked to subscription $legacyPlayerId")

Expand Down Expand Up @@ -306,7 +306,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
suppressBackendOperation = true
}

createAndSwitchToNewUser(suppressBackendOperation = true)
createAndSwitchToNewUser(suppressBackendOperation = suppressBackendOperation)

// This operation will be dropped if identity verification is on at the time the operation
// is being processed
Expand Down Expand Up @@ -471,7 +471,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
modify(identityModel, propertiesModel)
}

if (identityModel.jwtToken != null) {
if (!useIdentityVerification || identityModel.jwtToken != null) {
setupNewSubscription(identityModel, propertiesModel, suppressBackendOperation, sdkId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.onesignal.user.internal.operations.impl.executors
import com.onesignal.common.NetworkUtils
import com.onesignal.common.exceptions.BackendException
import com.onesignal.common.modeling.ModelChangeTags
import com.onesignal.core.internal.config.ConfigModelStore
import com.onesignal.core.internal.operations.ExecutionResponse
import com.onesignal.core.internal.operations.ExecutionResult
import com.onesignal.core.internal.operations.IOperationExecutor
Expand All @@ -19,6 +20,7 @@ import com.onesignal.user.internal.operations.impl.states.NewRecordsState
internal class IdentityOperationExecutor(
private val _identityBackend: IIdentityBackendService,
private val _identityModelStore: IdentityModelStore,
private val _configModelStore: ConfigModelStore,
private val _buildUserService: IRebuildUserService,
private val _newRecordState: NewRecordsState,
) : IOperationExecutor {
Expand All @@ -45,7 +47,13 @@ internal class IdentityOperationExecutor(

if (lastOperation is SetAliasOperation) {
try {
val identityAlias = _identityModelStore.getIdentityAlias()
var identityAlias: Pair<String, String>
// use onesignalId from the operation if identity verification is turned off
if (_configModelStore.model.useIdentityVerification) {
identityAlias = _identityModelStore.getIdentityAlias()
} else {
identityAlias = Pair(IdentityConstants.ONESIGNAL_ID, lastOperation.onesignalId)
}
_identityBackend.setAlias(
lastOperation.appId,
identityAlias.first,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ class IdentityOperationExecutorTests : FunSpec({
val mockBuildUserService = mockk<IRebuildUserService>()

val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
getNewRecordState(),
)
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))

// When
Expand Down Expand Up @@ -77,7 +83,13 @@ class IdentityOperationExecutorTests : FunSpec({
val mockBuildUserService = mockk<IRebuildUserService>()

val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
getNewRecordState(),
)
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))

// When
Expand All @@ -98,7 +110,13 @@ class IdentityOperationExecutorTests : FunSpec({
val mockBuildUserService = mockk<IRebuildUserService>()

val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
getNewRecordState(),
)
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))

// When
Expand All @@ -119,7 +137,13 @@ class IdentityOperationExecutorTests : FunSpec({
every { mockBuildUserService.getRebuildOperationsIfCurrentUser(any(), any()) } returns null

val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
getNewRecordState(),
)
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))

// When
Expand All @@ -142,7 +166,13 @@ class IdentityOperationExecutorTests : FunSpec({
val mockConfigModelStore = MockHelper.configModelStore().also { it.model.opRepoPostCreateRetryUpTo = 1_000 }
val newRecordState = getNewRecordState(mockConfigModelStore).also { it.add("onesignalId") }
val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, newRecordState)
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
newRecordState,
)
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))

// When
Expand All @@ -169,7 +199,13 @@ class IdentityOperationExecutorTests : FunSpec({
val mockBuildUserService = mockk<IRebuildUserService>()

val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
getNewRecordState(),
)
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))

// When
Expand All @@ -192,7 +228,13 @@ class IdentityOperationExecutorTests : FunSpec({
val mockBuildUserService = mockk<IRebuildUserService>()

val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
getNewRecordState(),
)
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))

// When
Expand All @@ -212,7 +254,13 @@ class IdentityOperationExecutorTests : FunSpec({
val mockBuildUserService = mockk<IRebuildUserService>()

val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
getNewRecordState(),
)
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))

// When
Expand All @@ -234,7 +282,13 @@ class IdentityOperationExecutorTests : FunSpec({
val mockBuildUserService = mockk<IRebuildUserService>()

val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
getNewRecordState(),
)
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))

// When
Expand All @@ -259,7 +313,13 @@ class IdentityOperationExecutorTests : FunSpec({
val mockConfigModelStore = MockHelper.configModelStore().also { it.model.opRepoPostCreateRetryUpTo = 1_000 }
val newRecordState = getNewRecordState(mockConfigModelStore).also { it.add("onesignalId") }
val identityOperationExecutor =
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, newRecordState)
IdentityOperationExecutor(
mockIdentityBackendService,
mockIdentityModelStore,
MockHelper.configModelStore(),
mockBuildUserService,
newRecordState,
)
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))

// When
Expand Down
Loading