(core) Update ACL resources/rules when tables/columns get renamed

Summary:
- Placed rule-updating functions in acl.py.
- Reset UI when rules update externally, or alert the user to reset if there
  are pending local changes.
- Removed some unused and distracting bits from client-side DocModel.

A few improvements related to poor error handling:
- In case of missing DocActions (tickled by broken ACL rule handling), don't
  add to confusion by attempting to process bad actions
- In case of missing attributes in ACL formulas, return undefined rather than
  fail; the latter creates more problems.
- In case in invalid rules, fail rather than skip; this feels more correct now
  that we have error checking and recovery option, and helps avoid invalid rules.
- Prevent saving invalid rules with an empty ACL formula.
- Fix bug with rule positions.

Test Plan: Added a python and browser test for table/column renames.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D2698
This commit is contained in:
Dmitry S
2020-12-28 00:40:10 -05:00
parent d6d1eb217f
commit 5deac68315
14 changed files with 338 additions and 79 deletions

View File

@@ -1,14 +0,0 @@
import {ACLPrincipalRec, DocModel, IRowModel, refRecord} from 'app/client/models/DocModel';
import * as ko from 'knockout';
// Table for containment relationships between Principals, e.g. user contains multiple
// instances, group contains multiple users, and groups may contain other groups.
export interface ACLMembershipRec extends IRowModel<"_grist_ACLMemberships"> {
parentRec: ko.Computed<ACLPrincipalRec>;
childRec: ko.Computed<ACLPrincipalRec>;
}
export function createACLMembershipRec(this: ACLMembershipRec, docModel: DocModel): void {
this.parentRec = refRecord(docModel.aclPrincipals, this.parent);
this.childRec = refRecord(docModel.aclPrincipals, this.child);
}

View File

@@ -1,29 +0,0 @@
import {KoArray} from 'app/client/lib/koArray';
import {ACLMembershipRec, DocModel, IRowModel, recordSet} from 'app/client/models/DocModel';
import {KoSaveableObservable} from 'app/client/models/modelUtil';
import * as ko from 'knockout';
// A principals used by ACL rules, including users, groups, and instances.
export interface ACLPrincipalRec extends IRowModel<"_grist_ACLPrincipals"> {
// Declare a more specific type for 'type' than what's set automatically from schema.ts.
type: KoSaveableObservable<'user'|'instance'|'group'>;
// KoArray of ACLMembership row models which contain this principal as a child.
parentMemberships: ko.Computed<KoArray<ACLMembershipRec>>;
// Gives an array of ACLPrincipal parents to this row model.
parents: ko.Computed<ACLPrincipalRec[]>;
// KoArray of ACLMembership row models which contain this principal as a parent.
childMemberships: ko.Computed<KoArray<ACLMembershipRec>>;
// Gives an array of ACLPrincipal children of this row model.
children: ko.Computed<ACLPrincipalRec[]>;
}
export function createACLPrincipalRec(this: ACLPrincipalRec, docModel: DocModel): void {
this.parentMemberships = recordSet(this, docModel.aclMemberships, 'child');
this.childMemberships = recordSet(this, docModel.aclMemberships, 'parent');
this.parents = ko.pureComputed(() => this.parentMemberships().all().map(m => m.parentRec()));
this.children = ko.pureComputed(() => this.childMemberships().all().map(m => m.childRec()));
}

View File

@@ -1,7 +0,0 @@
import {DocModel, IRowModel} from 'app/client/models/DocModel';
export type ACLResourceRec = IRowModel<"_grist_ACLResources">;
export function createACLResourceRec(this: ACLResourceRec, docModel: DocModel): void {
// no extra fields
}