Compare commits

...
Author SHA1 Message Date
Will Schurman 0e8e05f963 fix: convert privacy policy rule definition to functions 2023-12-04 14:33:52 -08:00
2 changed files with 77 additions and 20 deletions

No files matched your search

+37 -8
View File
@@ -98,34 +98,63 @@ export default abstract class EntityPrivacyPolicy<
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
TSelectedFields extends keyof TFields = keyof TFields
> {
protected readonly createRules: readonly PrivacyPolicyRule<
protected abstract getCreateRules?(): readonly PrivacyPolicyRule<
TFields,
TID,
TViewerContext,
TEntity,
TSelectedFields
>[] = [];
protected readonly readRules: readonly PrivacyPolicyRule<
>[];
protected abstract getReadRules?(): readonly PrivacyPolicyRule<
TFields,
TID,
TViewerContext,
TEntity,
TSelectedFields
>[] = [];
protected readonly updateRules: readonly PrivacyPolicyRule<
>[];
protected abstract getUpdateRules?(): readonly PrivacyPolicyRule<
TFields,
TID,
TViewerContext,
TEntity,
TSelectedFields
>[] = [];
protected readonly deleteRules: readonly PrivacyPolicyRule<
>[];
protected abstract getDeleteRules?(): readonly PrivacyPolicyRule<
TFields,
TID,
TViewerContext,
TEntity,
TSelectedFields
>[] = [];
>[];
private createRules: readonly PrivacyPolicyRule<
TFields,
TID,
TViewerContext,
TEntity,
TSelectedFields
>[] = this.getCreateRules ? this.getCreateRules() : [];
private readRules: readonly PrivacyPolicyRule<
TFields,
TID,
TViewerContext,
TEntity,
TSelectedFields
>[] = this.getReadRules ? this.getReadRules() : [];
private updateRules: readonly PrivacyPolicyRule<
TFields,
TID,
TViewerContext,
TEntity,
TSelectedFields
>[] = this.getUpdateRules ? this.getUpdateRules() : [];
private deleteRules: readonly PrivacyPolicyRule<
TFields,
TID,
TViewerContext,
TEntity,
TSelectedFields
>[] = this.getDeleteRules ? this.getDeleteRules() : [];
/**
* Get the privacy policy evaluation mode and deny handler for this policy.
@@ -6,6 +6,7 @@ import EntityPrivacyPolicy from '../../EntityPrivacyPolicy';
import ViewerContext from '../../ViewerContext';
import { successfulResults, failedResults } from '../../entityUtils';
import AlwaysAllowPrivacyPolicyRule from '../../rules/AlwaysAllowPrivacyPolicyRule';
import PrivacyPolicyRule from '../../rules/PrivacyPolicyRule';
import { createUnitTestEntityCompanionProvider } from '../../utils/testing/createUnitTestEntityCompanionProvider';
describe('Two entities backed by the same table', () => {
@@ -107,18 +108,45 @@ const testEntityConfiguration = new EntityConfiguration<TestFields>({
});
class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<any, string, ViewerContext, any, any> {
protected override readonly readRules = [
new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>(),
];
protected override readonly createRules = [
new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>(),
];
protected override readonly updateRules = [
new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>(),
];
protected override readonly deleteRules = [
new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>(),
];
protected override getReadRules(): readonly PrivacyPolicyRule<
any,
string,
ViewerContext,
any,
any
>[] {
return [new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>()];
}
protected override getCreateRules(): readonly PrivacyPolicyRule<
any,
string,
ViewerContext,
any,
any
>[] {
return [new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>()];
}
protected override getUpdateRules(): readonly PrivacyPolicyRule<
any,
string,
ViewerContext,
any,
any
>[] {
return [new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>()];
}
protected override getDeleteRules(): readonly PrivacyPolicyRule<
any,
string,
ViewerContext,
any,
any
>[] {
return [new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>()];
}
}
class OneTestEntity extends Entity<TestFields, string, ViewerContext, OneTestFields> {