From 98028b039550751417d798fd05e1a07cdcb212ce Mon Sep 17 00:00:00 2001 From: paulleonartcalvo Date: Thu, 19 Sep 2024 13:54:52 -0400 Subject: [PATCH] chore: complexity --- packages/casl-ability/spec/error.spec.ts | 2 +- packages/casl-ability/src/ForbiddenError.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/casl-ability/spec/error.spec.ts b/packages/casl-ability/spec/error.spec.ts index 3e147301c..e34d5d9f2 100644 --- a/packages/casl-ability/spec/error.spec.ts +++ b/packages/casl-ability/spec/error.spec.ts @@ -24,7 +24,7 @@ describe('`ForbiddenError` class', () => { it('does not produce error on forbidden action when inverted', () => { const { error } = setup() - expect(error.unlessCannot('read', 'Post')).toBeUndefined() + expect(error.unlessCannot('archive', 'Post')).toBeUndefined() }) it('produces an error on allowed action when inverted', () => { diff --git a/packages/casl-ability/src/ForbiddenError.ts b/packages/casl-ability/src/ForbiddenError.ts index c5c08d4ba..dee1f1d80 100644 --- a/packages/casl-ability/src/ForbiddenError.ts +++ b/packages/casl-ability/src/ForbiddenError.ts @@ -56,9 +56,9 @@ export class ForbiddenError extends NativeError { ): this | undefined { const rule = this.ability.relevantRuleFor(action, subject, field); - const isRuleInverted = rule?.inverted ?? false; - - if (inverted === isRuleInverted) { + if (inverted && (!rule || rule.inverted)) { + return; + } else if (!inverted && rule && !rule.inverted) { return; }