gristlabs_grist-core/app/client/models
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
..
entities (core) Forms feature 2023-12-20 13:23:12 +01:00
AppModel.ts Allow URLs with only a docID #768 (#771) 2023-11-29 15:13:29 -05:00
BaseRowModel.js (core) Update ACL resources/rules when tables/columns get renamed 2021-01-04 22:03:01 -05:00
ClientColumnGetters.ts (core) Filter rows based on linked widgets when exporting view 2023-07-26 21:49:52 +02:00
ColumnACIndexes.ts Rename text cleaning function to "normalizeText" 2022-08-17 19:11:52 +02:00
ColumnCache.ts (core) Show count of formula errors in the column config in the right-side panel. 2021-04-20 21:26:17 -04:00
ColumnFilter.ts (core) Fix date filter for DateTime columns. 2023-01-18 10:18:15 +01:00
ColumnFilterMenuModel.ts (core) Add behavioral and coaching call popups 2022-12-20 09:49:41 -05:00
ColumnToMap.ts (core) Extending widget 2023-10-09 14:53:20 +02:00
ConnectState.ts (core) move client code to core 2020-10-02 13:24:21 -04:00
DataRowModel.ts (core) When a checkbox is clicked on a new record, set default values determined by linking 2022-11-10 14:34:40 -05:00
DataTableModel.js (core) move client code to core 2020-10-02 13:24:21 -04:00
DataTableModelWithDiff.ts (core) Faster builds all around. 2022-07-04 10:42:40 -04:00
DocData.ts (core) forward more kinds of edits to a virtual table 2023-06-26 12:05:34 -04:00
DocModel.ts (core) Polish new Add Column menu 2023-10-17 15:39:53 -04:00
DocPageModel.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
errors.ts (core) Avoid reporting unhelpful ResizeObserver error 2023-10-27 15:26:20 -04:00
features.ts (core) Forms feature 2023-12-20 13:23:12 +01:00
gristConfigCache.ts (core) move client code to core 2020-10-02 13:24:21 -04:00
gristUrlState.ts (core) Treating API urls as external in cells 2023-10-24 08:55:08 +02:00
HomeModel.ts (core) Move theme from ConfigNotifier to ThemeNotifier 2023-10-10 21:45:10 -04:00
MetaRowModel.js (core) Forms feature 2023-12-20 13:23:12 +01:00
MetaTableModel.js (core) Raw renames 2022-04-27 22:21:55 +02:00
modelUtil.js (core) move client code to core 2020-10-02 13:24:21 -04:00
NotifyModel.ts (core) deleting queue from single webhook 2023-07-18 11:46:10 +02:00
QuerySet.ts (core) Fix for linking issue. 2023-12-20 12:57:41 +01:00
rowset.ts (core) Allow adding rows to widgets filtered by a link using a formula column 2023-12-18 20:28:41 +02:00
rowuid.js (core) move client code to core 2020-10-02 13:24:21 -04:00
RuleOwner.ts (core) Improve highlighting of previewed formula 2023-07-20 14:34:22 -04:00
SearchModel.ts (core) Cursor in custom widgets 2023-08-29 09:19:52 +02:00
SectionFilter.ts (core) Allow adding rows to widgets filtered by a link using a formula column 2023-12-18 20:28:41 +02:00
Styles.ts Header colored (#581) 2023-08-07 11:01:35 -07:00
TableData.ts (core) Use MetaTableData more 2021-12-07 17:09:58 +02:00
TableModel.js (core) Change how formula columns can be converted to data. 2021-03-05 12:42:57 -05:00
TelemetryModel.ts (core) Add Support Grist page and nudge 2023-07-04 17:36:59 -04:00
TreeModel.ts (core) Revealing hidden pages with visible children. 2022-10-31 14:02:38 +01:00
UnionRowSource.ts (core) Allow adding rows to widgets filtered by a link using a formula column 2023-12-18 20:28:41 +02:00
UserManagerModel.ts (core) User language switcher 2023-01-26 09:47:14 +01:00
UserPrefs.ts (core) Improve dark mode 2023-04-12 01:58:48 -04:00
ViewFieldConfig.ts Header colored (#581) 2023-08-07 11:01:35 -07:00
VirtualTable.ts (core) Adds a UI panel for managing webhooks 2023-05-08 18:25:27 -04:00
WorkspaceInfo.ts (core) move client code to core 2020-10-02 13:24:21 -04:00