Skip to content

Commit

Permalink
Change some methods on RLMApp, RLMUser to properties (#6825)
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire authored Oct 1, 2020
1 parent 2df35f4 commit 3f425d9
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 95 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ x.y.z Release notes (yyyy-MM-dd)
### Enhancements
* None.

### Breaking Changes
* Change the following methods on RLMUser to properties:
- `[RLMUser emailPasswordAuth]` => `RLMUser.emailPasswordAuth`
- `[RLMUser identities]` => `RLMUser.identities`
- `[RLMUser allSessions]` => `RLMUser.allSessions`
- `[RLMUser apiKeysAuth]` => `RLMUser.apiKeysAuth`

* Other changes to RLMUser:
- `nullable` has been removed from `RLMUser.identifier`
- `nullable` has been removed from `RLMUser.customData`

* Change the following methods on RLMApp to properties:
- `[RLMApp allUsers]` => `RLMApp.allUsers`
- `[RLMApp currentUser]` => `RLMApp.currentUser`
- `[RLMApp emailPasswordAuth]` => `RLMApp.emailPasswordAuth`

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-cocoa/issues/????), since v?.?.?)
* None.
Expand Down
116 changes: 58 additions & 58 deletions Realm/ObjectServerTests/SwiftObjectServerTests.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Realm/ObjectServerTests/SwiftSyncTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SwiftSyncTestCase: RLMSyncTestCase {
let password = "abcdef"
let credentials = Credentials(email: username, password: password)
let ex = expectation(description: "Should register in the user properly")
app.emailPasswordAuth().registerUser(email: username, password: password, completion: { error in
app.emailPasswordAuth.registerUser(email: username, password: password, completion: { error in
XCTAssertNil(error)
ex.fulfill()
})
Expand Down
32 changes: 14 additions & 18 deletions Realm/RLMApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ Create a new Realm App configuration.
/// The `RLMSyncManager` for this Realm app.
@property (nonatomic, readonly) RLMSyncManager *syncManager;

/// Get a dictionary containing all users keyed on id.
@property (nonatomic, readonly) NSDictionary<NSString *, RLMUser *> *allUsers;

/// Get the current user logged into the Realm app.
@property (nonatomic, readonly, nullable) RLMUser *currentUser;

/**
A client for the email/password authentication provider which
can be used to obtain a credential for logging in.
Used to perform requests specifically related to the email/password provider.
*/
@property (nonatomic, readonly) RLMEmailPasswordAuth *emailPasswordAuth;

/**
Get an application with a given appId and configuration.
Expand All @@ -114,24 +128,6 @@ Create a new Realm App configuration.
+ (instancetype)appWithId:(NSString *)appId
configuration:(nullable RLMAppConfiguration *)configuration;

/**
Get a dictionary containing all users keyed on id.
*/
- (NSDictionary<NSString *, RLMUser *> *)allUsers;

/**
Get the current user logged into the Realm app.
*/
- (nullable RLMUser *)currentUser;

/**
A client for the email/password authentication provider which
can be used to obtain a credential for logging in.
Used to perform requests specifically related to the email/password provider.
*/
- (RLMEmailPasswordAuth *)emailPasswordAuth;

/**
Login to a user for the Realm app.
Expand Down
19 changes: 7 additions & 12 deletions Realm/RLMUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ NS_ASSUME_NONNULL_BEGIN
The unique MongoDB Realm string identifying this user.
Note this is different from an identitiy: A user may have multiple identities but has a single indentifier. See RLMUserIdentity.
*/
@property (nullable, nonatomic, readonly) NSString *identifier NS_SWIFT_NAME(id);
@property (nonatomic, readonly) NSString *identifier NS_SWIFT_NAME(id);

/**
Returns an array of identities currently linked to a user.
*/
- (NSArray<RLMUserIdentity *> *)identities;
/// Returns an array of identities currently linked to a user.
@property (nonatomic, readonly) NSArray<RLMUserIdentity *> *identities;

/**
The user's refresh token used to access the Realm Applcation.
Expand All @@ -81,7 +79,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nullable, nonatomic, readonly) NSString *refreshToken;


/**
The user's refresh token used to access the Realm Application.
Expand Down Expand Up @@ -118,18 +115,16 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (nullable RLMSyncSession *)sessionForPartitionValue:(id<RLMBSON>)partitionValue;

/**
Retrieve all the valid sessions belonging to this user.
*/
- (NSArray<RLMSyncSession *> *)allSessions;
/// Retrieve all the valid sessions belonging to this user.
@property (nonatomic, readonly) NSArray<RLMSyncSession *> *allSessions;

#pragma mark - Custom Data

/**
The custom data of the user.
This is configured in your MongoDB Realm App.
*/
@property (nullable, nonatomic, readonly) NSDictionary *customData NS_REFINED_FOR_SWIFT;
@property (nonatomic, readonly) NSDictionary *customData NS_REFINED_FOR_SWIFT;

/**
Refresh a user's custom data. This will, in effect, refresh the user's auth session.
Expand Down Expand Up @@ -175,7 +170,7 @@ NS_ASSUME_NONNULL_BEGIN
This client should only be used by an authenticated user.
*/
- (RLMAPIKeyAuth *)apiKeysAuth;
@property (nonatomic, readonly) RLMAPIKeyAuth *apiKeysAuth;

/// A client for interacting with a remote MongoDB instance
/// @param serviceName The name of the MongoDB service
Expand Down
8 changes: 4 additions & 4 deletions Realm/RLMUser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ - (nullable RLMSyncSession *)sessionForPartitionValue:(id<RLMBSON>)partitionValu

- (NSString *)identifier {
if (!_user) {
return nil;
return @"";
}
return @(_user->identity().c_str());
}
Expand Down Expand Up @@ -242,22 +242,22 @@ + (void)_setUpBindingContextFactory {
}

- (NSString *)refreshToken {
if (!_user) {
if (!_user || _user->refresh_token().empty()) {
return nil;
}
return @(_user->refresh_token().c_str());
}

- (NSString *)accessToken {
if (!_user) {
if (!_user || _user->access_token().empty()) {
return nil;
}
return @(_user->access_token().c_str());
}

- (NSDictionary *)customData {
if (!_user || !_user->custom_data()) {
return nil;
return @{};
}

return (NSDictionary *)RLMConvertBsonToRLMBSON(*_user->custom_data());
Expand Down
4 changes: 2 additions & 2 deletions RealmSwift/Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ public extension User {
The custom data of the user.
This is configured in your MongoDB Realm App.
*/
var customData: Document? {
var customData: Document {
guard let rlmCustomData = self.__customData as RLMBSON?,
let anyBSON = ObjectiveCSupport.convert(object: rlmCustomData),
case let .document(customData) = anyBSON else {
return nil
return [:]
}

return customData
Expand Down

0 comments on commit 3f425d9

Please sign in to comment.