Skip to content

Commit

Permalink
add attribute check on delegate and delegator
Browse files Browse the repository at this point in the history
  • Loading branch information
MalpenZibo committed Nov 12, 2024
1 parent 7ad1b78 commit 3a5b6e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 7 additions & 3 deletions packages/backend-for-frontend/src/api/catalogApiConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function toBffCatalogDescriptorEService(
descriptor: catalogApi.EServiceDescriptor,
producerTenant: tenantApi.Tenant,
agreement: agreementApi.Agreement | undefined,
requesterTenant: tenantApi.Tenant
requesterTenants: tenantApi.Tenant[]
): bffApi.CatalogDescriptorEService {
const activeDescriptor = getLatestActiveDescriptor(eservice);
return {
Expand All @@ -107,8 +107,12 @@ export function toBffCatalogDescriptorEService(
technology: eservice.technology,
descriptors: getNotDraftDescriptor(eservice).map(toCompactDescriptor),
agreement: agreement && toBffCompactAgreement(agreement, eservice),
isMine: isRequesterEserviceProducer(requesterTenant.id, eservice),
hasCertifiedAttributes: hasCertifiedAttributes(descriptor, requesterTenant),
isMine: requesterTenants.some((t) =>
isRequesterEserviceProducer(t.id, eservice)
),
hasCertifiedAttributes: requesterTenants.some((t) =>
hasCertifiedAttributes(descriptor, t)
),
isSubscribed: isAgreementSubscribed(agreement),
activeDescriptor: activeDescriptor
? toCompactDescriptor(activeDescriptor)
Expand Down
22 changes: 15 additions & 7 deletions packages/backend-for-frontend/src/services/catalogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ import {
assertNotDelegatedEservice,
assertRequesterIsProducer,
} from "./validators.js";
import {
getAllDelegations,
getTenantsFromDelegation,
} from "./delegationService.js";

export type CatalogService = ReturnType<typeof catalogServiceBuilder>;

Expand Down Expand Up @@ -528,12 +532,16 @@ export function catalogServiceBuilder(
descriptor
);

const requesterTenant = await tenantProcessClient.tenant.getTenant({
headers,
params: {
id: requesterId,
},
});
const requesterTenants = await getTenantsFromDelegation(
tenantProcessClient,
await getAllDelegations(delegationProcessClient, headers, {
delegateIds: [requesterId],
delegationStates: ["ACTIVE"],
kind: "DELEGATED_CONSUMER",
eserviceIds: [eserviceId],
}),
headers
);
const producerTenant = await tenantProcessClient.tenant.getTenant({
headers,
params: {
Expand Down Expand Up @@ -571,7 +579,7 @@ export function catalogServiceBuilder(
descriptor,
producerTenant,
agreement,
requesterTenant
Array.from(requesterTenants, ([, tenant]) => tenant)
),
};
},
Expand Down

0 comments on commit 3a5b6e1

Please sign in to comment.