gristlabs_grist-core/app/server/lib
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
..
AccessTokens.ts
ACLFormula.ts (core) Decode cell values to prevent working around rule using 'in' on lists 2023-12-04 23:34:08 +02:00
ActionHistory.ts (core) Fix issue with lodash's map interpreting objects with length as array-like 2023-07-01 21:07:39 -04:00
ActionHistoryImpl.ts
ActiveDoc.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
ActiveDocImport.ts Split out new importFileAsNewTable method for grist-static (#564) 2023-07-12 15:57:02 +02:00
AppEndpoint.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
AppSettings.ts add an endpoint for doing SQL selects (#641) 2023-09-04 09:21:18 -04:00
Assistance.ts (core) updates from grist-core 2023-08-21 09:15:53 -04:00
Authorizer.ts (core) Revamp ForwardAuthLogin and unify with GRIST_PROXY_AUTH_HEADER 2023-11-07 16:30:49 -05:00
BrowserSession.ts Issue 740 OIDC login redirect (#742) 2023-11-15 09:23:32 -05:00
checksumFile.ts
Client.ts (core) Exit more cleanly on unhandled errors, and handle errors writing to Clients. 2023-12-01 09:42:00 -05:00
Comm.ts (core) Exit more cleanly on unhandled errors, and handle errors writing to Clients. 2023-12-01 09:42:00 -05:00
configureMinIOExternalStorage.ts Abort when MinIO bucket does not have versioning enabled #545 (#546) 2023-07-10 06:24:55 -04:00
dbUtils.ts Introduce TYPEORM_EXTRA env variable (#770) 2023-11-27 10:47:56 -05:00
DiscourseConnect.ts
DocApi.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
DocClients.ts (core) Exit more cleanly on unhandled errors, and handle errors writing to Clients. 2023-12-01 09:42:00 -05:00
DocManager.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
DocPluginData.ts
DocPluginManager.ts
DocSession.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
DocSnapshots.ts
DocStorage.ts add an endpoint for doing SQL selects (#641) 2023-09-04 09:21:18 -04:00
DocStorageManager.ts
docUtils.d.ts
docUtils.js
DocWorker.ts Remove attachments and system files from document download as template (#729) 2023-11-08 15:09:01 -05:00
DocWorkerMap.ts
DocWorkerUtils.ts (core) Add support for auto-copying docs on signup 2023-09-06 15:12:08 -04:00
ExcelFormatter.ts
ExpandedQuery.ts
Export.ts Option to export colId as header in CSV / XSLX instead of label (#688) (#692) 2023-10-15 20:17:43 -04:00
ExportCSV.ts Option to export colId as header in CSV / XSLX instead of label (#688) (#692) 2023-10-15 20:17:43 -04:00
ExportTableSchema.ts Add header=colId option for the table-schema API #719 (#749) 2023-11-17 17:45:15 +02:00
ExportXLSX.ts add hooks for tweaking how downloads happen (for grist-static) (#665) 2023-09-09 14:50:32 -04:00
expressWrap.ts (core) Update dependencies 2023-10-11 17:36:58 -04:00
ExternalStorage.ts
extractOrg.ts (core) support for bundling custom widgets with the Grist app 2023-10-27 17:00:10 -04:00
FileParserElement.ts
filterUtils.ts
FlexServer.ts (core) Forms feature 2023-12-20 13:23:12 +01:00
ForwardAuthLogin.ts (core) Revamp ForwardAuthLogin and unify with GRIST_PROXY_AUTH_HEADER 2023-11-07 16:30:49 -05:00
GoogleAuth.ts Add ws id and doc name params to POST /docs (#655) 2023-09-05 14:27:35 -04:00
GoogleExport.ts Add ws id and doc name params to POST /docs (#655) 2023-09-05 14:27:35 -04:00
GoogleImport.ts
GranularAccess.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
GristServer.ts (core) For slowly reported telemetry, add breaks to give other processes a chance to run 2023-11-28 14:34:36 -05:00
gristSessions.ts (core) Add options to /status health-check endpoints to check DB and Redis liveness. 2023-10-02 14:41:04 -04:00
gristSettings.ts move getTemplateOrg method; enable template org in docker tests (#602) 2023-07-31 16:10:59 -04:00
guessExt.ts
hashingUtils.ts (core) Add Support Grist page and nudge 2023-07-04 17:36:59 -04:00
HashUtil.ts
HostedMetadataManager.ts
HostedStorageManager.ts
httpEncoding.ts
IBilling.ts
IChecksumStore.ts
ICreate.ts (core) move apiserver tests to core, disentangling notifier+billing parts 2023-12-26 08:43:12 -05:00
IDocStorageManager.ts
idUtils.ts
IElectionStore.ts
initialDocSql.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
INotifier.ts (core) move apiserver tests to core, disentangling notifier+billing parts 2023-12-26 08:43:12 -05:00
ISandbox.ts
IShell.ts
ITestingHooks-ti.ts (core) Exit more cleanly on unhandled errors, and handle errors writing to Clients. 2023-12-01 09:42:00 -05:00
ITestingHooks.ts (core) Exit more cleanly on unhandled errors, and handle errors writing to Clients. 2023-12-01 09:42:00 -05:00
log.ts
LogMethods.ts
manifest.ts (core) support for bundling custom widgets with the Grist app 2023-10-27 17:00:10 -04:00
MemoryPool.ts (core) Manage memory used for websocket responses to reduce the risk of server crashes. 2023-08-07 11:28:31 -04:00
MinimalLogin.ts
MinIOExternalStorage.ts Issue 359 support scaleway (#577) 2023-07-20 06:16:58 -04:00
NSandbox.ts (core) Support adjusting OOM score for child sandbox processes. 2023-11-16 17:43:06 -05:00
NullSandbox.ts
OIDCConfig.ts Rename endSessionEndpoint flag to skipEndSessionEndpoint (#793) 2023-12-17 15:10:10 -05:00
OnDemandActions.ts
PermissionInfo.ts (core) Fixing memos in record dependent rules. 2023-09-08 10:16:09 +02:00
Permit.ts
places.ts
PluginEndpoint.ts include the @gristlabs/grist-widget package, so Calendar is always available (#745) 2023-11-28 09:28:15 -05:00
PluginManager.ts include the @gristlabs/grist-widget package, so Calendar is always available (#745) 2023-11-28 09:28:15 -05:00
ProcessMonitor.ts (core) Add new telemetry events 2023-11-01 10:49:33 -04:00
ProxyAgent.ts
reportTimeTaken.ts
Requests.ts REQUEST now supports POST (#588) 2023-07-30 15:13:43 -04:00
requestUtils.ts (core) Add welcomeQuestionsSubmitted telemetry event 2023-09-13 00:31:04 -04:00
RowAccess.ts
SafePythonComponent.ts
SamlConfig.ts (core) Fix delete user button for Google-only accounts 2023-10-18 10:52:58 -04:00
SandboxControl.ts (core) Update dependencies 2023-10-11 17:36:58 -04:00
sandboxUtil.ts (core) Update logging in sandbox code, and log tracebacks as single log messages. 2023-07-18 11:21:25 -04:00
sendAppPage.ts (core) Record Cards 2023-11-19 20:12:37 -05:00
ServerColumnGetters.ts (core) Filter rows based on linked widgets when exporting view 2023-07-26 21:49:52 +02:00
ServerLocale.ts
serverUtils.ts (core) Add timeouts to prevent ActiveDoc bad state during shutdown. 2023-09-26 15:32:49 -04:00
Sessions.ts
Sharing.ts (core) add initial support for special shares 2024-01-04 05:57:38 -05:00
shortDesc.ts
shutdown.js
SqliteCommon.ts add an endpoint for doing SQL selects (#641) 2023-09-04 09:21:18 -04:00
SQLiteDB.ts add an endpoint for doing SQL selects (#641) 2023-09-04 09:21:18 -04:00
SqliteNode.ts add an endpoint for doing SQL selects (#641) 2023-09-04 09:21:18 -04:00
TableMetadataLoader.ts (core) Support adjusting OOM score for child sandbox processes. 2023-11-16 17:43:06 -05:00
TagChecker.ts
Telemetry.ts (core) Add visitorId to telemetry 2023-12-11 11:16:23 -05:00
TestingHooks.ts (core) Exit more cleanly on unhandled errors, and handle errors writing to Clients. 2023-12-01 09:42:00 -05:00
TestLogin.ts
Throttle.ts
TimeQuery.ts
Triggers.ts (core) When a webhook is disabled, clear its queue 2023-11-07 15:48:35 +02:00
UnsafeNodeComponent.ts
uploads.ts (core) Add support for auto-copying docs on signup 2023-09-06 15:12:08 -04:00
WidgetRepository.ts Change how a builtin custom widget bundle is found (#783) 2023-12-05 11:51:22 -05:00
WorkCoordinator.ts
workerExporter.ts Option to export colId as header in CSV / XSLX instead of label (#688) (#692) 2023-10-15 20:17:43 -04:00