Skip to content

Commit

Permalink
Verify and revoke verified attribute service fixes (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carminepo2 authored Oct 7, 2024
1 parent c25f9f0 commit 18e20ae
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/agreement-process/src/model/domain/apiConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function fromApiTenantVerifier(
verifier: agreementApi.TenantVerifier
): TenantVerifier {
return {
id: verifier.id,
id: unsafeBrandId(verifier.id),
verificationDate: new Date(verifier.verificationDate),
expirationDate: verifier.expirationDate
? new Date(verifier.expirationDate)
Expand All @@ -115,7 +115,7 @@ function fromApiTenantRevoker(
revoker: agreementApi.TenantRevoker
): TenantRevoker {
return {
id: revoker.id,
id: unsafeBrandId(revoker.id),
verificationDate: new Date(revoker.verificationDate),
expirationDate: revoker.expirationDate
? new Date(revoker.expirationDate)
Expand Down
4 changes: 2 additions & 2 deletions packages/backend-for-frontend/src/api/tenantApiConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export function toTenantAttribute(
type: tenantAttributeType.VERIFIED,
assignmentTimestamp: new Date(att.verified.assignmentTimestamp),
verifiedBy: att.verified.verifiedBy.map((v) => ({
id: v.id,
id: unsafeBrandId(v.id),
verificationDate: new Date(v.verificationDate),
expirationDate: v.expirationDate ? new Date(v.expirationDate) : undefined,
extensionDate: v.extensionDate ? new Date(v.extensionDate) : undefined,
})),
revokedBy: att.verified.revokedBy.map((r) => ({
id: r.id,
id: unsafeBrandId(r.id),
verificationDate: new Date(r.verificationDate),
revocationDate: new Date(r.revocationDate),
expirationDate: r.expirationDate ? new Date(r.expirationDate) : undefined,
Expand Down
2 changes: 2 additions & 0 deletions packages/models/src/tenant/protobufConverterFromV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ export const fromTenantVerifierV1 = (
input: TenantVerifierV1
): TenantVerifier => ({
...input,
id: unsafeBrandId(input.id),
verificationDate: bigIntToDate(input.verificationDate),
expirationDate: bigIntToDate(input.expirationDate),
extensionDate: bigIntToDate(input.extensionDate),
});

export const fromTenantRevokerV1 = (input: TenantRevokerV1): TenantRevoker => ({
...input,
id: unsafeBrandId(input.id),
expirationDate: bigIntToDate(input.expirationDate),
extensionDate: bigIntToDate(input.extensionDate),
revocationDate: bigIntToDate(input.revocationDate),
Expand Down
2 changes: 2 additions & 0 deletions packages/models/src/tenant/protobufConverterFromV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ export const fromTenantVerifierV2 = (
input: TenantVerifierV2
): TenantVerifier => ({
...input,
id: unsafeBrandId(input.id),
verificationDate: bigIntToDate(input.verificationDate),
expirationDate: bigIntToDate(input.expirationDate),
extensionDate: bigIntToDate(input.extensionDate),
});

export const fromTenantRevokerV2 = (input: TenantRevokerV2): TenantRevoker => ({
...input,
id: unsafeBrandId(input.id),
expirationDate: bigIntToDate(input.expirationDate),
extensionDate: bigIntToDate(input.extensionDate),
revocationDate: bigIntToDate(input.revocationDate),
Expand Down
4 changes: 2 additions & 2 deletions packages/models/src/tenant/tenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const TenantAttributeType = z.enum([
export type TenantAttributeType = z.infer<typeof TenantAttributeType>;

export const TenantVerifier = z.object({
id: z.string(),
id: TenantId,
verificationDate: z.coerce.date(),
expirationDate: z.coerce.date().optional(),
extensionDate: z.coerce.date().optional(),
Expand All @@ -56,7 +56,7 @@ export type TenantVerifier = z.infer<typeof TenantVerifier>;
export const TenantRevoker = z.object({
expirationDate: z.coerce.date().optional(),
extensionDate: z.coerce.date().optional(),
id: z.string().uuid(),
id: TenantId,
revocationDate: z.coerce.date(),
verificationDate: z.coerce.date(),
});
Expand Down
26 changes: 13 additions & 13 deletions packages/tenant-process/src/services/tenantService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,18 +778,6 @@ export function tenantServiceBuilder(
throw attributeNotFound(attributeId);
}

if (
verifiedTenantAttribute.revokedBy.some(
(a) => a.id === authData.organizationId
)
) {
throw attributeAlreadyRevoked(
tenantId,
authData.organizationId,
attributeId
);
}

const verifier = verifiedTenantAttribute.verifiedBy.find(
(a) => a.id === authData.organizationId
);
Expand All @@ -798,6 +786,18 @@ export function tenantServiceBuilder(
throw attributeRevocationNotAllowed(tenantId, attributeId);
}

const isInRevokedBy = verifiedTenantAttribute.revokedBy.some(
(a) => a.id === authData.organizationId
);

if (isInRevokedBy) {
throw attributeAlreadyRevoked(
tenantId,
authData.organizationId,
attributeId
);
}

const updatedTenant: Tenant = {
...targetTenant.data,
updatedAt: new Date(),
Expand Down Expand Up @@ -1726,7 +1726,7 @@ function reassignVerifiedAttribute(
tenantAttributeSeed.expirationDate
),
revokedBy: verifiedTenantAttribute.revokedBy.filter(
(i) => i.id !== attr.id
(i) => i.id !== organizationId
),
}
: attr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ describe("revokeVerifiedAttribute", async () => {
attributes: [
{
...verifiedAttribute,
verifiedBy: [{ ...getMockVerifiedBy() }],
verifiedBy: [{ ...getMockVerifiedBy(), id: revokerTenant.id }],
revokedBy: [{ ...getMockRevokedBy(), id: revokerTenant.id }],
},
],
Expand Down

0 comments on commit 18e20ae

Please sign in to comment.