diff --git a/keyserver/src/fetchers/policy-acknowledgment-fetchers.js b/keyserver/src/fetchers/policy-acknowledgment-fetchers.js --- a/keyserver/src/fetchers/policy-acknowledgment-fetchers.js +++ b/keyserver/src/fetchers/policy-acknowledgment-fetchers.js @@ -20,4 +20,20 @@ return data; } -export { fetchPolicyAcknowledgments }; +async function fetchNotAcknowledgedPolicies( + viewer: Viewer, + policies: $ReadOnlyArray, +): Promise<$ReadOnlyArray> { + const viewerAcknowledgments = await fetchPolicyAcknowledgments( + viewer, + policies, + ); + return policies.filter(policy => { + const policyAcknowledgment = viewerAcknowledgments.find( + viewerAcknowledgment => viewerAcknowledgment.policy === policy, + ); + return !policyAcknowledgment?.confirmed; + }); +} + +export { fetchPolicyAcknowledgments, fetchNotAcknowledgedPolicies }; diff --git a/keyserver/src/utils/validation-utils.js b/keyserver/src/utils/validation-utils.js --- a/keyserver/src/utils/validation-utils.js +++ b/keyserver/src/utils/validation-utils.js @@ -10,7 +10,7 @@ tPlatformDetails, } from 'lib/utils/validation-utils'; -import { fetchPolicyAcknowledgments } from '../fetchers/policy-acknowledgment-fetchers.js'; +import { fetchNotAcknowledgedPolicies } from '../fetchers/policy-acknowledgment-fetchers.js'; import { verifyClientSupported } from '../session/version'; import type { Viewer } from '../session/viewer'; @@ -167,16 +167,10 @@ return; } - const viewerAcknowledgments = await fetchPolicyAcknowledgments( + const notAcknowledgedPolicies = await fetchNotAcknowledgedPolicies( viewer, policies, ); - const notAcknowledgedPolicies = policies.filter(policy => { - const policyAcknowledgment = viewerAcknowledgments.find( - viewerAcknowledgment => viewerAcknowledgment.policy === policy, - ); - return !policyAcknowledgment?.confirmed; - }); if (notAcknowledgedPolicies.length) { throw new ServerError('policies_not_accepted', {