permissions.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef REALM_SYNC_PERMISSIONS_HPP
  2. #define REALM_SYNC_PERMISSIONS_HPP
  3. #include <stddef.h>
  4. namespace realm {
  5. namespace sync {
  6. /// The Privilege enum is intended to be used in a bitfield.
  7. enum class Privilege : uint_least32_t {
  8. None = 0,
  9. /// The user can read the object (i.e. it can participate in the user's
  10. /// subscription.
  11. ///
  12. /// NOTE: On objects, it is a prerequisite that the object's class is also
  13. /// readable by the user.
  14. ///
  15. /// FIXME: Until we get asynchronous links, any object that is reachable
  16. /// through links from another readable/queryable object is also readable,
  17. /// regardless of whether the user specifically does not have read access.
  18. Read = 1,
  19. /// The user can modify the fields of the object.
  20. ///
  21. /// NOTE: On objects, it is a prerequisite that the object's class is also
  22. /// updatable by the user. When applied to a Class object, it does not
  23. /// imply that the user can modify the schema of the class, only the
  24. /// objects of that class.
  25. ///
  26. /// NOTE: This does not imply the SetPermissions privilege.
  27. Update = 2,
  28. /// The user can delete the object.
  29. ///
  30. /// NOTE: When applied to a Class object, it has no effect on whether
  31. /// objects of that class can be deleted by the user.
  32. ///
  33. /// NOTE: This implies the ability to implicitly nullify links pointing
  34. /// to the object from other objects, even if the user does not have
  35. /// permission to modify those objects in the normal way.
  36. Delete = 4,
  37. //@{
  38. /// The user can modify the object's permissions.
  39. ///
  40. /// NOTE: The user will only be allowed to assign permissions at or below
  41. /// their own privilege level.
  42. SetPermissions = 8,
  43. Share = SetPermissions,
  44. //@}
  45. /// When applied to a Class object, the user can query objects in that
  46. /// class.
  47. ///
  48. /// Has no effect when applied to objects other than Class.
  49. Query = 16,
  50. /// When applied to a Class object, the user may create objects in that
  51. /// class.
  52. ///
  53. /// NOTE: The user implicitly has Update and SetPermissions
  54. /// (but not necessarily Delete permission) within the same
  55. /// transaction as the object was created.
  56. ///
  57. /// NOTE: Even when a user has CreateObject rights, a CreateObject
  58. /// operation may still be rejected by the server, if the object has a
  59. /// primary key and the object already exists, but is not accessible by the
  60. /// user.
  61. Create = 32,
  62. /// When applied as a "Realm" privilege, the user can add classes and add
  63. /// columns to classes.
  64. ///
  65. /// NOTE: When applied to a class or object, this has no effect.
  66. ModifySchema = 64,
  67. ///
  68. /// Aggregate permissions for compatibility:
  69. ///
  70. Download = Read | Query,
  71. Upload = Update | Delete | Create,
  72. DeleteRealm = Upload, // FIXME: This seems overly permissive
  73. };
  74. inline constexpr uint_least32_t operator|(Privilege a, Privilege b)
  75. {
  76. return static_cast<uint_least32_t>(a) | static_cast<uint_least32_t>(b);
  77. }
  78. inline constexpr uint_least32_t operator|(uint_least32_t a, Privilege b)
  79. {
  80. return a | static_cast<uint_least32_t>(b);
  81. }
  82. inline constexpr uint_least32_t operator&(Privilege a, Privilege b)
  83. {
  84. return static_cast<uint_least32_t>(a) & static_cast<uint_least32_t>(b);
  85. }
  86. inline constexpr uint_least32_t operator&(uint_least32_t a, Privilege b)
  87. {
  88. return a & static_cast<uint_least32_t>(b);
  89. }
  90. inline uint_least32_t& operator|=(uint_least32_t& a, Privilege b)
  91. {
  92. return a |= static_cast<uint_least32_t>(b);
  93. }
  94. inline constexpr uint_least32_t operator~(Privilege p)
  95. {
  96. return ~static_cast<uint_least32_t>(p);
  97. }
  98. } // namespace sync
  99. } // namespace realm
  100. #endif // REALM_SYNC_PERMISSIONS_HPP