Skip to content

Commit 7b16022

Browse files
authored
Add check for sites with SSO enabled (#15159)
2 parents 52dee91 + e1b08e6 commit 7b16022

File tree

17 files changed

+1188
-13
lines changed

17 files changed

+1188
-13
lines changed

Fakes/Fakes/Networking.generated.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,8 @@ extension Networking.Site {
22192219
visibility: .fake(),
22202220
canBlaze: .fake(),
22212221
isAdmin: .fake(),
2222-
wasEcommerceTrial: .fake()
2222+
wasEcommerceTrial: .fake(),
2223+
hasSSOEnabled: .fake()
22232224
)
22242225
}
22252226
}

Networking/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,7 +3311,8 @@ extension Networking.Site {
33113311
visibility: CopiableProp<SiteVisibility> = .copy,
33123312
canBlaze: CopiableProp<Bool> = .copy,
33133313
isAdmin: CopiableProp<Bool> = .copy,
3314-
wasEcommerceTrial: CopiableProp<Bool> = .copy
3314+
wasEcommerceTrial: CopiableProp<Bool> = .copy,
3315+
hasSSOEnabled: CopiableProp<Bool> = .copy
33153316
) -> Networking.Site {
33163317
let siteID = siteID ?? self.siteID
33173318
let name = name ?? self.name
@@ -3334,6 +3335,7 @@ extension Networking.Site {
33343335
let canBlaze = canBlaze ?? self.canBlaze
33353336
let isAdmin = isAdmin ?? self.isAdmin
33363337
let wasEcommerceTrial = wasEcommerceTrial ?? self.wasEcommerceTrial
3338+
let hasSSOEnabled = hasSSOEnabled ?? self.hasSSOEnabled
33373339

33383340
return Networking.Site(
33393341
siteID: siteID,
@@ -3356,7 +3358,8 @@ extension Networking.Site {
33563358
visibility: visibility,
33573359
canBlaze: canBlaze,
33583360
isAdmin: isAdmin,
3359-
wasEcommerceTrial: wasEcommerceTrial
3361+
wasEcommerceTrial: wasEcommerceTrial,
3362+
hasSSOEnabled: hasSSOEnabled
33603363
)
33613364
}
33623365
}

Networking/Networking/Model/Site.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
8888
///
8989
public let wasEcommerceTrial: Bool
9090

91+
/// Whether Jetpack SSO is enabled for the site
92+
///
93+
public let hasSSOEnabled: Bool
94+
9195
/// Decodable Conformance.
9296
///
9397
public init(from decoder: Decoder) throws {
@@ -126,6 +130,11 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
126130
return activeFeatures.contains { $0 == Constants.aiAssistantFeature }
127131
}()
128132

133+
let hasSSOEnabled: Bool = {
134+
let jetpackModules = (try? siteContainer.decodeIfPresent([String].self, forKey: SiteKeys.jetpackModules)) ?? []
135+
return jetpackModules.contains(OptionKeys.sso.rawValue) == true
136+
}()
137+
129138
self.init(siteID: siteID,
130139
name: name,
131140
description: description,
@@ -146,7 +155,8 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
146155
visibility: visibility,
147156
canBlaze: canBlaze,
148157
isAdmin: isAdmin,
149-
wasEcommerceTrial: wasEcommerceTrial)
158+
wasEcommerceTrial: wasEcommerceTrial,
159+
hasSSOEnabled: hasSSOEnabled)
150160
}
151161

152162
/// Designated Initializer.
@@ -171,7 +181,8 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
171181
visibility: SiteVisibility,
172182
canBlaze: Bool,
173183
isAdmin: Bool,
174-
wasEcommerceTrial: Bool) {
184+
wasEcommerceTrial: Bool,
185+
hasSSOEnabled: Bool) {
175186
self.siteID = siteID
176187
self.name = name
177188
self.description = description
@@ -193,6 +204,7 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
193204
self.canBlaze = canBlaze
194205
self.isAdmin = isAdmin
195206
self.wasEcommerceTrial = wasEcommerceTrial
207+
self.hasSSOEnabled = hasSSOEnabled
196208
}
197209
}
198210

@@ -239,6 +251,7 @@ private extension Site {
239251
case isJetpackThePluginInstalled = "jetpack"
240252
case isJetpackConnected = "jetpack_connection"
241253
case wasEcommerceTrial = "was_ecommerce_trial"
254+
case jetpackModules = "jetpack_modules"
242255
}
243256

244257
enum PlanInfo: String, CodingKey {
@@ -266,6 +279,7 @@ private extension Site {
266279
case frameNonce = "frame_nonce"
267280
case visibility = "blog_public"
268281
case canBlaze = "can_blaze"
282+
case sso = "sso"
269283
}
270284

271285
enum PlanKeys: String, CodingKey {

Networking/Networking/Model/WordPressSite.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public extension WordPressSite {
108108
visibility: .publicSite,
109109
canBlaze: false,
110110
isAdmin: false,
111-
wasEcommerceTrial: false)
111+
wasEcommerceTrial: false,
112+
hasSSOEnabled: false)
112113
}
113114

114115
struct Authentication: Decodable {

Networking/Networking/Remote/SiteRemote.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ extension SiteRemote {
292292
enum SiteParameter {
293293
enum Fields {
294294
static let key = "fields"
295-
static let value = "ID,name,description,URL,options,jetpack,jetpack_connection,capabilities,was_ecommerce_trial,plan"
295+
static let value = "ID,name,description,URL,options,jetpack,jetpack_connection,capabilities,was_ecommerce_trial,plan,jetpack_modules"
296296
}
297297
enum Options {
298298
static let key = "options"

Networking/NetworkingTests/Mapper/SiteListMapperTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ final class SiteListMapperTests: XCTestCase {
2424
XCTAssertFalse(site.wasEcommerceTrial)
2525
XCTAssertEqual(site.plan, "business-bundle")
2626
}
27+
28+
func test_site_hasSSOEnabled_is_parsed_successfully() throws {
29+
// Given
30+
let sites = mapLoadSiteListResponse()
31+
32+
// Then
33+
let first = try XCTUnwrap(sites[safe: 0])
34+
XCTAssertTrue(first.hasSSOEnabled)
35+
36+
let second = try XCTUnwrap(sites[safe: 1])
37+
XCTAssertFalse(second.hasSSOEnabled)
38+
}
2739
}
2840

2941
private extension SiteListMapperTests {

Networking/NetworkingTests/Responses/sites.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,43 @@
4343
]
4444
}
4545
},
46+
"jetpack_modules": [
47+
"carousel",
48+
"comment-likes",
49+
"comments",
50+
"contact-form",
51+
"copy-post",
52+
"custom-content-types",
53+
"gravatar-hovercards",
54+
"infinite-scroll",
55+
"json-api",
56+
"latex",
57+
"likes",
58+
"notes",
59+
"photon",
60+
"photon-cdn",
61+
"post-by-email",
62+
"protect",
63+
"publicize",
64+
"search",
65+
"seo-tools",
66+
"sharedaddy",
67+
"shortcodes",
68+
"shortlinks",
69+
"sitemaps",
70+
"sso",
71+
"stats",
72+
"subscriptions",
73+
"tiled-gallery",
74+
"verification-tools",
75+
"videopress",
76+
"widget-visibility",
77+
"widgets",
78+
"google-fonts",
79+
"blaze",
80+
"woocommerce-analytics",
81+
"blocks"
82+
],
4683
"options": {
4784
"timezone": "",
4885
"gmt_offset": 3.5,
@@ -212,6 +249,7 @@
212249
"product_id": 1008,
213250
"product_slug": "business-bundle"
214251
},
252+
"jetpack_modules": [],
215253
"options": {
216254
"timezone": "",
217255
"gmt_offset": -4,

Storage/Storage.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@
589589
DE001324279FD7D900EB0350 /* Model 62.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 62.xcdatamodel"; sourceTree = "<group>"; };
590590
DE00132B279FDC2200EB0350 /* CouponSearchResult+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CouponSearchResult+CoreDataClass.swift"; sourceTree = "<group>"; };
591591
DE00132C279FDC2200EB0350 /* CouponSearchResult+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CouponSearchResult+CoreDataProperties.swift"; sourceTree = "<group>"; };
592+
DE06C81B2D62E9AF00419FFA /* Model 120.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 120.xcdatamodel"; sourceTree = "<group>"; };
592593
DE26B5242775C5F000A2EA0A /* Coupon+CoreDataClass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Coupon+CoreDataClass.swift"; sourceTree = "<group>"; };
593594
DE26B5252775C5F000A2EA0A /* Coupon+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Coupon+CoreDataProperties.swift"; sourceTree = "<group>"; };
594595
DE26B52A2775C8DC00A2EA0A /* Model 60.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 60.xcdatamodel"; sourceTree = "<group>"; };
@@ -2072,6 +2073,7 @@
20722073
DEC51AA4275B41BE009F3DF4 /* WooCommerce.xcdatamodeld */ = {
20732074
isa = XCVersionGroup;
20742075
children = (
2076+
DE06C81B2D62E9AF00419FFA /* Model 120.xcdatamodel */,
20752077
CE0FBB072D0C4420008B7789 /* Model 119.xcdatamodel */,
20762078
B99824A12CCBA8120090DDF3 /* Model 118.xcdatamodel */,
20772079
454AE50A2C8878B800D3C6FE /* Model 117.xcdatamodel */,
@@ -2192,7 +2194,7 @@
21922194
DEC51ADE275B41BE009F3DF4 /* Model 47.xcdatamodel */,
21932195
DEC51ADF275B41BE009F3DF4 /* Model 19.xcdatamodel */,
21942196
);
2195-
currentVersion = CE0FBB072D0C4420008B7789 /* Model 119.xcdatamodel */;
2197+
currentVersion = DE06C81B2D62E9AF00419FFA /* Model 120.xcdatamodel */;
21962198
path = WooCommerce.xcdatamodeld;
21972199
sourceTree = "<group>";
21982200
versionGroupType = wrapper.xcdatamodel;

Storage/Storage/Model/MIGRATIONS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This file documents changes in the WCiOS Storage data model. Please explain any changes to the data model as well as any custom migrations.
44

5+
## Model 120 (Release 21.8.0.0)
6+
- @itsmeichigo 2025-02-17
7+
- Added `hasSSOEnabled` attribute to `Site` entity.
8+
59
## Model 119 (Release 21.3.0.0)
610
- @rachelmcr 2024-12-16
711
- Added `WooShippingPackagesResponse` entity.

Storage/Storage/Model/Site+CoreDataProperties.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extension Site {
2828
@NSManaged public var isAdmin: Bool
2929
@NSManaged public var canBlaze: Bool
3030
@NSManaged public var wasEcommerceTrial: Bool
31+
@NSManaged public var hasSSOEnabled: Bool
3132

3233
}
3334

0 commit comments

Comments
 (0)