Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIN 5558 - Get eservice descriptor #1218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/api-clients/open-api/bffApi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13172,6 +13172,11 @@ components:
type: boolean
hasCertifiedAttributes:
type: boolean
description: >
True in case:
- the requester has the certified attributes required to consume the eservice, or
- the requester is the delegated consumer for the eservice and
the delegator has the certified attributes required to consume the eservice
isSubscribed:
type: boolean
activeDescriptor:
Expand Down
11 changes: 9 additions & 2 deletions packages/backend-for-frontend/src/api/catalogApiConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export function toBffCatalogDescriptorEService(
descriptor: catalogApi.EServiceDescriptor,
producerTenant: tenantApi.Tenant,
agreement: agreementApi.Agreement | undefined,
requesterTenant: tenantApi.Tenant
requesterTenant: tenantApi.Tenant,
consumerDelegators: tenantApi.Tenant[]
): bffApi.CatalogDescriptorEService {
const activeDescriptor = getLatestActiveDescriptor(eservice);
return {
Expand All @@ -108,7 +109,13 @@ export function toBffCatalogDescriptorEService(
descriptors: getNotDraftDescriptor(eservice).map(toCompactDescriptor),
agreement: agreement && toBffCompactAgreement(agreement, eservice),
isMine: isRequesterEserviceProducer(requesterTenant.id, eservice),
hasCertifiedAttributes: hasCertifiedAttributes(descriptor, requesterTenant),
hasCertifiedAttributes: [requesterTenant, ...consumerDelegators].some(
(t) => hasCertifiedAttributes(descriptor, t)
/* True in case:
- the requester has the certified attributes required to consume the eservice, or
- the requester is the delegated consumer for the eservice and
the delegator has the certified attributes required to consume the eservice */
),
isSubscribed: isAgreementSubscribed(agreement),
activeDescriptor: activeDescriptor
? toCompactDescriptor(activeDescriptor)
Expand Down
35 changes: 33 additions & 2 deletions packages/backend-for-frontend/src/services/catalogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
/* eslint-disable functional/immutable-data */
import { randomUUID } from "crypto";
import AdmZip from "adm-zip";
import { bffApi, catalogApi, tenantApi } from "pagopa-interop-api-clients";
import {
bffApi,
catalogApi,
delegationApi,
tenantApi,
} from "pagopa-interop-api-clients";
import {
FileManager,
WithLogger,
Expand All @@ -26,6 +31,7 @@ import {
invalidZipStructure,
missingDescriptorInClonedEservice,
noDescriptorInEservice,
tenantNotFound,
} from "../model/errors.js";
import { getLatestActiveDescriptor } from "../model/modelMappingUtils.js";
import {
Expand Down Expand Up @@ -62,6 +68,10 @@ import {
assertNotDelegatedEservice,
assertRequesterIsProducer,
} from "./validators.js";
import {
getAllDelegations,
getTenantsFromDelegation,
} from "./delegationService.js";

export type CatalogService = ReturnType<typeof catalogServiceBuilder>;

Expand Down Expand Up @@ -534,6 +544,26 @@ export function catalogServiceBuilder(
id: requesterId,
},
});
if (!requesterTenant) {
throw tenantNotFound(requesterId);
}

const delegationTenantsSet = await getTenantsFromDelegation(
tenantProcessClient,
await getAllDelegations(delegationProcessClient, headers, {
delegateIds: [requesterId],
delegationStates: [delegationApi.DelegationState.Values.ACTIVE],
kind: delegationApi.DelegationKind.Values.DELEGATED_CONSUMER,
eserviceIds: [eserviceId],
}),
headers
);

const delegationTenants = Array.from(delegationTenantsSet.values());
const consumerDelegators = delegationTenants.filter(
(t) => t.id !== requesterId
);

const producerTenant = await tenantProcessClient.tenant.getTenant({
headers,
params: {
Expand Down Expand Up @@ -571,7 +601,8 @@ export function catalogServiceBuilder(
descriptor,
producerTenant,
agreement,
requesterTenant
requesterTenant,
consumerDelegators
),
};
},
Expand Down