Skip to content

Commit

Permalink
Add delegate to reject agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrotaje committed Nov 6, 2024
1 parent ab36714 commit f02882f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ export const assertRequesterIsConsumerOrProducerOrDelegate = async (
}
};

export const assertRequesterIsProducerOrDelegate = (
agreement: Agreement,
delegateIdActiveDelegation: TenantId | undefined,
authData: AuthData
): void => {
if (delegateIdActiveDelegation) {
assertRequesterIsDelegate(delegateIdActiveDelegation, authData);
} else {
assertRequesterIsProducer(agreement, authData);
}
};

export const assertRequesterIsDelegate = (
delegateId: TenantId | undefined,
authData: AuthData
Expand Down
15 changes: 12 additions & 3 deletions packages/agreement-process/src/services/agreementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import {
assertRequesterIsConsumer,
assertRequesterIsConsumerOrProducer,
assertRequesterIsConsumerOrProducerOrDelegate,
assertRequesterIsProducer,
assertRequesterIsProducerOrDelegate,
assertSubmittableState,
failOnActivationFailure,
matchingCertifiedAttributes,
Expand Down Expand Up @@ -893,8 +893,17 @@ export function agreementServiceBuilder(
agreementId,
readModelService
);
const activeDelegation = await retrieveActiveDelegationByEserviceId(
agreementToBeRejected.data.eserviceId,
readModelService
);
const delegateId = activeDelegation?.data.delegateId;

assertRequesterIsProducer(agreementToBeRejected.data, authData);
assertRequesterIsProducerOrDelegate(
agreementToBeRejected.data,
delegateId,
authData
);

assertExpectedState(
agreementId,
Expand Down Expand Up @@ -933,7 +942,7 @@ export function agreementServiceBuilder(
suspendedByPlatform: undefined,
stamps: {
...agreementToBeRejected.data.stamps,
rejection: createStamp(authData.userId),
rejection: createStamp(authData.userId, delegateId),
},
};

Expand Down

0 comments on commit f02882f

Please sign in to comment.