gristlabs_grist-core/app/gen-server/migration
Paul Fitzpatrick 2a206dfcf8 (core) add initial support for special shares
Summary:
This gives a mechanism for controlling access control within a document that is distinct from (though implemented with the same machinery as) granular access rules.

It was hard to find a good way to insert this that didn't dissolve in a soup of complications, so here's what I went with:
 * When reading rules, if there are shares, extra rules are added.
 * If there are shares, all rules are made conditional on a "ShareRef" user property.
 * "ShareRef" is null when a doc is accessed in normal way, and the row id of a share when accessed via a share.

There's no UI for controlling shares (George is working on it for forms), but you can do it by editing a `_grist_Shares` table in a document. Suppose you make a fresh document with a single page/table/widget, then to create an empty share you can do:

```
gristDocPageModel.gristDoc.get().docData.sendAction(['AddRecord', '_grist_Shares', null, {linkId: 'xyz', options: '{"publish": true}'}])
```

If you look at the home db now there should be something in the `shares` table:

```
$ sqlite3 -table landing.db "select * from shares"
+----+------------------------+------------------------+--------------+---------+
| id |          key           |         doc_id         |   link_id    | options |
+----+------------------------+------------------------+--------------+---------+
| 1  | gSL4g38PsyautLHnjmXh2K | 4qYuace1xP2CTcPunFdtan | xyz | ...      |
+----+------------------------+------------------------+--------------+---------+
```

If you take the key from that (gSL4g38PsyautLHnjmXh2K in this case) and replace the document's urlId in its URL with `s.<key>` (in this case `s.gSL4g38PsyautLHnjmXh2K` then you can use the regular document landing page (it will be quite blank initially) or API endpoint via the share.

E.g. for me `http://localhost:8080/o/docs/s0gSL4g38PsyautLHnjmXh2K/share-inter-3` accesses the doc.

To actually share some material - useful commands:

```
gristDocPageModel.gristDoc.get().docData.getMetaTable('_grist_Views_section').getRecords()
gristDocPageModel.gristDoc.get().docData.sendAction(['UpdateRecord', '_grist_Views_section', 1, {shareOptions: '{"publish": true, "form": true}'}])
gristDocPageModel.gristDoc.get().docData.getMetaTable('_grist_Pages').getRecords()
gristDocPageModel.gristDoc.get().docData.sendAction(['UpdateRecord', '_grist_Pages', 1, {shareRef: 1}])
```

For a share to be effective, at least one page needs to have its shareRef set to the rowId of the share, and at least one widget on one of those pages needs to have its shareOptions set to {"publish": "true", "form": "true"} (meaning turn on sharing, and include form sharing), and the share itself needs {"publish": true} on its options.

I think special shares are kind of incompatible with public sharing, since by their nature (allowing access to all endpoints) they easily expose the docId, and changing that would be hard.

Test Plan: tests added

Reviewers: dsagal, georgegevoian

Reviewed By: dsagal, georgegevoian

Subscribers: jarek, dsagal

Differential Revision: https://phab.getgrist.com/D4144
2024-01-04 05:57:38 -05:00
..
1536634251710-Initial.ts (core) add a yarn run cli tool, and add a sqlite gristify option 2022-07-14 12:00:30 -04:00
1539031763952-Login.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1549313797109-PinDocs.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1549381727494-UserPicture.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1551805156919-LoginDisplayEmail.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1552416614755-LoginDisplayEmailNonNull.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1553016106336-Indexes.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1556726945436-Billing.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1557157922339-OrgDomainUnique.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1561589211752-Aliases.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1568238234987-TeamMembers.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1569593726320-FirstLogin.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1569946508569-FirstTimeUser.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1573569442552-CustomerIndex.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1579559983067-ExtraIndexes.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1591755411755-OrgHost.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1592261300044-DocRemovedAt.ts (core) move home server into core 2020-07-21 20:39:10 -04:00
1596456522124-Prefs.ts (core) add per-user per-org preferences to database 2020-08-04 15:20:13 -04:00
1623871765992-ExternalBilling.ts (core) add appsumo endpoints with stub implementations 2021-06-21 16:04:33 -04:00
1626369037484-DocOptions.ts (core) add docs.options column to home db to store doc description, icon, openMode 2021-07-15 21:51:05 -04:00
1631286208009-Secret.ts (core) Initial webhooks implementation 2021-09-23 14:35:39 +02:00
1644363380225-UserOptions.ts (core) Add account page option to allow Google login 2022-02-14 16:56:23 -08:00
1647883793388-GracePeriodStart.ts (core) Grace period and delete-only mode when exceeding row limit 2022-03-25 13:41:33 +02:00
1651469582887-DocumentUsage.ts (core) Add API endpoint to get site usage summary 2022-05-16 11:16:19 -07:00
1652273656610-Activations.ts (core) add a yarn run cli tool, and add a sqlite gristify option 2022-07-14 12:00:30 -04:00
1652277549983-UserConnectId.ts (core) Adding GristConnect login system 2022-05-18 20:28:25 +02:00
1663851423064-UserUUID.ts (core) Adding new column in users table "ref" with unique identifier. 2022-10-04 15:19:28 +02:00
1664528376930-UserRefUnique.ts (core) Migration that makes user.ref unique and non-nullable 2022-10-12 11:13:00 +02:00
1673051005072-Forks.ts (core) Persist forks in home db 2023-02-20 22:46:36 -05:00
1678737195050-ForkIndexes.ts (core) Add initial tutorials implementation 2023-03-22 10:09:02 -04:00
1682636695021-ActivationPrefs.ts (core) Add Support Grist page and nudge 2023-07-04 17:36:59 -04:00
1685343047786-AssistantLimit.ts (core) Billing for formula assistant 2023-07-10 13:24:08 +02:00
1701557445716-Shares.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00