RLMSyncPermission.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2017 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Foundation/Foundation.h>
  19. /**
  20. Access levels which can be granted to Realm Mobile Platform users
  21. for specific synchronized Realms, using the permissions APIs.
  22. Note that each access level guarantees all allowed actions provided
  23. by less permissive access levels. Specifically, users with write
  24. access to a Realm can always read from that Realm, and users with
  25. administrative access can always read or write from the Realm.
  26. */
  27. typedef NS_ENUM(NSUInteger, RLMSyncAccessLevel) {
  28. /// No access whatsoever.
  29. RLMSyncAccessLevelNone = 0,
  30. /**
  31. User can only read the contents of the Realm.
  32. @warning Users who have read-only access to a Realm should open the
  33. Realm using `+[RLMRealm asyncOpenWithConfiguration:callbackQueue:callback:]`.
  34. Attempting to directly open the Realm is an error; in this
  35. case the Realm must be deleted and re-opened.
  36. */
  37. RLMSyncAccessLevelRead = 1,
  38. /// User can read and write the contents of the Realm.
  39. RLMSyncAccessLevelWrite = 2,
  40. /// User can read, write, and administer the Realm, including
  41. /// granting permissions to other users.
  42. RLMSyncAccessLevelAdmin = 3,
  43. };
  44. NS_ASSUME_NONNULL_BEGIN
  45. /**
  46. A property on which a `RLMResults<RLMSyncPermission *>` can be queried or filtered.
  47. @warning If building `NSPredicate`s using format strings including these string
  48. constants, use %K instead of %@ as the substitution parameter.
  49. */
  50. typedef NSString * RLMSyncPermissionSortProperty NS_STRING_ENUM;
  51. /// Sort by the Realm Object Server path to the Realm to which the permission applies.
  52. extern RLMSyncPermissionSortProperty const RLMSyncPermissionSortPropertyPath;
  53. /// Sort by the identity of the user to whom the permission applies.
  54. extern RLMSyncPermissionSortProperty const RLMSyncPermissionSortPropertyUserID;
  55. /// Sort by the date the permissions were last updated.
  56. extern RLMSyncPermissionSortProperty const RLMSyncPermissionSortPropertyUpdated;
  57. /**
  58. A value representing a permission granted to the specified user(s) to access the specified Realm(s).
  59. `RLMSyncPermission` is immutable and can be accessed from any thread.
  60. See https://realm.io/docs/realm-object-server/#permissions for general documentation.
  61. */
  62. @interface RLMSyncPermission : NSObject
  63. /**
  64. The Realm Object Server path to the Realm to which this permission applies (e.g. "/path/to/realm").
  65. Specify "*" if this permission applies to all Realms managed by the server.
  66. */
  67. @property (nonatomic, readonly) NSString *path;
  68. /**
  69. The access level described by this permission.
  70. */
  71. @property (nonatomic, readonly) RLMSyncAccessLevel accessLevel;
  72. /// Whether the access level allows the user to read from the Realm.
  73. @property (nonatomic, readonly) BOOL mayRead;
  74. /// Whether the access level allows the user to write to the Realm.
  75. @property (nonatomic, readonly) BOOL mayWrite;
  76. /// Whether the access level allows the user to administer the Realm.
  77. @property (nonatomic, readonly) BOOL mayManage;
  78. /**
  79. Create a new sync permission value, for use with permission APIs.
  80. @param path The Realm Object Server path to the Realm whose permission should be modified
  81. (e.g. "/path/to/realm"). Pass "*" to apply to all Realms managed by the user.
  82. @param identity The Realm Object Server identity of the user who should be granted access to
  83. the Realm at `path`.
  84. Pass "*" to apply to all users managed by the server.
  85. @param accessLevel The access level to grant.
  86. */
  87. - (instancetype)initWithRealmPath:(NSString *)path
  88. identity:(NSString *)identity
  89. accessLevel:(RLMSyncAccessLevel)accessLevel;
  90. /**
  91. Create a new sync permission value, for use with permission APIs.
  92. @param path The Realm Object Server path to the Realm whose permission should be modified
  93. (e.g. "/path/to/realm"). Pass "*" to apply to all Realms managed by the user.
  94. @param username The username (often an email address) of the user who should be granted access
  95. to the Realm at `path`.
  96. @param accessLevel The access level to grant.
  97. */
  98. - (instancetype)initWithRealmPath:(NSString *)path
  99. username:(NSString *)username
  100. accessLevel:(RLMSyncAccessLevel)accessLevel;
  101. /**
  102. The identity of the user to whom this permission is granted, or "*"
  103. if all users are granted this permission. Nil if the permission is
  104. defined in terms of a key-value pair.
  105. */
  106. @property (nullable, nonatomic, readonly) NSString *identity;
  107. /**
  108. If the permission is defined in terms of a key-value pair, the key
  109. describing the type of criterion used to determine what users the
  110. permission applies to. Otherwise, nil.
  111. */
  112. @property (nullable, nonatomic, readonly) NSString *key;
  113. /**
  114. If the permission is defined in terms of a key-value pair, a string
  115. describing the criterion value used to determine what users the
  116. permission applies to. Otherwise, nil.
  117. */
  118. @property (nullable, nonatomic, readonly) NSString *value;
  119. /**
  120. When this permission was last updated.
  121. */
  122. @property (nonatomic, readonly) NSDate *updatedAt;
  123. /// :nodoc:
  124. - (instancetype)init __attribute__((unavailable("Use the designated initializer")));
  125. /// :nodoc:
  126. + (instancetype)new __attribute__((unavailable("Use the designated initializer")));
  127. // MARK: - Migration assistance
  128. /// :nodoc:
  129. @property (nullable, nonatomic, readonly) NSString *userId __attribute__((unavailable("Renamed to `identity`")));
  130. /// :nodoc:
  131. - (instancetype)initWithRealmPath:(NSString *)path
  132. userID:(NSString *)identity
  133. accessLevel:(RLMSyncAccessLevel)accessLevel
  134. __attribute__((unavailable("Renamed to `-initWithRealmPath:identity:accessLevel:`")));
  135. @end
  136. NS_ASSUME_NONNULL_END