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-5443 - Updated publish descriptor and added approve delegated descriptor #1113

Open
wants to merge 19 commits into
base: pin-5459_add-new-eservice-state-and-events
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1f4b2e8
Update catalogApi.yml
Carminepo2 Oct 16, 2024
83df4f9
Merge branch 'pin-5442_update-e-service-calls-check' into pin-5443_ap…
Carminepo2 Oct 16, 2024
1eac9c7
WIP add new approve path in catalog process
Carminepo2 Oct 16, 2024
3611850
Merge branch 'pin-5459_add-new-eservice-state-and-events' into pin-54…
Carminepo2 Oct 16, 2024
a7f9019
Update catalogService.ts
Carminepo2 Oct 17, 2024
d4759f6
Merge branch 'pin-5459_add-new-eservice-state-and-events' into pin-54…
Carminepo2 Oct 17, 2024
dced145
Merge branch 'pin-5459_add-new-eservice-state-and-events' into pin-54…
Carminepo2 Oct 17, 2024
70fdb3b
Updated publishDescriptor and approveDescriptor logic
Carminepo2 Oct 17, 2024
a9ee25d
Merge branch 'pin-5459_add-new-eservice-state-and-events' into pin-54…
Carminepo2 Oct 17, 2024
ab93062
Merge branch 'pin-5459_add-new-eservice-state-and-events' into pin-54…
Carminepo2 Oct 17, 2024
ffc1d22
Updated logic
Carminepo2 Oct 17, 2024
b1a7676
Updated tests
Carminepo2 Oct 17, 2024
467c96c
Added bff route
Carminepo2 Oct 17, 2024
47faab7
Merge branch 'pin-5459_add-new-eservice-state-and-events' into pin-54…
Carminepo2 Oct 17, 2024
ed1c4a3
Merge branch 'pin-5459_add-new-eservice-state-and-events' into pin-54…
Carminepo2 Oct 18, 2024
b4b454c
Merge branch 'pin-5459_add-new-eservice-state-and-events' into pin-54…
Carminepo2 Oct 18, 2024
9d786d1
Merge branch 'pin-5459_add-new-eservice-state-and-events' into pin-54…
Carminepo2 Oct 18, 2024
effdbbc
Update tests
Carminepo2 Oct 18, 2024
2361d3e
Merge branch 'pin-5443_approve-delegated-descriptor' of https://githu…
Carminepo2 Oct 18, 2024
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
7 changes: 5 additions & 2 deletions packages/agreement-process/test/createAgreement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ describe("create agreement", () => {
const authData = getRandomAuthData();
const eserviceId = generateId<EServiceId>();
const notDraftDescriptorStates = Object.values(descriptorState).filter(
(state) => state !== descriptorState.draft
(state) =>
state !== descriptorState.draft &&
state !== descriptorState.waitingForApproval
);

const descriptor0: Descriptor = {
Expand Down Expand Up @@ -444,7 +446,8 @@ describe("create agreement", () => {
Object.values(descriptorState).filter(
(state) =>
state !== descriptorState.published &&
state !== descriptorState.draft
state !== descriptorState.draft &&
state !== descriptorState.waitingForApproval
)
),
};
Expand Down
12 changes: 9 additions & 3 deletions packages/agreement-process/test/submitAgreement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,9 @@ describe("submit agreement", () => {
id: descriptorId,
state: randomArrayItem(
Object.values(descriptorState).filter(
(state: DescriptorState) => state !== descriptorState.draft
(state: DescriptorState) =>
state !== descriptorState.draft &&
state !== descriptorState.waitingForApproval
)
),
version: "1",
Expand All @@ -542,7 +544,9 @@ describe("submit agreement", () => {
...getMockDescriptor(),
state: randomArrayItem(
Object.values(descriptorState).filter(
(state: DescriptorState) => state !== descriptorState.draft
(state: DescriptorState) =>
state !== descriptorState.draft &&
state !== descriptorState.waitingForApproval
)
),
version: "2",
Expand Down Expand Up @@ -602,7 +606,9 @@ describe("submit agreement", () => {
state: randomArrayItem(
Object.values(descriptorState).filter(
(state: DescriptorState) =>
!allowedStatus.includes(state) && state !== descriptorState.draft
!allowedStatus.includes(state) &&
state !== descriptorState.draft &&
state !== descriptorState.waitingForApproval
)
),
};
Expand Down
102 changes: 102 additions & 0 deletions packages/api-clients/open-api/bffApi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3885,6 +3885,108 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Problem"
/eservices/{eServiceId}/descriptors/{descriptorId}/approve:
parameters:
- $ref: "#/components/parameters/CorrelationIdHeader"
post:
security:
- bearerAuth: []
tags:
- eservices
summary: approve a delegated new e-service version
operationId: approveDelegatedEServiceDescriptor
parameters:
- name: eServiceId
in: path
description: the eservice id
required: true
schema:
type: string
format: uuid
- name: descriptorId
in: path
description: the descriptor id
required: true
schema:
type: string
format: uuid
responses:
"204":
description: New delegated e-service version approved
headers:
"X-Rate-Limit-Limit":
schema:
type: integer
description: Max allowed requests within time interval
"X-Rate-Limit-Remaining":
schema:
type: integer
description: Remaining requests within time interval
"X-Rate-Limit-Interval":
schema:
type: integer
description: Time interval in milliseconds. Allowed requests will be constantly replenished during the interval. At the end of the interval the max allowed requests will be available
content:
application/json:
schema:
$ref: "#/components/schemas/CreatedResource"
"403":
description: Forbidden
headers:
"X-Rate-Limit-Limit":
schema:
type: integer
description: Max allowed requests within time interval
"X-Rate-Limit-Remaining":
schema:
type: integer
description: Remaining requests within time interval
"X-Rate-Limit-Interval":
schema:
type: integer
description: Time interval in milliseconds. Allowed requests will be constantly replenished during the interval. At the end of the interval the max allowed requests will be available
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
"404":
description: EService or Descriptor not found
headers:
"X-Rate-Limit-Limit":
schema:
type: integer
description: Max allowed requests within time interval
"X-Rate-Limit-Remaining":
schema:
type: integer
description: Remaining requests within time interval
"X-Rate-Limit-Interval":
schema:
type: integer
description: Time interval in milliseconds. Allowed requests will be constantly replenished during the interval. At the end of the interval the max allowed requests will be available
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
"400":
description: Bad request
headers:
"X-Rate-Limit-Limit":
schema:
type: integer
description: Max allowed requests within time interval
"X-Rate-Limit-Remaining":
schema:
type: integer
description: Remaining requests within time interval
"X-Rate-Limit-Interval":
schema:
type: integer
description: Time interval in milliseconds. Allowed requests will be constantly replenished during the interval. At the end of the interval the max allowed requests will be available
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
/export/eservices/{eserviceId}/descriptors/{descriptorId}:
parameters:
- $ref: "#/components/parameters/CorrelationIdHeader"
Expand Down
46 changes: 46 additions & 0 deletions packages/api-clients/open-api/catalogApi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,52 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Problem"
/eservices/:eServiceId/descriptors/:descriptorId/approve:
parameters:
- $ref: "#/components/parameters/CorrelationIdHeader"
post:
security:
- bearerAuth: []
tags:
- process
summary: approve a delegated new e-service version
operationId: approveDelegatedEServiceDescriptor
parameters:
- name: eServiceId
in: path
description: the eservice id
required: true
schema:
type: string
format: uuid
- name: descriptorId
in: path
description: the descriptor id
required: true
schema:
type: string
format: uuid
responses:
"204":
description: New delegated e-service version approved
"403":
description: Forbidden
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
"404":
description: EService not found
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
"400":
description: Bad request
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
/status:
get:
security: []
Expand Down
24 changes: 23 additions & 1 deletion packages/backend-for-frontend/src/routers/catalogRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,29 @@ const catalogRouter = (
);
return res.status(errorRes.status).send(errorRes);
}
});
})
.post(
"/eservices/:eServiceId/descriptors/:descriptorId/approve",
async (req, res) => {
const ctx = fromBffAppContext(req.ctx, req.headers);
try {
await catalogService.approveDelegatedEServiceDescriptor(
unsafeBrandId(req.params.eServiceId),
unsafeBrandId(req.params.descriptorId),
ctx
);
return res.status(204).send();
} catch (error) {
const errorRes = makeApiProblem(
error,
emptyErrorMapper,
ctx.logger,
`Error approving eService ${req.params.eServiceId} version ${req.params.descriptorId}`
);
return res.status(errorRes.status).send(errorRes);
}
}
);

return catalogRouter;
};
Expand Down
14 changes: 14 additions & 0 deletions packages/backend-for-frontend/src/services/catalogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1200,5 +1200,19 @@ export function catalogServiceBuilder(
descriptorId: eservice.descriptors[0].id,
};
},
approveDelegatedEServiceDescriptor: async (
eServiceId: EServiceId,
descriptorId: EServiceId,
{ headers, logger }: WithLogger<BffAppContext>
): Promise<void> => {
logger.info(`Approving e-service ${eServiceId} version ${descriptorId}`);
await catalogProcessClient.approveDelegatedEServiceDescriptor(undefined, {
headers,
params: {
eServiceId,
descriptorId,
},
});
},
};
}
38 changes: 38 additions & 0 deletions packages/catalog-process/src/model/domain/toEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,41 @@ export const toCreateEventEServiceDescriptionUpdated = (
},
correlationId,
});

export const toCreateEventEServiceDescriptorDelegateSubmitted = (
version: number,
descriptorId: DescriptorId,
eservice: EService,
correlationId: string
): CreateEvent<EServiceEvent> => ({
streamId: eservice.id,
version,
event: {
type: "EServiceDescriptorDelegateSubmitted",
event_version: 2,
data: {
descriptorId,
eservice: toEServiceV2(eservice),
},
},
correlationId,
});

export const toCreateEventEServiceDescriptorDelegatorApproved = (
version: number,
descriptorId: DescriptorId,
eservice: EService,
correlationId: string
): CreateEvent<EServiceEvent> => ({
streamId: eservice.id,
version,
event: {
type: "EServiceDescriptorDelegatorApproved",
event_version: 2,
data: {
descriptorId,
eservice: toEServiceV2(eservice),
},
},
correlationId,
});
24 changes: 24 additions & 0 deletions packages/catalog-process/src/routers/EServiceRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
updateEServiceDescriptionErrorMapper,
updateEServiceErrorMapper,
updateRiskAnalysisErrorMapper,
approveDelegatedEServiceDescriptorErrorMapper,
} from "../utilities/errorMappers.js";

const readModelService = readModelServiceBuilder(
Expand Down Expand Up @@ -687,6 +688,29 @@ const eservicesRouter = (
return res.status(errorRes.status).send(errorRes);
}
}
)
.post(
"/eservices/:eServiceId/descriptors/:descriptorId/approve",
authorizationMiddleware([ADMIN_ROLE]),
async (req, res) => {
const ctx = fromAppContext(req.ctx);

try {
await catalogService.approveDelegatedEServiceDescriptor(
unsafeBrandId(req.params.eServiceId),
unsafeBrandId(req.params.descriptorId),
ctx
);
return res.status(204).send();
} catch (error) {
const errorRes = makeApiProblem(
error,
approveDelegatedEServiceDescriptorErrorMapper,
ctx.logger
);
return res.status(errorRes.status).send(errorRes);
}
}
);
return eservicesRouter;
};
Expand Down
Loading