mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) control the distribution of attachment metadata
Summary: for users who don't automatically have deep rights to the document, provide them with attachment metadata only for rows they have access to. This is a little tricky to do efficiently. We provide attachment metadata when an individual table is fetched, rather than on initial document load, so we don't block that load on a full document scan. We provide attachment metadata to a client when we see that we are shipping rows mentioning particular attachments, without making any effort to keep track of the metadata they already have. Test Plan: updated tests Reviewers: dsagal, jarek Reviewed By: dsagal, jarek Differential Revision: https://phab.getgrist.com/D3722
This commit is contained in:
@@ -178,9 +178,12 @@ export function toTableDataAction(tableId: string, colValues: TableColValues): T
|
||||
|
||||
// Convert from TableDataAction (used mainly by the sandbox) to TableColValues (used by DocStorage
|
||||
// and external APIs).
|
||||
export function fromTableDataAction(tableData: TableDataAction): TableColValues {
|
||||
const rowIds: number[] = tableData[2];
|
||||
const colValues: BulkColValues = tableData[3];
|
||||
// Also accepts a TableDataAction nested as a tableData member of a larger structure,
|
||||
// for convenience in dealing with the result of fetches.
|
||||
export function fromTableDataAction(tableData: TableDataAction|{tableData: TableDataAction}): TableColValues {
|
||||
const data = ('tableData' in tableData) ? tableData.tableData : tableData;
|
||||
const rowIds: number[] = data[2];
|
||||
const colValues: BulkColValues = data[3];
|
||||
return {id: rowIds, ...colValues};
|
||||
}
|
||||
|
||||
@@ -203,3 +206,33 @@ export function getColValues(records: Partial<RowRecord>[]): BulkColValues {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the col ids mentioned in a record-related DocAction as a list
|
||||
* (even if the action is not a bulk action). Returns undefined if no col ids
|
||||
* mentioned.
|
||||
*/
|
||||
export function getColIdsFromDocAction(docActions: RemoveRecord | BulkRemoveRecord | AddRecord |
|
||||
BulkAddRecord | UpdateRecord | BulkUpdateRecord | ReplaceTableData |
|
||||
TableDataAction): string[] | undefined {
|
||||
if (docActions[3]) { return Object.keys(docActions[3]); }
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract column values for a particular column as CellValue[] from a
|
||||
* record-related DocAction. Undefined if absent.
|
||||
*/
|
||||
export function getColValuesFromDocAction(docAction: RemoveRecord | BulkRemoveRecord | AddRecord |
|
||||
BulkAddRecord | UpdateRecord | BulkUpdateRecord | ReplaceTableData |
|
||||
TableDataAction, colId: string): CellValue[]|undefined {
|
||||
const colValues = docAction[3];
|
||||
if (!colValues) { return undefined; }
|
||||
const cellValues = colValues[colId];
|
||||
if (!cellValues) { return undefined; }
|
||||
if (Array.isArray(docAction[2])) {
|
||||
return cellValues as CellValue[];
|
||||
} else {
|
||||
return [cellValues as CellValue];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user