From f9e766948773dc8a24725e8c390f3177f81d4619 Mon Sep 17 00:00:00 2001 From: Dave Bouwman Date: Fri, 16 Feb 2024 11:24:49 -0700 Subject: [PATCH] fix: checkPermission tolerates context without userHubSettings (#1416) --- packages/common/src/permissions/checkPermission.ts | 2 +- packages/common/test/permissions/checkPermission.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/common/src/permissions/checkPermission.ts b/packages/common/src/permissions/checkPermission.ts index f9416b22589..2ec9b08e6b2 100644 --- a/packages/common/src/permissions/checkPermission.ts +++ b/packages/common/src/permissions/checkPermission.ts @@ -108,7 +108,7 @@ export function checkPermission( // We also check the context.userHubSettings.preview array // which can also be used to enable features. - if (context.userHubSettings.preview) { + if (context.userHubSettings?.preview) { const preview = getWithDefault( context, "userHubSettings.preview", diff --git a/packages/common/test/permissions/checkPermission.test.ts b/packages/common/test/permissions/checkPermission.test.ts index 9950eb579ab..e8c6955487d 100644 --- a/packages/common/test/permissions/checkPermission.test.ts +++ b/packages/common/test/permissions/checkPermission.test.ts @@ -418,5 +418,11 @@ describe("checkPermission:", () => { expect(chk.access).toBe(true); }); + it("tolerates context without userHubSettings", () => { + const localCtx = cloneObject(premiumCtxMgr.context); + delete localCtx.userHubSettings; + const chk = checkPermission("hub:feature:workspace", localCtx); + expect(chk.access).toBe(false); + }); }); });