diff --git a/.codecov.yml b/.codecov.yml index 91d745324..f894afcd2 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -4,7 +4,7 @@ coverage: status: patch: default: - target: 0 + target: auto changes: false project: default: diff --git a/CHANGELOG.md b/CHANGELOG.md index c0220d125..c92cacbdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,15 @@ ### main -[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.0...main) +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.1...main) * _Contributing to this repo? Add info about your change here to be included in the next release_ +### 2.0.1 +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.0...2.0.1) + +__Fixes__ +- ParseUser should only encode email when User.current?.email is different from current user email ([#256](https://github.com/parse-community/Parse-Swift/pull/256)), thanks to [Corey Baker](https://github.com/cbaker6). + ### 2.0.0 [Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.11.0...2.0.0) diff --git a/Sources/ParseSwift/Objects/ParseInstallation.swift b/Sources/ParseSwift/Objects/ParseInstallation.swift index ec0e22c79..a2f2e7efe 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation.swift @@ -323,7 +323,7 @@ extension ParseInstallation { // MARK: Fetchable extension ParseInstallation { internal static func updateKeychainIfNeeded(_ results: [Self], deleting: Bool = false) throws { - guard let currentInstallation = BaseParseInstallation.current else { + guard let currentInstallation = Self.current else { return } diff --git a/Sources/ParseSwift/Objects/ParseUser.swift b/Sources/ParseSwift/Objects/ParseUser.swift index 42ed4f8f0..ddb80bbb1 100644 --- a/Sources/ParseSwift/Objects/ParseUser.swift +++ b/Sources/ParseSwift/Objects/ParseUser.swift @@ -128,7 +128,7 @@ extension ParseUser { } try? KeychainStore.shared.delete(valueFor: ParseStorage.Keys.currentUser) #endif - BaseParseUser.currentContainer = nil + Self.currentContainer = nil } /** @@ -685,7 +685,7 @@ extension ParseUser { // MARK: Fetchable extension ParseUser { internal static func updateKeychainIfNeeded(_ results: [Self], deleting: Bool = false) throws { - guard let currentUser = BaseParseUser.current else { + guard let currentUser = Self.current else { return } @@ -946,9 +946,18 @@ extension ParseUser { private func updateCommand() -> API.Command { var mutableSelf = self if let currentUser = Self.current, - currentUser.hasSameObjectId(as: mutableSelf) == true, - currentUser.email == mutableSelf.email { - mutableSelf.email = nil + currentUser.hasSameObjectId(as: mutableSelf) == true { + #if !os(Linux) && !os(Android) + // swiftlint:disable:next line_length + if let currentUserContainerInKeychain: CurrentUserContainer = try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentUser), + currentUserContainerInKeychain.currentUser?.email == mutableSelf.email { + mutableSelf.email = nil + } + #else + if currentUser.email == mutableSelf.email { + mutableSelf.email = nil + } + #endif } let mapper = { (data) -> Self in try ParseCoding.jsonDecoder().decode(UpdateResponse.self, from: data).apply(to: self) diff --git a/Sources/ParseSwift/Parse.swift b/Sources/ParseSwift/Parse.swift index 014fbc3a6..975ce713c 100644 --- a/Sources/ParseSwift/Parse.swift +++ b/Sources/ParseSwift/Parse.swift @@ -84,6 +84,10 @@ public struct ParseConfiguration { - parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessionconfiguration/1411532-httpadditionalheaders) for more info. + - parameter migrateFromObjcSDK: If your app previously used the iOS Objective-C SDK, setting this value + to `true` will attempt to migrate relevant data stored in the Keychain to ParseSwift. Defaults to `false`. + - parameter deleteKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time. + Defaults to `false`. - parameter authentication: A callback block that will be used to receive/accept/decline network challenges. Defaults to `nil` in which the SDK will use the default OS authentication methods for challenges. It should have the following argument signature: `(challenge: URLAuthenticationChallenge, diff --git a/Tests/ParseSwiftTests/ParseUserTests.swift b/Tests/ParseSwiftTests/ParseUserTests.swift index afd221d19..e2bc02e7a 100644 --- a/Tests/ParseSwiftTests/ParseUserTests.swift +++ b/Tests/ParseSwiftTests/ParseUserTests.swift @@ -542,6 +542,46 @@ class ParseUserTests: XCTestCase { // swiftlint:disable:this type_body_length XCTAssertEqual(command.body?.email, email) } + #if !os(Linux) && !os(Android) + func testUpdateCommandCurrentUserModifiedEmail() throws { + try userSignUp() + guard let user = User.current, + let objectId = user.objectId else { + XCTFail("Should have current user.") + return + } + let email = "peace@parse.com" + User.current?.email = email + XCTAssertNotNil(User.current?.email) + let command = try User.current?.saveCommand() + XCTAssertNotNil(command) + XCTAssertEqual(command?.path.urlComponent, "/users/\(objectId)") + XCTAssertEqual(command?.method, API.Method.PUT) + XCTAssertNil(command?.params) + XCTAssertNotNil(command?.body) + XCTAssertEqual(command?.body?.email, email) + } + + func testUpdateCommandCurrentUserNotCurrentModifiedEmail() throws { + try userSignUp() + guard let user = User.current, + let objectId = user.objectId else { + XCTFail("Should have current user.") + return + } + let email = "peace@parse.com" + User.current?.email = email + XCTAssertNotNil(User.current?.email) + let command = try User.current?.saveCommand() + XCTAssertNotNil(command) + XCTAssertEqual(command?.path.urlComponent, "/users/\(objectId)") + XCTAssertEqual(command?.method, API.Method.PUT) + XCTAssertNil(command?.params) + XCTAssertNotNil(command?.body) + XCTAssertEqual(command?.body?.email, email) + } + #endif + func testSaveAndUpdateCurrentUser() throws { // swiftlint:disable:this function_body_length XCTAssertNil(User.current?.objectId) try userSignUp()