Skip to content

Commit b968181

Browse files
committed
Fix: bug that causes onesignalId to be local when setting alias while identity verification is off
Also removed backend operation suppression; fixed test units using identity operation executor
1 parent f4a9356 commit b968181

File tree

3 files changed

+82
-14
lines changed

3 files changed

+82
-14
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
257257
)
258258
if (legacyPlayerId == null) {
259259
Logging.debug("initWithContext: creating new device-scoped user")
260-
createAndSwitchToNewUser(suppressBackendOperation = true)
260+
createAndSwitchToNewUser()
261261
} else {
262262
Logging.debug("initWithContext: creating user linked to subscription $legacyPlayerId")
263263

@@ -306,7 +306,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
306306
suppressBackendOperation = true
307307
}
308308

309-
createAndSwitchToNewUser(suppressBackendOperation = true)
309+
createAndSwitchToNewUser(suppressBackendOperation = suppressBackendOperation)
310310

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

474-
if (identityModel.jwtToken != null) {
474+
if (!useIdentityVerification || identityModel.jwtToken != null) {
475475
setupNewSubscription(identityModel, propertiesModel, suppressBackendOperation, sdkId)
476476
}
477477

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/IdentityOperationExecutor.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.onesignal.user.internal.operations.impl.executors
33
import com.onesignal.common.NetworkUtils
44
import com.onesignal.common.exceptions.BackendException
55
import com.onesignal.common.modeling.ModelChangeTags
6+
import com.onesignal.core.internal.config.ConfigModelStore
67
import com.onesignal.core.internal.operations.ExecutionResponse
78
import com.onesignal.core.internal.operations.ExecutionResult
89
import com.onesignal.core.internal.operations.IOperationExecutor
@@ -19,6 +20,7 @@ import com.onesignal.user.internal.operations.impl.states.NewRecordsState
1920
internal class IdentityOperationExecutor(
2021
private val _identityBackend: IIdentityBackendService,
2122
private val _identityModelStore: IdentityModelStore,
23+
private val _configModelStore: ConfigModelStore,
2224
private val _buildUserService: IRebuildUserService,
2325
private val _newRecordState: NewRecordsState,
2426
) : IOperationExecutor {
@@ -45,7 +47,13 @@ internal class IdentityOperationExecutor(
4547

4648
if (lastOperation is SetAliasOperation) {
4749
try {
48-
val identityAlias = _identityModelStore.getIdentityAlias()
50+
var identityAlias: Pair<String, String>
51+
// use onesignalId from the operation if identity verification is turned off
52+
if (_configModelStore.model.useIdentityVerification) {
53+
identityAlias = _identityModelStore.getIdentityAlias()
54+
} else {
55+
identityAlias = Pair(IdentityConstants.ONESIGNAL_ID, lastOperation.onesignalId)
56+
}
4957
_identityBackend.setAlias(
5058
lastOperation.appId,
5159
identityAlias.first,

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/operations/IdentityOperationExecutorTests.kt

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ class IdentityOperationExecutorTests : FunSpec({
4141
val mockBuildUserService = mockk<IRebuildUserService>()
4242

4343
val identityOperationExecutor =
44-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
44+
IdentityOperationExecutor(
45+
mockIdentityBackendService,
46+
mockIdentityModelStore,
47+
MockHelper.configModelStore(),
48+
mockBuildUserService,
49+
getNewRecordState(),
50+
)
4551
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))
4652

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

7985
val identityOperationExecutor =
80-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
86+
IdentityOperationExecutor(
87+
mockIdentityBackendService,
88+
mockIdentityModelStore,
89+
MockHelper.configModelStore(),
90+
mockBuildUserService,
91+
getNewRecordState(),
92+
)
8193
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))
8294

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

100112
val identityOperationExecutor =
101-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
113+
IdentityOperationExecutor(
114+
mockIdentityBackendService,
115+
mockIdentityModelStore,
116+
MockHelper.configModelStore(),
117+
mockBuildUserService,
118+
getNewRecordState(),
119+
)
102120
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))
103121

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

121139
val identityOperationExecutor =
122-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
140+
IdentityOperationExecutor(
141+
mockIdentityBackendService,
142+
mockIdentityModelStore,
143+
MockHelper.configModelStore(),
144+
mockBuildUserService,
145+
getNewRecordState(),
146+
)
123147
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))
124148

125149
// When
@@ -142,7 +166,13 @@ class IdentityOperationExecutorTests : FunSpec({
142166
val mockConfigModelStore = MockHelper.configModelStore().also { it.model.opRepoPostCreateRetryUpTo = 1_000 }
143167
val newRecordState = getNewRecordState(mockConfigModelStore).also { it.add("onesignalId") }
144168
val identityOperationExecutor =
145-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, newRecordState)
169+
IdentityOperationExecutor(
170+
mockIdentityBackendService,
171+
mockIdentityModelStore,
172+
MockHelper.configModelStore(),
173+
mockBuildUserService,
174+
newRecordState,
175+
)
146176
val operations = listOf<Operation>(SetAliasOperation("appId", "onesignalId", "aliasKey1", "aliasValue1"))
147177

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

171201
val identityOperationExecutor =
172-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
202+
IdentityOperationExecutor(
203+
mockIdentityBackendService,
204+
mockIdentityModelStore,
205+
MockHelper.configModelStore(),
206+
mockBuildUserService,
207+
getNewRecordState(),
208+
)
173209
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))
174210

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

194230
val identityOperationExecutor =
195-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
231+
IdentityOperationExecutor(
232+
mockIdentityBackendService,
233+
mockIdentityModelStore,
234+
MockHelper.configModelStore(),
235+
mockBuildUserService,
236+
getNewRecordState(),
237+
)
196238
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))
197239

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

214256
val identityOperationExecutor =
215-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
257+
IdentityOperationExecutor(
258+
mockIdentityBackendService,
259+
mockIdentityModelStore,
260+
MockHelper.configModelStore(),
261+
mockBuildUserService,
262+
getNewRecordState(),
263+
)
216264
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))
217265

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

236284
val identityOperationExecutor =
237-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, getNewRecordState())
285+
IdentityOperationExecutor(
286+
mockIdentityBackendService,
287+
mockIdentityModelStore,
288+
MockHelper.configModelStore(),
289+
mockBuildUserService,
290+
getNewRecordState(),
291+
)
238292
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))
239293

240294
// When
@@ -259,7 +313,13 @@ class IdentityOperationExecutorTests : FunSpec({
259313
val mockConfigModelStore = MockHelper.configModelStore().also { it.model.opRepoPostCreateRetryUpTo = 1_000 }
260314
val newRecordState = getNewRecordState(mockConfigModelStore).also { it.add("onesignalId") }
261315
val identityOperationExecutor =
262-
IdentityOperationExecutor(mockIdentityBackendService, mockIdentityModelStore, mockBuildUserService, newRecordState)
316+
IdentityOperationExecutor(
317+
mockIdentityBackendService,
318+
mockIdentityModelStore,
319+
MockHelper.configModelStore(),
320+
mockBuildUserService,
321+
newRecordState,
322+
)
263323
val operations = listOf<Operation>(DeleteAliasOperation("appId", "onesignalId", "aliasKey1"))
264324

265325
// When

0 commit comments

Comments
 (0)