mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) alert user if they try to use rec in a column rule controlling read permission
Summary: This particular combination of features is not built out - data will be censored but changes to data will not. So the user will now get an error if they try to do it. Existing rules of this kind will continue to operate as before, and can be set via the api. Test Plan: added test Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2751
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {ActionGroup} from 'app/common/ActionGroup';
|
||||
import {CellValue, TableDataAction, UserAction} from 'app/common/DocActions';
|
||||
import {FormulaProperties} from 'app/common/GranularAccessClause';
|
||||
import {Peer} from 'app/common/sharing';
|
||||
import {UploadResult} from 'app/common/uploads';
|
||||
import {ParseOptions} from 'app/plugin/FileParserAPI';
|
||||
@@ -226,7 +227,7 @@ export interface ActiveDocAPI {
|
||||
/**
|
||||
* Check if an ACL formula is valid. If not, will throw an error with an explanation.
|
||||
*/
|
||||
checkAclFormula(text: string): Promise<void>;
|
||||
checkAclFormula(text: string): Promise<FormulaProperties>;
|
||||
|
||||
/**
|
||||
* Returns the full set of tableIds, with the list of colIds for each table. This is intended
|
||||
|
||||
@@ -57,6 +57,13 @@ export type AclMatchFunc = (input: AclMatchInput) => boolean;
|
||||
*/
|
||||
export type ParsedAclFormula = [string, ...Array<ParsedAclFormula|CellValue>];
|
||||
|
||||
/**
|
||||
* Observations about a formula.
|
||||
*/
|
||||
export interface FormulaProperties {
|
||||
hasRecOrNewRec?: boolean;
|
||||
}
|
||||
|
||||
export interface UserAttributeRule {
|
||||
origRecord?: RowRecord; // Original record used to create this UserAttributeRule.
|
||||
name: string; // Should be unique among UserAttributeRules.
|
||||
@@ -64,3 +71,26 @@ export interface UserAttributeRule {
|
||||
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'.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check some key facts about the formula.
|
||||
*/
|
||||
export function getFormulaProperties(formula: ParsedAclFormula) {
|
||||
const result: FormulaProperties = {}
|
||||
if (usesRec(formula)) { result.hasRecOrNewRec = true; }
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a formula mentions `rec` or `newRec`.
|
||||
*/
|
||||
export function usesRec(formula: ParsedAclFormula): boolean {
|
||||
if (!Array.isArray(formula)) { throw new Error('expected a list'); }
|
||||
if (formula[0] === 'Name' && (formula[1] === 'rec' || formula[1] === 'newRec')) {
|
||||
return true;
|
||||
}
|
||||
return formula.some(el => {
|
||||
if (!Array.isArray(el)) { return false; }
|
||||
return usesRec(el as any);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user