RLMSyncPermissionValue.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 value representing a permission granted to the specified user(s) to access the specified Realm(s).
  47. `RLMSyncPermissionValue` is immutable and can be accessed from any thread.
  48. See https://realm.io/docs/realm-object-server/#permissions for general documentation.
  49. */
  50. @interface RLMSyncPermissionValue : NSObject
  51. /**
  52. The Realm Object Server path to the Realm to which this permission applies (e.g. "/path/to/realm").
  53. Specify "*" if this permission applies to all Realms managed by the server.
  54. */
  55. @property (nonatomic, readonly) NSString *path;
  56. /**
  57. The access level described by this permission.
  58. */
  59. @property (nonatomic, readonly) RLMSyncAccessLevel accessLevel;
  60. /// Whether the access level allows the user to read from the Realm.
  61. @property (nonatomic, readonly) BOOL mayRead;
  62. /// Whether the access level allows the user to write to the Realm.
  63. @property (nonatomic, readonly) BOOL mayWrite;
  64. /// Whether the access level allows the user to administer the Realm.
  65. @property (nonatomic, readonly) BOOL mayManage;
  66. /**
  67. Create a new sync permission value, for use with permission APIs.
  68. @param path The Realm Object Server path to the Realm whose permission should be modified
  69. (e.g. "/path/to/realm"). Pass "*" to apply to all Realms managed by the user.
  70. @param userID The identity of the user who should be granted access to the Realm at `path`.
  71. Pass "*" to apply to all users managed by the server.
  72. @param accessLevel The access level to grant.
  73. */
  74. - (instancetype)initWithRealmPath:(NSString *)path
  75. userID:(NSString *)userID
  76. accessLevel:(RLMSyncAccessLevel)accessLevel;
  77. /**
  78. Create a new sync permission value, for use with permission APIs.
  79. @param path The Realm Object Server path to the Realm whose permission should be modified
  80. (e.g. "/path/to/realm"). Pass "*" to apply to all Realms managed by the user.
  81. @param username The username (often an email address) of the user who should be granted access
  82. to the Realm at `path`.
  83. @param accessLevel The access level to grant.
  84. */
  85. - (instancetype)initWithRealmPath:(NSString *)path
  86. username:(NSString *)username
  87. accessLevel:(RLMSyncAccessLevel)accessLevel;
  88. /**
  89. The identity of the user to whom this permission is granted, or "*"
  90. if all users are granted this permission. Nil if the permission is
  91. defined in terms of a key-value pair.
  92. */
  93. @property (nullable, nonatomic, readonly) NSString *userId;
  94. /**
  95. If the permission is defined in terms of a key-value pair, the key
  96. describing the type of criterion used to determine what users the
  97. permission applies to. Otherwise, nil.
  98. */
  99. @property (nullable, nonatomic, readonly) NSString *key;
  100. /**
  101. If the permission is defined in terms of a key-value pair, a string
  102. describing the criterion value used to determine what users the
  103. permission applies to. Otherwise, nil.
  104. */
  105. @property (nullable, nonatomic, readonly) NSString *value;
  106. /**
  107. When this permission object was last updated.
  108. */
  109. @property (nonatomic, readonly) NSDate *updatedAt;
  110. /// :nodoc:
  111. - (instancetype)init __attribute__((unavailable("Use the designated initializer")));
  112. /// :nodoc:
  113. + (instancetype)new __attribute__((unavailable("Use the designated initializer")));
  114. @end
  115. NS_ASSUME_NONNULL_END