2021-12-07 11:21:16 +00:00
|
|
|
import {PartialPermissionSet} from 'app/common/ACLPermissions';
|
|
|
|
import {CellValue, RowRecord} from 'app/common/DocActions';
|
2024-04-26 20:34:16 +00:00
|
|
|
import {CompiledPredicateFormula} from 'app/common/PredicateFormula';
|
|
|
|
import {Role} from 'app/common/roles';
|
2021-12-07 11:21:16 +00:00
|
|
|
import {MetaRowRecord} from 'app/common/TableData';
|
2020-10-19 14:25:21 +00:00
|
|
|
|
2020-11-17 21:49:32 +00:00
|
|
|
export interface RuleSet {
|
|
|
|
tableId: '*' | string;
|
|
|
|
colIds: '*' | string[];
|
2020-12-04 23:29:29 +00:00
|
|
|
// The default permissions for this resource, if set, are represented by a RulePart with
|
|
|
|
// aclFormula of "", which must be the last element of body.
|
2020-11-17 21:49:32 +00:00
|
|
|
body: RulePart[];
|
2020-10-12 13:50:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 21:49:32 +00:00
|
|
|
export interface RulePart {
|
2021-12-07 11:21:16 +00:00
|
|
|
origRecord?: MetaRowRecord<'_grist_ACLRules'>; // Original record used to create this RulePart.
|
2020-11-17 21:49:32 +00:00
|
|
|
aclFormula: string;
|
|
|
|
permissions: PartialPermissionSet;
|
|
|
|
permissionsText: string; // The text version of PermissionSet, as stored.
|
|
|
|
|
|
|
|
// Compiled version of aclFormula.
|
2024-04-26 20:34:16 +00:00
|
|
|
matchFunc?: CompiledPredicateFormula;
|
2021-02-15 21:36:33 +00:00
|
|
|
|
|
|
|
// Optional memo, currently extracted from comment in formula.
|
|
|
|
memo?: string;
|
2020-10-12 13:50:07 +00:00
|
|
|
}
|
|
|
|
|
2021-03-01 16:51:30 +00:00
|
|
|
// Light wrapper for reading records or user attributes.
|
2020-11-17 21:49:32 +00:00
|
|
|
export interface InfoView {
|
|
|
|
get(key: string): CellValue;
|
|
|
|
toJSON(): {[key: string]: any};
|
2020-10-19 14:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-03-01 16:51:30 +00:00
|
|
|
// As InfoView, but also supporting writing.
|
|
|
|
export interface InfoEditor {
|
|
|
|
get(key: string): CellValue;
|
|
|
|
set(key: string, val: CellValue): this;
|
|
|
|
toJSON(): {[key: string]: any};
|
|
|
|
}
|
|
|
|
|
2020-11-17 21:49:32 +00:00
|
|
|
// Represents user info, which may include properties which are themselves RowRecords.
|
2021-07-15 00:45:53 +00:00
|
|
|
export interface UserInfo {
|
|
|
|
Name: string | null;
|
|
|
|
Email: string | null;
|
|
|
|
Access: Role | null;
|
|
|
|
Origin: string | null;
|
|
|
|
LinkKey: Record<string, string | undefined>;
|
|
|
|
UserID: number | null;
|
2022-10-17 09:47:16 +00:00
|
|
|
UserRef: string | null;
|
2022-11-15 14:37:48 +00:00
|
|
|
SessionID: string | null;
|
(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-03 16:53:20 +00:00
|
|
|
ShareRef: number | null; // This is a rowId in the _grist_Shares table, if the user
|
|
|
|
// is accessing a document via a share. Otherwise null.
|
2021-07-15 00:45:53 +00:00
|
|
|
[attributes: string]: unknown;
|
|
|
|
toJSON(): {[key: string]: any};
|
|
|
|
}
|
2020-11-17 21:49:32 +00:00
|
|
|
|
|
|
|
export interface UserAttributeRule {
|
2020-12-04 23:29:29 +00:00
|
|
|
origRecord?: RowRecord; // Original record used to create this UserAttributeRule.
|
2020-11-17 21:49:32 +00:00
|
|
|
name: string; // Should be unique among UserAttributeRules.
|
|
|
|
tableId: string; // Table in which to look up an existing attribute.
|
|
|
|
lookupColId: string; // Column in tableId in which to do the lookup.
|
|
|
|
charId: string; // Attribute to look up, possibly a path. E.g. 'Email' or 'office.city'.
|
2020-10-19 14:25:21 +00:00
|
|
|
}
|