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 5687: Verify tenant certified attributes for agreement creation #1224

Merged
merged 65 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
731d361
added rout to bff api
AsterITA Nov 15, 2024
d31aafb
small refactor of AgreementRouter
AsterITA Nov 18, 2024
682c63d
implement route bff
AsterITA Nov 18, 2024
e8d5fbd
initial process implementation
AsterITA Nov 18, 2024
72f403c
implementation process
AsterITA Nov 18, 2024
79354f5
fix logic
AsterITA Nov 22, 2024
de55991
add tests
AsterITA Nov 22, 2024
ca17431
Merge remote-tracking branch 'origin/feature/incaricato' into PIN-568…
AsterITA Nov 22, 2024
e384d14
initial implementation
AsterITA Nov 26, 2024
aae2867
process implementation
AsterITA Nov 27, 2024
e5b53b6
fix tests
AsterITA Nov 27, 2024
0944d2f
better initial logging
AsterITA Nov 27, 2024
e07e51d
implement tests
AsterITA Nov 27, 2024
9b25af4
fix test
AsterITA Nov 27, 2024
c78e9bb
revert bffapi
AsterITA Nov 27, 2024
e800186
Revert "revert bffapi"
AsterITA Nov 28, 2024
be40348
Apply suggestions from code review
AsterITA Nov 28, 2024
bdf91d2
fix lint
AsterITA Nov 28, 2024
dac9d9e
Revert "small refactor of AgreementRouter"
AsterITA Nov 28, 2024
bea6c4c
added collections
AsterITA Nov 28, 2024
109f54d
fix getConsumerLogic
AsterITA Nov 29, 2024
655ad58
fix test
AsterITA Nov 29, 2024
02e3420
deleted unused error
AsterITA Nov 29, 2024
104b5b0
Apply suggestions from code review
AsterITA Nov 29, 2024
bfd64d5
Merge branch 'feature/incaricato' into PIN-5607_DelegatedConsumerAgre…
AsterITA Nov 29, 2024
d618648
removed delegationId from body
AsterITA Nov 29, 2024
5b5ece5
Merge branch 'PIN-5607_DelegatedConsumerAgreementCreation' into PIN-5…
AsterITA Nov 29, 2024
357575c
refactored route
AsterITA Nov 29, 2024
d080063
fixed errorMapper
AsterITA Nov 29, 2024
43d3554
fix tests
AsterITA Dec 2, 2024
42d8fbc
fix ids
AsterITA Dec 2, 2024
0ba673c
added check for valid delegation
AsterITA Dec 2, 2024
dd40fc0
fix checks
AsterITA Dec 2, 2024
f9d17be
fix collection
AsterITA Dec 2, 2024
b5b2785
removed 409 since it wasn't returned
AsterITA Dec 2, 2024
5ecd6ef
Update packages/agreement-process/src/routers/AgreementRouter.ts
AsterITA Dec 3, 2024
35ca43f
Merge branch 'feature/incaricato' into PIN-5607_DelegatedConsumerAgre…
AsterITA Dec 4, 2024
78416f9
Apply suggestions from code review
AsterITA Dec 4, 2024
ad12ba0
small refactor on validators
AsterITA Dec 4, 2024
45fd12a
removed unused error
AsterITA Dec 4, 2024
3928289
added comments
AsterITA Dec 4, 2024
7301972
Merge branch 'PIN-5607_DelegatedConsumerAgreementCreation' into PIN-5…
AsterITA Dec 4, 2024
aad6f04
replace operationForbidden with operationNotAllowed
AsterITA Dec 4, 2024
ac02969
simplified checks on route
AsterITA Dec 4, 2024
e1c8fa0
rename const
AsterITA Dec 4, 2024
b29dcd8
small fix
AsterITA Dec 4, 2024
b7eb636
removed unused get from readModel
AsterITA Dec 4, 2024
6e5024b
refactor getDelegation on readModelService
AsterITA Dec 4, 2024
d78f615
updated assert name as suggested
AsterITA Dec 4, 2024
405efba
fix lint
AsterITA Dec 4, 2024
354a21c
Apply suggestions from code review
AsterITA Dec 4, 2024
f653ea8
revert authData in asserts
AsterITA Dec 4, 2024
1db7e6e
fixed check hasDelegation and replaced error
AsterITA Dec 4, 2024
8156fe5
Merge branch 'PIN-5607_DelegatedConsumerAgreementCreation' of https:/…
AsterITA Dec 4, 2024
3734d3a
fix lint
AsterITA Dec 4, 2024
faf637d
fix test description
AsterITA Dec 4, 2024
617c558
fix consumerId in created agreement
AsterITA Dec 4, 2024
1b7825e
Update packages/agreement-process/src/model/domain/agreement-validato…
AsterITA Dec 4, 2024
f33358c
Merge branch 'feature/incaricato' into PIN-5607_DelegatedConsumerAgre…
AsterITA Dec 4, 2024
09a0f90
Merge branch 'PIN-5607_DelegatedConsumerAgreementCreation' into PIN-5…
AsterITA Dec 5, 2024
8dfaf2a
align queries with readModel refactor
AsterITA Dec 5, 2024
0bef0f7
made query suitable for both kinds
AsterITA Dec 5, 2024
26df232
Revert "made query suitable for both kinds"
AsterITA Dec 5, 2024
436ec8b
revert query changes
AsterITA Dec 5, 2024
f0306c4
Merge branch 'feature/incaricato' into PIN-5687_agreementsVerify
AsterITA Dec 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
EServiceId,
unsafeBrandId,
TenantId,
Delegation,
delegationState,
} from "pagopa-interop-models";
import { agreementApi } from "pagopa-interop-api-clients";
import { AuthData } from "pagopa-interop-commons";
Expand All @@ -29,12 +31,15 @@ import {
agreementAlreadyExists,
agreementNotInExpectedState,
agreementSubmissionFailed,
delegationNotActive,
descriptorNotFound,
descriptorNotInExpectedState,
documentChangeNotAllowed,
missingCertifiedAttributesError,
notLatestEServiceDescriptor,
operationNotAllowed,
operationRestrictedToDelegate,
tenantIsNotRequester,
} from "./errors.js";
import {
CertifiedAgreementAttribute,
Expand Down Expand Up @@ -189,6 +194,30 @@ export const assertActivableState = (agreement: Agreement): void => {
}
};

export const assertIsDelegate = (
delegation: Delegation,
delegateId: TenantId
): void => {
if (delegation.delegateId !== delegateId) {
throw operationRestrictedToDelegate(delegateId, delegation.id);
}
};

export const assertDelegationIsActive = (delegation: Delegation): void => {
if (delegation.state !== delegationState.active) {
throw delegationNotActive(delegation.id);
}
};

export const assertTenantIsRequester = (
organizationId: TenantId,
tenantId: TenantId
): void => {
if (organizationId !== tenantId) {
throw tenantIsNotRequester(organizationId, tenantId);
}
};

/* ========= VALIDATIONS ========= */

const validateDescriptorState = (
Expand Down
44 changes: 44 additions & 0 deletions packages/agreement-process/src/model/domain/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const errorCodes = {
consumerWithNotValidEmail: "0024",
agreementDocumentAlreadyExists: "0025",
userNotFound: "0026",
delegationNotFound: "0027",
operationRestrictedToDelegate: "0028",
delegationNotActive: "0029",
tenantIsNotRequester: "0030",
};

export type ErrorCodes = keyof typeof errorCodes;
Expand Down Expand Up @@ -308,3 +312,43 @@ export function attributeNotFound(
title: "Attribute not found",
});
}

export function delegationNotFound(delegationId: string): ApiError<ErrorCodes> {
return new ApiError({
detail: `Delegation ${delegationId} not found`,
code: "delegationNotFound",
title: "Delegation not found",
});
}

export function operationRestrictedToDelegate(
tenantId: string,
delegationId: string
): ApiError<ErrorCodes> {
return new ApiError({
detail: `Tenant ${tenantId} is not a delegate for delegation ${delegationId}`,
code: "operationRestrictedToDelegate",
title: "Operation restricted to delegate",
});
}

export function delegationNotActive(
delegationId: string
): ApiError<ErrorCodes> {
return new ApiError({
detail: `Delegation ${delegationId} is not active`,
code: "delegationNotActive",
title: "Delegation not active",
});
}

export function tenantIsNotRequester(
organizationId: string,
tenantId: string
): ApiError<ErrorCodes> {
return new ApiError({
detail: `Requester ${organizationId} is not the same as tenant ${tenantId}`,
code: "tenantIsNotRequester",
title: "Tenant is not requester",
});
}
Loading