From 67af26df03d3c9be9f85e98e8e18230446bde28f Mon Sep 17 00:00:00 2001 From: Sukeerth Vegaraju Date: Thu, 10 Mar 2022 20:53:30 -0800 Subject: [PATCH] fix: scopes should not be filtered in search use cases (#79) --- src/smartScopeHelper.test.ts | 14 ++++++++++++++ src/smartScopeHelper.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/smartScopeHelper.test.ts b/src/smartScopeHelper.test.ts index 0469b45..fe2f17a 100644 --- a/src/smartScopeHelper.test.ts +++ b/src/smartScopeHelper.test.ts @@ -395,6 +395,20 @@ describe('filterOutUnusableScope', () => { ), ).toEqual(['system/*.write']); }); + + test('do not filter patient scope out in type-search use case', () => { + const clonedScopeRule = emptyScopeRule(); + clonedScopeRule.system.read = ['search-type']; + expect( + filterOutUnusableScope( + ['system/DocumentReference.read', 'system/Patient.read'], + clonedScopeRule, + 'search-type', + false, + 'DocumentReference', + ), + ).toEqual(['system/DocumentReference.read', 'system/Patient.read']); + }); }); describe('getValidOperationsForScopeTypeAndAccessType', () => { diff --git a/src/smartScopeHelper.ts b/src/smartScopeHelper.ts index 2c47efa..ec4fcb9 100644 --- a/src/smartScopeHelper.ts +++ b/src/smartScopeHelper.ts @@ -55,7 +55,7 @@ function getValidOperationsForScope( let validOperations: (TypeOperation | SystemOperation)[] = []; const { scopeType, resourceType, accessType } = smartScope; if (reqResourceType) { - if (resourceType === '*' || resourceType === reqResourceType) { + if (resourceType === '*' || resourceType === reqResourceType || reqOperation === 'search-type') { validOperations = getValidOperationsForScopeTypeAndAccessType(scopeType, accessType, scopeRule); } }