Skip to content

Commit 8581286

Browse files
authored
Merge pull request #72 from polybase/eng-511-improve-permissions-docs
Improve permissions docs
2 parents d284bab + c69f8f0 commit 8581286

12 files changed

+224
-81
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### `@call` on collections
2+
3+
Allows anyone to call functions that do not have a `@call` directive.
4+
5+
```js
6+
@call
7+
collection Form {
8+
...
9+
10+
updateTitle (title: string) { ... }
11+
}
12+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### `@call` on functions
2+
3+
Allows anyone who can sign using the specified public key to call a given function.
4+
5+
```js
6+
collection Form {
7+
@read
8+
creator: PublicKey;
9+
10+
@call(creator);
11+
update () {
12+
...
13+
}
14+
}
15+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Example of delegating ***call permission*** to `Response` to a user with given `publicKey`:
2+
3+
`Response``Form``User``publicKey`:
4+
5+
```js
6+
collection Response {
7+
form: Form;
8+
9+
// Delegate call permission to form/Form
10+
@call(form)
11+
function approve () {
12+
13+
}
14+
}
15+
16+
collection Form {
17+
// Delegate call permission to User
18+
@delegate
19+
creator: User;
20+
}
21+
22+
collection User {
23+
// Delegate call permission to publicKey
24+
@delegate
25+
publicKey: PublicKey;
26+
}
27+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Example of delegating ***read access*** to `Response` to a user with given `publicKey`:
2+
3+
`Response``Form``User``publicKey`:
4+
5+
```js
6+
collection Response {
7+
// Delegate read permission to form/Form
8+
@read
9+
form: Form;
10+
}
11+
12+
collection Form {
13+
// Delegate read permission to User
14+
@delegate
15+
creator: User;
16+
}
17+
18+
collection User {
19+
// Delegate read permission to publicKey
20+
@delegate
21+
publicKey: PublicKey;
22+
}
23+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Delegation allows you to create rules across multiple records, allowing for complex permissions to be defined.
2+
3+
<Note>
4+
Delegation rules must always end in a [PublicKey](/collections#public-key) field. You must
5+
[authenticate the user with using a `signer`](/authentication) function in order to use delegation.
6+
</Note>
7+
8+
You can annotate your collections with `@read`, `@call` and `@delegate` directives to control who can read, call and delegate data.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### `@public` on collections
2+
3+
Allows anyone to read all records and call functions in the collection (it's the equivalent of adding `@read` and `@call`).
4+
You can still further restrict write permissions by adding custom code to your [collections functions](#functions).
5+
6+
```js
7+
@public
8+
collection Response {
9+
...
10+
}
11+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
### `@read` on collections
2+
3+
Allows anyone to read all records in the collection (but calls to functions are still restricted).
4+
5+
```js
6+
@read
7+
collection Response {
8+
...
9+
}
10+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### `@read` on fields
2+
3+
Allows anyone who can sign using the specified public key to read the record.
4+
5+
```js
6+
collection Response {
7+
@read
8+
publicKey: PublicKey;
9+
...
10+
}
11+
```

collections.mdx

Lines changed: 10 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -551,101 +551,31 @@ collection cities {
551551
}
552552
```
553553

554-
## Authorization
554+
## Permissions
555555

556556
By default, collections in Polybase are private and their records cannot be accessed.
557-
To make a collection private, remove the `@public` directive.
557+
To make a collection public, add the `@public` directive.
558558

559559
To allow users to access and manipulate their records, you can use the following directives:
560560

561-
### `@public` on collections
562561

563-
Allows anyone to read records or call functions in the collection. You can still further
564-
restrict write permissions by adding custom code to your [collections functions](#functions).
562+
<Snippet file="permissions/public-on-collections.mdx" />
565563

566-
```js
567-
@public
568-
collection Response {
569-
...
570-
}
571-
```
572-
573-
### `@read` on collections
574-
575-
Allows anyone to read records in the collection.
576-
577-
```js
578-
@read
579-
collection Response {
580-
...
581-
}
582-
```
564+
<Snippet file="permissions/read-on-collections.mdx" />
583565

584-
### `@read` on fields
566+
<Snippet file="permissions/read-on-fields.mdx" />
585567

586-
Allows anyone who can sign using the specified public key to read the record.
568+
<Snippet file="permissions/call-on-collections.mdx" />
587569

588-
```js
589-
collection Response {
590-
@read
591-
publicKey: PublicKey;
592-
...
593-
}
594-
```
595-
596-
### `@call` on collections
597-
598-
Allows anyone to call functions that do not have a `@call` directive.
599-
600-
```js
601-
@call
602-
collection Form {
603-
...
604-
605-
updateTitle (title: string) { ... }
606-
}
607-
```
608-
609-
### `@call` on functions
610-
611-
Allows anyone who can sign using the specified public key to call a given function.
612-
613-
```js
614-
collection Form {
615-
@read
616-
creator: PublicKey;
617-
618-
@call(creator);
619-
update () {
620-
...
621-
}
622-
}
623-
```
624-
625-
A `@call` directive without arguments allows anyone to call the function.
570+
<Snippet file="permissions/call-on-functions.mdx" />
626571

627572
### `@delegate`
628573

629-
Allows anyone who can sign using the specified public key to read the response data, via delegated permissions.
630-
631-
Example of delegating `Response``Form``User``publicKey`:
632-
633-
```js
634-
collection Response {
635-
@read
636-
form: Form;
637-
}
574+
<Snippet file="permissions/delegate/desc.mdx" />
638575

639-
collection Form {
640-
@delegate
641-
creator: User;
642-
}
576+
<Snippet file="permissions/delegate/delegate-read.mdx" />
643577

644-
collection User {
645-
@delegate
646-
publicKey: PublicKey;
647-
}
648-
```
578+
For more on delegating permissions, see [Delegating Permissions](/permissions#delegate).
649579

650580
## Reference a collection
651581

encrypt-data.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Encrypt data"
33
---
44

5-
Polybase data is publicly accessible, therefore sensitive data should be encrypted
5+
Polybase can be publicly accessible (if [@public](permissions#public-on-collections) directive used). In the case of public data, sensitive data should be encrypted
66
before being written to the database. To make this process easier, Polybase has
77
created a helper library to handle common encryption tasks:
88
[`@polybase/util`](https://www.npmjs.com/package/@polybase/util)

0 commit comments

Comments
 (0)