Skip to content

Commit 0878c22

Browse files
committed
align with latest wprs
1 parent e8cdb01 commit 0878c22

File tree

7 files changed

+22
-9
lines changed

7 files changed

+22
-9
lines changed

Modules/Sources/WordPressCore/Users/DisplayUser.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import WordPressAPI
23

34
public struct DisplayUser: Identifiable, Codable, Hashable, Sendable {
45
public let id: Int64
@@ -8,7 +9,7 @@ public struct DisplayUser: Identifiable, Codable, Hashable, Sendable {
89
public let lastName: String
910
public let displayName: String
1011
public let profilePhotoUrl: URL?
11-
public let role: String
12+
public let role: UserRole
1213

1314
public let emailAddress: String
1415
public let websiteUrl: String?
@@ -23,7 +24,7 @@ public struct DisplayUser: Identifiable, Codable, Hashable, Sendable {
2324
lastName: String,
2425
displayName: String,
2526
profilePhotoUrl: URL?,
26-
role: String,
27+
role: UserRole,
2728
emailAddress: String,
2829
websiteUrl: String?,
2930
biography: String?
@@ -49,7 +50,7 @@ public struct DisplayUser: Identifiable, Codable, Hashable, Sendable {
4950
lastName: "Smith",
5051
displayName: "John Smith",
5152
profilePhotoUrl: URL(string: "https://gravatar.com/avatar/58fc51586c9a1f9895ac70e3ca60886e?size=256"),
52-
role: "administrator",
53+
role: .administrator,
5354
emailAddress: "[email protected]",
5455
websiteUrl: "https://example.com",
5556
biography: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
@@ -68,3 +69,15 @@ extension DisplayUser {
6869
.joined(separator: " ")
6970
}
7071
}
72+
73+
extension UserRole: @retroactive Codable {
74+
public init(from decoder: any Decoder) throws {
75+
let role = try decoder.singleValueContainer().decode(String.self)
76+
self.init(role)
77+
}
78+
79+
public func encode(to encoder: any Encoder) throws {
80+
var container = encoder.singleValueContainer()
81+
try container.encode(self.rawValue)
82+
}
83+
}

Modules/Sources/WordPressCore/Users/UserService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public actor UserService: UserServiceProtocol {
3636
}
3737
}
3838

39-
public func isCurrentUserCapableOf(_ capability: String) async -> Bool {
39+
public func isCurrentUserCapableOf(_ capability: UserCapability) async -> Bool {
4040
await currentUser?.capabilities.keys.contains(capability) == true
4141
}
4242

Modules/Sources/WordPressCore/Users/UserServiceProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import WordPressAPI
44
public protocol UserServiceProtocol: Actor {
55
func fetchUsers() async throws
66

7-
func isCurrentUserCapableOf(_ capability: String) async -> Bool
7+
func isCurrentUserCapableOf(_ capability: UserCapability) async -> Bool
88

99
func setNewPassword(id: UserId, newPassword: String) async throws
1010

WordPress/Classes/Services/CommentServiceRemoteCoreRESTAPI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private extension RemoteComment {
149149
self.postID = NSNumber(value: comment.post)
150150

151151
self.status = comment.status.commentStatusType?.description
152-
self.type = comment.commentType.type
152+
self.type = comment.commentType.rawValue
153153

154154
if let ext = try? comment.additionalFields.parseWpcomCommentsExtension() {
155155
self.postTitle = ext.post?.title

WordPress/Classes/Users/UserProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ actor MockUserProvider: UserServiceProtocol {
5858
await userDataStore.listStream(query: .all)
5959
}
6060

61-
func isCurrentUserCapableOf(_ capability: String) async -> Bool {
61+
func isCurrentUserCapableOf(_ capability: UserCapability) async -> Bool {
6262
true
6363
}
6464

WordPress/Classes/Users/ViewModel/UserListViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class UserListViewModel: ObservableObject {
126126
}
127127

128128
private func sortUsers(_ users: [DisplayUser]) -> [Section] {
129-
Dictionary(grouping: users) { $0.id == currentUserId ? RoleSection.me : RoleSection.role($0.role) }
129+
Dictionary(grouping: users) { $0.id == currentUserId ? RoleSection.me : RoleSection.role($0.role.rawValue) }
130130
.map { Section(id: $0.key, users: $0.value.sorted(by: { $0.username < $1.username })) }
131131
.sorted { $0.id < $1.id }
132132
}

WordPress/Classes/Users/Views/UserDetailsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct UserDetailsView: View {
5555
.listRowInsets(.zero)
5656

5757
Section {
58-
makeRow(title: Strings.roleFieldTitle, content: user.role)
58+
makeRow(title: Strings.roleFieldTitle, content: user.role.rawValue)
5959
makeRow(title: Strings.emailAddressFieldTitle, content: user.emailAddress, link: user.emailAddress.asEmail())
6060
if let website = user.websiteUrl, !website.isEmpty {
6161
makeRow(title: Strings.websiteFieldTitle, content: website, link: URL(string: website))

0 commit comments

Comments
 (0)