You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cloud/docs/access-control.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ The server endpoint of Dexie Cloud controls access to data for every sync reques
28
28
29
29
The whole idea with Dexie Cloud is to create applications that work as identically as possible no matter if user is offline or online. This means that the application logic needs to be fully executable on the client. A ToDo app must be able to add items while offline, a barcode scanner app must work offline and store scanned codes in the offline database.
30
30
31
-
Dexie Cloud comes with an access control model that has the same security benefits as a server side app, but the creation of the objects that control access happens in your client side app. How is this possible? **It must all start with a user creating a realm**. Any user can do that. A realm does not give any new access or affect other users just yet. The realm owner can invite members to the realm and connect the application model objects to the realm (or several different objects to the same realm). Then, users that accepts the invitations will gain the access that the realm owner has given and the model continues to work with water-proof isolation between users and between customers.
31
+
Dexie Cloud comes with an access control model that has the same security benefits as a server side app, but the creation of the objects that control access happens in your client side app. How is this possible? **It must all start with a user creating a realm**. Any user can do that. A realm does not give any new access or affect other users just yet. The realm owner can invite members to the realm and connect the application model objects to the realm (or several different objects to the same realm). Then, users that accept the invitations will gain access that the realm owner has given and the model continues to work with water-proof isolation between users and between customers.
32
32
33
33
The invitation step is important in non-enterprise use cases because it protects other users from unwillingly starting to see new data showing up in their app without their acceptance - data that could potentially confuse them or delude them to mix it up with authentic data.
34
34
@@ -38,13 +38,13 @@ For enterprise use cases, Dexie Cloud also has a server side REST API that enabl
38
38
39
39
A realm represents an access controlled partition of data. All objects in your database are connected to a realm via the `realmId` property also when that property isn't explicitly set. The realmId property of any object will implicitly be set to the private realmId of the object creator. Every user has its own unique realmId that is private for that user only.
40
40
41
-
New realms can be created by anyone but they are of little use unless that user invites members and the members accepts the invitation.
41
+
New realms can be created by anyone but they are of little use unless that user invites members and the members accept the invitation.
42
42
43
43
Realms are managed in the `db.realms` table. A given user will only have the realms they are member of visible for them and synced for offline access. When a realm is shared with new users, those users will get an invitation to join the realm and when users accept the invitation, they will get the realm in their next sync request together with objects that are connected to that realm. Invitations are created using the `db.members` table. Invited members can be given full, limited or no permission to mutate objects connected to the realm.
44
44
45
45
## Members
46
46
47
-
Realms have members. A member connected to a realm will have the realm and all objects connected to it synced locally if the member have accepted the membership. Each member can be given **permissions** to mutate objects connected to the realm. Zero permissions means readonly access. Member can also be given roles.
47
+
Realms have members. A member connected to a realm will have the realm and all objects connected to it synced locally if the member has accepted the membership. Each member can be given **permissions** to mutate objects connected to the realm. Zero permissions means readonly access. Members can also be given roles.
48
48
49
49
## Roles
50
50
@@ -59,13 +59,13 @@ In all custom application tables, there are two reserved property names that aff
59
59
60
60
## Default Access Control
61
61
62
-
In the simplest setup of Dexie Cloud, you do not need to specify anything related to access control. All data that one user creates will be private. It will sync to the cloud but not visible for any other user. This is still a valid use case since the data is continuously backed up and possible to access from different devices for the same user.
62
+
In the simplest setup of Dexie Cloud, you do not need to specify anything related to access control. All data that one user creates will be private. It will sync to the cloud but not be visible for any other user. This is still a valid use case since the data is continuously backed up and therefore accessible from different devices for the same user.
63
63
64
64
### Example: Zero config Access Control
65
65
66
66
Let's say you write a ToDo app where you don't care at all about collaboration. You just want each user to get their IndexedDB synced with the cloud so that they can have their same ToDo list on multiple devices and have them in sync. No user should access another user's ToDo list - they are 100% private for each user.
67
67
68
-
The sample I'm gonna show you is almost identical to how you would declare it in a plain Dexie.js app. The difference is just that you've enabled the dexieCloud addon, connect it to a database and use the '@' sign to get generated universal IDs.
68
+
The sample below is almost identical to how it would be declared in a plain Dexie.js app. The differences are simply that the dexieCloud addon has been enabled, it has connected to a Dexie Cloud database, and it uses the '@' sign to generate universal IDs.
69
69
70
70
```js
71
71
importDexiefrom'dexie'
@@ -106,13 +106,13 @@ db.version(2).stores({
106
106
})
107
107
```
108
108
109
-
_Access Control tables needs to be spelled exactly as in this sample and their primary keys needs to be spelled exactly the same. On top of that, you are free to index those properties you will need to query. The properties of objects in these tables are documented under each table below._
109
+
_Access Control tables need to be spelled exactly as in this sample and their primary keys needs to be spelled exactly the same. On top of that, you are free to index those properties you will need to query. The properties of objects in these tables are documented under each table below._
110
110
111
111
We will walk through how to use these tables to share objects to others.
112
112
113
113
### Table "realms"
114
114
115
-
Access Control are defined using realms. Each object you create belongs to a realm even if realm is not specified. Every user has its own private realm. Users can create new realms and invite other users to them. The id of a realm needs to be a globally unique string.
115
+
Access Control are defined using realms. Each object you create belongs to a realm even if the realm is not specified. Every user has its own private realm. Users can create new realms and invite other users to them. The id of a realm needs to be a globally unique string.
116
116
117
117
| Table Name | "realms" |
118
118
| Primary key | realmId |
@@ -334,19 +334,19 @@ See [Permissions](#permissions)
334
334
This is the typical flow for the non-enterprise use case in applications with a similar model as Slack, GitHub and ToDo list applications.
335
335
336
336
1. Client side: Add new object to the 'members' table with {invite: true}.
337
-
2. The changes are synced onto Dexie Cloud backend who will send an invite email to the added member.
337
+
2. The changes are synced onto Dexie Cloud backend which will send an invite email to the added member.
338
338
3. User clicks link in email to accept the invitation.
339
339
4. User gains access: Next sync request from a device belonging to the user will start downloading data connected to the newly accepted realm.
340
340
341
341
#### Enterprise membership
342
342
343
-
If your app is targeting enterprise customers, a realm can represent an enterprise department or organisation and you might want to offer your customer to define access using their existing directory rather than having to invite all the employees manually.
343
+
If your app is targeting enterprise customers, a realm can represent an enterprise department or organisation. You might want to offer your customer access using their existing directory rather than having to invite all the employees manually.
344
344
345
345
Using the Dexie Cloud REST API, it is also possible to manage realms and members from a cloud function or service and by-pass the invite step and set the userId property of members directly.
346
346
347
347
### Table "roles"
348
348
349
-
Contains roles for each realm with predefined permissions. Users can then be assigned to roles and gain the permissions that comes with them.
349
+
Contains roles for each realm with predefined permissions. Users can then be assigned to roles and gain the permissions that come with them.
350
350
351
351
| Table Name | "roles" |
352
352
| Primary key |[realmId+name]|
@@ -501,7 +501,7 @@ _The sample uses roles, which need to be imported using the `dexie-cloud` comman
501
501
502
502
## The Public Realm
503
503
504
-
As mentioned before, realms can be created any time, but there are also one "built-in" realm per user, representing the user's private data. Those realms have the same ID as the user's ID. There is also another built-in realm with the id "rlm-public". All users, also unauthenicated users, have visibility / sync access to it. By default, only the owner of the database has permissions to mutate data in the public realm but everyone have access to see and access its data online or offline.
504
+
As mentioned before, realms can be created any time, but there is also one "built-in" realm per user, representing the user's private data. This realm has the same ID as the user's ID. There is also another built-in realm with the id "rlm-public". All users, also unauthenicated users, have visibility / sync access to it. By default, only the owner of the database has permissions to mutate data in the public realm but everyone have access to see and access its data online or offline.
505
505
506
506
Public data can be populated using the REST API.
507
507
@@ -515,7 +515,7 @@ Permissions can be set on members and / or roles. Here we explain their syntax a
515
515
516
516
**add**
517
517
518
-
Permission to add new objects to given set of tables. Note that [object ownership](#object-ownership)imply full permissions of an object. So unless a user specifies `{owner: null}` when adding an object, the user will keep control of the object and be able to delete it or update any field of it no matter not having any other permission than the **add** permission.
518
+
Permission to add new objects to given set of tables. Note that [object ownership](#object-ownership)implies full permissions of an object. So unless a user specifies `{owner: null}` when adding an object, the user will keep control of the object and be able to delete it or update any field within it, no matter that user's other existing permissions.
519
519
520
520
Example
521
521
@@ -525,11 +525,11 @@ Example
525
525
}
526
526
```
527
527
528
-
The **add** permission also grants the user move an object of the given types (tables) into this realm (by changing the realmId property). Note though that the same user also needs to either be owner of the object in the source realm, or to have **manage** permission in the source realm.
528
+
The **add** permission also grants the user the ability to move an object of the given types (tables) into this realm (by changing the realmId property). Note though that the same user also needs to either be owner of the object in the source realm, or to have **manage** permission in the source realm.
529
529
530
530
**update**
531
531
532
-
Permission to update given set of properties in given set of tables. Allowing "\*" will allow updating all non-reserver properties (all properties but `realmId` and `owner`).
532
+
Permission to update a given set of properties in given set of tables. Allowing "\*" will allow updating all non-reserved properties (all properties but `realmId` and `owner`).
533
533
534
534
Example
535
535
@@ -578,7 +578,7 @@ See [typescript interface DBPermissionSet](DBPermissionSet)
578
578
579
579
The ownership of objects are defined by the `owner` reserved property name of any object. The content of that property is the userId of the owner.
580
580
581
-
An owner have full permissions on an object. This applies even if the object is connected to a realm where the user has limited permissions.
581
+
An owner has full permissions on an object. This applies even if the object is connected to a realm where the user has limited permissions.
582
582
583
583
For example if you have permissions `{add: ["comments"]}` within a realm but not `update` or `manage` permissions you can add new comments but also update or delete your own comments tied to that realm. You will not be able to update or delete other users' comments though.
0 commit comments