Skip to content

Commit

Permalink
Fix risk analysis validation when delegator tenant kind is different …
Browse files Browse the repository at this point in the history
…from delegate's one (#1038)

* Fix risk analysis validation when delegator tenant kind is different from delegate's one

* Update eservice.mocks.ts
  • Loading branch information
Carminepo2 authored and ruggerocastagnola committed Dec 13, 2024
1 parent 2798cc0 commit c5362f0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions __mocks__/data/eservice.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ const createMockEServiceDescriptorProvider = createMockFactory<ProducerEServiceD
audience: [],
},
],
producer: {
id: '4edda5fd-2fed-485c-9ab4-bc7d78a67624',
tenantKind: 'PA',
},
id: '4edda5fd-2fed-485c-9ab4-bc7d78a67624',
name: '-- LUMACA -- test 20/10 [4]\t',
technology: 'REST',
Expand Down
15 changes: 14 additions & 1 deletion src/api/api.generatedTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ export interface ProducerDescriptorEService {
id: string
name: string
description: string
producer: ProducerDescriptorEServiceProducer
/** EService Descriptor State */
technology: EServiceTechnology
/** Risk Analysis Mode */
Expand All @@ -354,6 +355,12 @@ export interface ProducerDescriptorEService {
isSignalHubEnabled?: boolean
}

export interface ProducerDescriptorEServiceProducer {
/** @format uuid */
id: string
tenantKind?: TenantKind
}

export interface EServiceDoc {
/** @format uuid */
id: string
Expand Down Expand Up @@ -1832,6 +1839,10 @@ export interface GetClientKeysParams {
clientId: string
}

export interface RetrieveLatestRiskAnalysisConfigurationParams {
tenantKind?: TenantKind
}

export interface RetrieveRiskAnalysisConfigurationByVersionParams {
/** @format uuid */
eserviceId: string
Expand Down Expand Up @@ -4190,7 +4201,9 @@ export namespace Purposes {
*/
export namespace RetrieveLatestRiskAnalysisConfiguration {
export type RequestParams = {}
export type RequestQuery = {}
export type RequestQuery = {
tenantKind?: TenantKind
}
export type RequestBody = never
export type RequestHeaders = {
'X-Correlation-Id': string
Expand Down
5 changes: 3 additions & 2 deletions src/api/purpose/purpose.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PurposeServices } from './purpose.services'
import type {
GetConsumerPurposesParams,
GetProducerPurposesParams,
RetrieveLatestRiskAnalysisConfigurationParams,
RetrieveRiskAnalysisConfigurationByVersionParams,
} from '../api.generatedTypes'

Expand All @@ -27,10 +28,10 @@ function getSingle(purposeId: string) {
})
}

function getRiskAnalysisLatest() {
function getRiskAnalysisLatest(params?: RetrieveLatestRiskAnalysisConfigurationParams) {
return queryOptions({
queryKey: ['GetRiskAnalysisLatest'],
queryFn: () => PurposeServices.getRiskAnalysisLatest(),
queryFn: () => PurposeServices.getRiskAnalysisLatest(params),
})
}

Expand Down
6 changes: 4 additions & 2 deletions src/api/purpose/purpose.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
PurposeVersionResource,
PurposeVersionSeed,
RejectPurposeVersionPayload,
RetrieveLatestRiskAnalysisConfigurationParams,
RetrieveRiskAnalysisConfigurationByVersionParams,
ReversePurposeUpdateContent,
RiskAnalysisFormConfig,
Expand Down Expand Up @@ -68,9 +69,10 @@ async function getSingle(purposeId: string) {
return REMOVE_ME_remapPurpose(response.data)
}

async function getRiskAnalysisLatest() {
async function getRiskAnalysisLatest(params?: RetrieveLatestRiskAnalysisConfigurationParams) {
const response = await axiosInstance.get<RiskAnalysisFormConfig>(
`${BACKEND_FOR_FRONTEND_URL}/purposes/riskAnalysis/latest`
`${BACKEND_FOR_FRONTEND_URL}/purposes/riskAnalysis/latest`,
{ params }
)
return response.data
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ export const EServiceCreateStepPurposeRiskAnalysis: React.FC = () => {
const { mutate: addEServiceRiskAnalysis } = EServiceMutations.useAddEServiceRiskAnalysis()
const { mutate: updateEServiceRiskAnalysis } = EServiceMutations.useUpdateEServiceRiskAnalysis()

const { data: riskAnalysisLatest } = useQuery(PurposeQueries.getRiskAnalysisLatest())
const { data: riskAnalysisLatest } = useQuery(
PurposeQueries.getRiskAnalysisLatest({
/**
* We need to retrieve the risk analysis configuration for the tenant kind of the producer
* because the actual user might be a producer delegate with a different tenant kind.
*/
tenantKind: descriptor?.eservice.producer.tenantKind,
})
)

if (!riskAnalysisLatest || !descriptor) return <RiskAnalysisFormSkeleton />

Expand Down

0 comments on commit c5362f0

Please sign in to comment.