Skip to content

Commit 6ddd65f

Browse files
committed
Add concept of supported fields for user updates
* OSDeltas can be created by Model changes and now manually created by the User Manager to enqueue updates not driven by model changes. These are for session time, session count, and purchases. In the latter scenario, the User Manager can set a value of "session_time" for example, but could potentially set any random string. * Introduce an enum OSPropertiesSupportedProperty, that restricts the properties we allow for updating a user.
1 parent 394381e commit 6ddd65f

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
3CE8CC582911B2B2000DB0D3 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CE8CC572911B2B2000DB0D3 /* SystemConfiguration.framework */; };
154154
3CE8CC5B29143F4B000DB0D3 /* NSDateFormatter+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE98772A2591655800DE07D5 /* NSDateFormatter+OneSignal.m */; };
155155
3CE9227A289FA88B001B1062 /* OSIdentityModelStoreListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CE92279289FA88B001B1062 /* OSIdentityModelStoreListener.swift */; };
156+
3CEE90A72BFE6ABD00B0FB5B /* SupportedProperty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CEE90A62BFE6ABD00B0FB5B /* SupportedProperty.swift */; };
156157
3CEE93422B7C4174008440BD /* OneSignalUserMocks.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CC063DD2B6D7F2A002BB07F /* OneSignalUserMocks.framework */; };
157158
3CEE93432B7C4174008440BD /* OneSignalUserMocks.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3CC063DD2B6D7F2A002BB07F /* OneSignalUserMocks.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
158159
3CEE93462B7C73AB008440BD /* OneSignalCoreMocks.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CC0639A2B6D7A8C002BB07F /* OneSignalCoreMocks.framework */; };
@@ -1184,6 +1185,7 @@
11841185
3CE8CC552911B1E0000DB0D3 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/iOSSupport/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
11851186
3CE8CC572911B2B2000DB0D3 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = DEVELOPER_DIR; };
11861187
3CE92279289FA88B001B1062 /* OSIdentityModelStoreListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSIdentityModelStoreListener.swift; sourceTree = "<group>"; };
1188+
3CEE90A62BFE6ABD00B0FB5B /* SupportedProperty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportedProperty.swift; sourceTree = "<group>"; };
11871189
3CF8629D28A183F900776CA4 /* OSIdentityModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSIdentityModel.swift; sourceTree = "<group>"; };
11881190
3CF8629F28A1964F00776CA4 /* OSPropertiesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSPropertiesModel.swift; sourceTree = "<group>"; };
11891191
3CF862A128A197D200776CA4 /* OSPropertiesModelStoreListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSPropertiesModelStoreListener.swift; sourceTree = "<group>"; };
@@ -1914,6 +1916,7 @@
19141916
3C9AD6BA2B2284AB00BC1540 /* Executors */ = {
19151917
isa = PBXGroup;
19161918
children = (
1919+
3CEE90A52BFE6A7700B0FB5B /* Support */,
19171920
3C8E6E0028AC0BA10031E48A /* OSIdentityOperationExecutor.swift */,
19181921
3C8E6DFE28AB09AE0031E48A /* OSPropertyOperationExecutor.swift */,
19191922
3CE795FA28DBDCE700736BD4 /* OSSubscriptionOperationExecutor.swift */,
@@ -1983,6 +1986,14 @@
19831986
path = OneSignalUserTests;
19841987
sourceTree = "<group>";
19851988
};
1989+
3CEE90A52BFE6A7700B0FB5B /* Support */ = {
1990+
isa = PBXGroup;
1991+
children = (
1992+
3CEE90A62BFE6ABD00B0FB5B /* SupportedProperty.swift */,
1993+
);
1994+
path = Support;
1995+
sourceTree = "<group>";
1996+
};
19861997
3E2400391D4FFC31008BDE70 /* OneSignalFramework */ = {
19871998
isa = PBXGroup;
19881999
children = (
@@ -3926,6 +3937,7 @@
39263937
3C8E6E0128AC0BA10031E48A /* OSIdentityOperationExecutor.swift in Sources */,
39273938
3CF862A228A197D200776CA4 /* OSPropertiesModelStoreListener.swift in Sources */,
39283939
3C277D7E2BD76E0000857606 /* OSIdentityModelRepo.swift in Sources */,
3940+
3CEE90A72BFE6ABD00B0FB5B /* SupportedProperty.swift in Sources */,
39293941
3C9AD6C12B22886600BC1540 /* OSRequestUpdateSubscription.swift in Sources */,
39303942
3C0EF49E28A1DBCB00E5434B /* OSUserInternalImpl.swift in Sources */,
39313943
3C8E6DFF28AB09AE0031E48A /* OSPropertyOperationExecutor.swift in Sources */,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Modified MIT License
3+
4+
Copyright 2024 OneSignal
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
1. The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
2. All copies of substantial portions of the Software may only be used in connection
17+
with services provided by OneSignal.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
*/
27+
28+
/**
29+
These are supported properties for updating a user's properties.
30+
The `OSDelta` `property` field for user updates must be one of the following.
31+
The `OSPropertyOperationExecutor` will only process the following updates.
32+
*/
33+
// swiftlint:disable identifier_name
34+
enum OSPropertiesSupportedProperty: String {
35+
// Driven by Properties Model changes
36+
case language
37+
case location
38+
case tags
39+
// Created manually by User Manager, not through Models
40+
case session_count
41+
case session_time
42+
case purchases
43+
}
44+
// swiftlint:enable identifier_name

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertiesModelStoreListener.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class OSPropertiesModelStoreListener: OSModelStoreListener {
4545
}
4646

4747
func getUpdateModelDelta(_ args: OSModelChangedArgs) -> OSDelta? {
48+
guard let _ = OSPropertiesSupportedProperty(rawValue: args.property) else {
49+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSPropertiesModelStoreListener.getUpdateModelDelta encountered unsupported property: \(args.property)")
50+
return nil
51+
}
52+
4853
return OSDelta(
4954
name: OS_UPDATE_PROPERTIES_DELTA,
5055
identityModelId: OneSignalUserManagerImpl.sharedInstance.user.identityModel.modelId,

0 commit comments

Comments
 (0)