2020-12-04 23:29:29 +00:00
|
|
|
import { PartialPermissionSet } from 'app/common/ACLPermissions';
|
2020-11-17 21:49:32 +00:00
|
|
|
import { CellValue, RowRecord } from 'app/common/DocActions';
|
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 {
|
2020-12-04 23:29:29 +00:00
|
|
|
origRecord?: RowRecord; // 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.
|
|
|
|
matchFunc?: AclMatchFunc;
|
2020-10-12 13:50:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 21:49:32 +00:00
|
|
|
// Light wrapper around characteristics or records.
|
|
|
|
export interface InfoView {
|
|
|
|
get(key: string): CellValue;
|
|
|
|
toJSON(): {[key: string]: any};
|
2020-10-19 14:25:21 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 21:49:32 +00:00
|
|
|
// Represents user info, which may include properties which are themselves RowRecords.
|
2020-12-09 13:57:35 +00:00
|
|
|
export type UserInfo = Record<string, CellValue|InfoView|Record<string, string>>;
|
2020-11-17 21:49:32 +00:00
|
|
|
|
2020-11-03 23:44:09 +00:00
|
|
|
/**
|
2020-11-17 21:49:32 +00:00
|
|
|
* Input into the AclMatchFunc. Compiled formulas evaluate AclMatchInput to produce a boolean.
|
2020-11-03 23:44:09 +00:00
|
|
|
*/
|
2020-11-17 21:49:32 +00:00
|
|
|
export interface AclMatchInput {
|
|
|
|
user: UserInfo;
|
|
|
|
rec?: InfoView;
|
|
|
|
newRec?: InfoView;
|
2020-11-03 23:44:09 +00:00
|
|
|
}
|
|
|
|
|
2020-10-19 14:25:21 +00:00
|
|
|
/**
|
2020-11-17 21:49:32 +00:00
|
|
|
* The actual boolean function that can evaluate a request. The result of compiling ParsedAclFormula.
|
2020-10-19 14:25:21 +00:00
|
|
|
*/
|
2020-11-17 21:49:32 +00:00
|
|
|
export type AclMatchFunc = (input: AclMatchInput) => boolean;
|
2020-10-19 14:25:21 +00:00
|
|
|
|
2020-11-03 23:44:09 +00:00
|
|
|
/**
|
2020-11-17 21:49:32 +00:00
|
|
|
* Representation of a parsed ACL formula.
|
2020-11-03 23:44:09 +00:00
|
|
|
*/
|
2020-11-17 21:49:32 +00:00
|
|
|
export type ParsedAclFormula = [string, ...Array<ParsedAclFormula|CellValue>];
|
2020-10-19 14:25:21 +00:00
|
|
|
|
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
|
|
|
}
|