mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Checks that an ACL formula can be parsed, and prevent saving unparsable ACL rules.
Summary: - Fix error-handling in bundleActions(), and wait for the full bundle to complete. (The omissions here were making it impossibly to react to errors from inside bundleActions()) - Catch problematic rules early enough to undo them, by trying out ruleCollection.update() on updated rules before the updates are applied. - Added checkAclFormula() call to DocComm that checks parsing and compiling formula, and reports errors. - In UI, prevent saving if any aclFormulas are invalid, or while waiting for the to get checked. - Also fixed some lint errors Test Plan: Added a test case of error reporting in ACL formulas. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2689
This commit is contained in:
@@ -49,6 +49,10 @@ const EMERGENCY_RULE_SET: RuleSet = {
|
||||
};
|
||||
|
||||
export class ACLRuleCollection {
|
||||
// Store error if one occurs while reading rules. Rules are replaced with emergency rules
|
||||
// in this case.
|
||||
public ruleError: Error|undefined;
|
||||
|
||||
// In the absence of rules, some checks are skipped. For now this is important to maintain all
|
||||
// existing behavior. TODO should make sure checking access against default rules is equivalent
|
||||
// and efficient.
|
||||
@@ -72,10 +76,6 @@ export class ACLRuleCollection {
|
||||
// Maps name to the corresponding UserAttributeRule.
|
||||
private _userAttributeRules = new Map<string, UserAttributeRule>();
|
||||
|
||||
// Store error if one occurs while reading rules. Rules are replaced with emergency rules
|
||||
// in this case.
|
||||
public ruleError: Error|undefined;
|
||||
|
||||
// Whether there are ANY user-defined rules.
|
||||
public haveRules(): boolean {
|
||||
return this._haveRules;
|
||||
@@ -170,7 +170,7 @@ export class ACLRuleCollection {
|
||||
try {
|
||||
this.ruleError = undefined;
|
||||
return readAclRules(docData, options);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
this.ruleError = e; // Report the error indirectly.
|
||||
return {ruleSets: [EMERGENCY_RULE_SET], userAttributes: []};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user