gristlabs_grist-core/app/common
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
..
themes (core) Improve dark mode in tutorials 2023-11-06 13:06:13 -05:00
ACLPermissions.ts
ACLRuleCollection.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
ACLShareRules.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
ActionBundle.ts REQUEST now supports POST (#588) 2023-07-30 15:13:43 -04:00
ActionDispatcher.ts
ActionGroup.ts
ActionRouter.ts
ActionSummarizer.ts (core) Adds a UI panel for managing webhooks 2023-05-08 18:25:27 -04:00
ActionSummary.ts
ActiveDocAPI.ts (core) Cursor in custom widgets 2023-08-29 09:19:52 +02:00
AlternateActions.ts (core) Adds a UI panel for managing webhooks 2023-05-08 18:25:27 -04:00
ApiError.ts (core) Trigger email verification flow when needed 2023-12-13 09:18:41 -05:00
arrayToString.ts
AssistancePrompts.ts (core) Add AI assistant usage banners 2023-08-30 16:00:04 -04:00
AsyncCreate.ts
AsyncFlow.ts
asyncIterators.ts
AttachmentColumns.ts
BaseAPI.ts remove a log message about fetching URLs (#643) 2023-08-29 08:49:25 -04:00
BasketClientAPI.ts
BigInt.ts
BillingAPI.ts (core) Removing temporary pro site 2023-08-16 08:11:26 +02:00
BinaryIndexedTree.js
BrowserSettings.ts
CircularArray.js
ColumnFilterFunc.ts
ColumnGetters.ts (core) Filter rows based on linked widgets when exporting view 2023-07-26 21:49:52 +02:00
CommTypes.ts (core) deleting queue from single webhook 2023-07-18 11:46:10 +02:00
csvFormat.ts
CustomWidget.ts allow bundled widgets to be hidden from dropdown, and nested (#714) 2023-10-30 21:13:21 -04:00
declarations.d.ts
delay.ts
DisposableWithEvents.ts
DocActions.ts (core) Remove transform columns on shutdown 2023-11-14 22:31:34 +02:00
DocData.ts (core) Adds a UI panel for managing webhooks 2023-05-08 18:25:27 -04:00
DocDataCache.ts (core) Adds a UI panel for managing webhooks 2023-05-08 18:25:27 -04:00
DocLimits.ts
DocListAPI.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
DocSnapshot.ts
DocumentSettings.ts
DocUsage.ts
emails.ts
EncActionBundle.ts
ErrorWithCode.ts
Features.ts (core) Change the label/nickname of the paid plan to Pro 2023-08-07 23:45:18 -04:00
FilterState.ts
Forms.ts (core) Forms feature 2023-12-20 13:23:12 +01:00
Formula.ts
getCurrentTime.ts
GranularAccessClause.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
GristServerAPI.ts
gristTypes.ts (core) Treating null in toggle column as a valid value 2023-11-13 20:38:30 +01:00
gristUrls.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
gutil.ts (core) Forms feature 2023-12-20 13:23:12 +01:00
InactivityTimer.ts
Install.ts (core) Add Support Grist page and nudge 2023-07-04 17:36:59 -04:00
InstallAPI.ts (core) Add Support Grist page and nudge 2023-07-04 17:36:59 -04:00
Interval.ts
isHiddenTable.ts (core) Cursor in custom widgets 2023-08-29 09:19:52 +02:00
KeyedMutex.ts
KeyedOps.ts
LocaleCodes.ts
Locales.ts
LoginSessionAPI.ts
marshal.ts support other SQLite wrappers, and various hooks needed by grist-static (#516) 2023-05-23 15:17:28 -04:00
MemBuffer.js
NumberFormat.ts
NumberParse.ts
orgNameUtils.ts (core) Add optional telemetry to grist-core 2023-06-07 12:00:51 -04:00
parseDate.ts (core) Converting big number (9 digits or more) to date directly 2023-10-05 16:58:25 +02:00
plugin.ts
PluginInstance.ts
Prefs.ts (core) Add tip for calendar widget configuration 2023-09-20 11:10:58 -04:00
RecentItems.js
RefCountMap.ts
RelativeDates.ts (core) Set DateTime timezone during xlsx import 2023-05-24 11:39:49 -04:00
resetOrg.ts
roles.ts
RowFilterFunc.ts (core) Filter rows based on linked widgets when exporting view 2023-07-26 21:49:52 +02:00
schema.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
ShareAnnotator.ts
ShareOptions.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
sharing.ts
SortFunc.ts
SortSpec.ts
StringUnion.ts
TableData.ts (core) Cursor in custom widgets 2023-08-29 09:19:52 +02:00
TabularDiff.ts
tagManager.ts
tbind.ts
Telemetry.ts (core) Add more telemetry events 2023-11-16 12:38:08 -05:00
TestState.ts
ThemePrefs-ti.ts (core) Improve dark mode in tutorials 2023-11-06 13:06:13 -05:00
ThemePrefs.ts (core) Improve dark mode in tutorials 2023-11-06 13:06:13 -05:00
Themes.ts
timeFormat.ts
tpromisified.ts
Triggers-ti.ts (core) GET endpoint for webhooks returns now data in format {webhooks:[...]} 2023-07-26 11:36:24 +02:00
Triggers.ts (core) GET endpoint for webhooks returns now data in format {webhooks:[...]} 2023-07-26 11:36:24 +02:00
tsconfig.json
tsvFormat.ts
uploads.ts
urlUtils.ts
UserAPI.ts (core) Forms feature 2023-12-20 13:23:12 +01:00
UserConfig.ts
ValueConverter.ts (core) Implement exported functions without relying on ActiveDoc.docData 2023-06-07 22:30:01 +02:00
ValueFormatter.ts
ValueGuesser.ts
ValueParser.ts
WidgetOptions.ts
widgetTypes.ts (core) Forms feature 2023-12-20 13:23:12 +01:00