Skip to content
This repository was archived by the owner on Oct 14, 2026. It is now read-only.

Commit 35cbe33

Browse files
Ravi VermaCopilot
andcommitted
refactor(http-utils): simplify FACS state-grant union for full branch coverage
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 829b21b commit 35cbe33

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

‎packages/spacecat-shared-http-utils/src/auth/facs-wrapper.js‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -836,18 +836,13 @@ export function facsWrapper(fn, {
836836
})
837837
: Promise.resolve([]),
838838
]);
839-
const groupMappingsList = Array.isArray(groupMappings) ? groupMappings : [];
840-
stateGrants = [
841-
...(userMapping?.granted_capabilities || []),
842-
...(orgMapping?.granted_capabilities || []),
843-
...groupMappingsList.flatMap((mapping) => mapping?.granted_capabilities || []),
844-
];
839+
const capsOf = (mapping) => mapping?.granted_capabilities || [];
840+
const groupCaps = groupMappings.flatMap(capsOf);
841+
stateGrants = [...capsOf(userMapping), ...capsOf(orgMapping), ...groupCaps];
845842
grantSources = [
846-
...(userMapping?.granted_capabilities?.includes(routeCapability) ? ['user'] : []),
847-
...(orgMapping?.granted_capabilities?.includes(routeCapability) ? ['org'] : []),
848-
...(groupMappingsList.some(
849-
(mapping) => mapping?.granted_capabilities?.includes(routeCapability),
850-
) ? ['group'] : []),
843+
...(capsOf(userMapping).includes(routeCapability) ? ['user'] : []),
844+
...(capsOf(orgMapping).includes(routeCapability) ? ['org'] : []),
845+
...(groupCaps.includes(routeCapability) ? ['group'] : []),
851846
];
852847
} catch (e) {
853848
// Fail closed on state-layer read errors.

0 commit comments

Comments
 (0)