Skip to content

Commit

Permalink
0XP-1641: add imageOptions for other pipelines (#2179)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrliu authored Nov 27, 2024
1 parent 7e56c21 commit 529f041
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 19 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
BadgeConfig,
CONTACT_EVENT_NAME,
GenericIssuanceSendPipelineEmailResponseValue,
ImageOptions,
LemonadePipelineDefinition,
LemonadePipelineEventConfig,
LemonadePipelineTicketTypeConfig,
Expand Down Expand Up @@ -586,6 +587,40 @@ export class LemonadePipeline implements BasePipeline {
});
}

private imageOptionsToImageUrl(
imageOptions: ImageOptions | undefined,
isCheckedIn: boolean
): string | undefined {
if (!imageOptions) return undefined;
if (imageOptions.requireCheckedIn && !isCheckedIn) return undefined;
return imageOptions.imageUrl;
}

private atomToQrCodeOverrideImageUrl(
ticketAtom: LemonadeAtom
): string | undefined {
const event = this.lemonadeAtomToEvent(ticketAtom);
return event.imageOptions?.qrCodeOverrideImageUrl;
}

private atomToImageUrl(ticketAtom: LemonadeAtom): string | undefined {
const event = this.lemonadeAtomToEvent(ticketAtom);
return this.imageOptionsToImageUrl(
event.imageOptions,
ticketAtom.checkinDate !== undefined
);
}

private atomToEventLocation(atom: LemonadeAtom): string | undefined {
const event = this.lemonadeAtomToEvent(atom);
return event.imageOptions?.eventLocation;
}

private atomToEventStartDate(atom: LemonadeAtom): string | undefined {
const event = this.lemonadeAtomToEvent(atom);
return event.imageOptions?.eventStartDate;
}

private async manualTicketToTicketData(
client: PoolClient,
manualTicket: ManualTicket,
Expand All @@ -608,6 +643,10 @@ export class LemonadePipeline implements BasePipeline {
attendeeName: manualTicket.attendeeName,
attendeeSemaphoreId: sempahoreId,
isConsumed: checkIn ? true : false,
imageUrl: this.imageOptionsToImageUrl(event.imageOptions, !!checkIn),
qrCodeOverrideImageUrl: event.imageOptions?.qrCodeOverrideImageUrl,
eventStartDate: event.imageOptions?.eventStartDate,
eventLocation: event.imageOptions?.eventLocation,
isRevoked: false,
timestampSigned: Date.now(),
timestampConsumed: checkIn ? checkIn.timestamp.getTime() : 0,
Expand Down Expand Up @@ -783,7 +822,6 @@ export class LemonadePipeline implements BasePipeline {
): Promise<EdDSATicketPCD[]> {
return traced(LOG_NAME, "getTicketsForEmail", async () => {
// Load atom-backed tickets

const relevantTickets = await this.db.loadByEmail(this.id, email);

// Load check-in data
Expand Down Expand Up @@ -832,7 +870,6 @@ export class LemonadePipeline implements BasePipeline {
): Promise<PollFeedResponseValue> {
return traced(LOG_NAME, "issueLemonadeTicketPCDs", async (span) => {
tracePipeline(this.definition);

if (!req.pcd) {
throw new Error("missing credential pcd");
}
Expand Down Expand Up @@ -1160,6 +1197,10 @@ export class LemonadePipeline implements BasePipeline {
timestampConsumed:
atom.checkinDate instanceof Date ? atom.checkinDate.getTime() : 0,
timestampSigned: Date.now(),
imageUrl: this.atomToImageUrl(atom),
qrCodeOverrideImageUrl: this.atomToQrCodeOverrideImageUrl(atom),
eventStartDate: this.atomToEventStartDate(atom),
eventLocation: this.atomToEventLocation(atom),
attendeeSemaphoreId: semaphoreId,
isConsumed: atom.checkinDate instanceof Date,
isRevoked: false, // Not clear what concept this maps to in Lemonade
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ export class PretixPipeline implements BasePipeline {
ticketId: atom.id,
eventId: atom.eventId,
productId: atom.productId,
timestampConsumed: atom.timestampConsumed?.getTime() ?? 0,
timestampConsumed: atom?.timestampConsumed?.getTime() ?? 0,
timestampSigned: Date.now(),
owner: semaphoreV4Id,
imageUrl: this.atomToImageUrl(atom),
Expand Down
24 changes: 21 additions & 3 deletions apps/passport-server/src/services/issuanceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,19 @@ export class IssuanceService {
isConsumed: false,
isRevoked: false,
ticketCategory: TicketCategory.Zuzalu,
imageUrl: urljoin(imageServerUrl, "images/zuzalu", "zuzalu.png"),
imageAltText: "Zuzalu logo"
imageUrl: urljoin(
imageServerUrl,
"images/zuzalu",
"zuzalu-landscape.webp"
),
qrCodeOverrideImageUrl: urljoin(
imageServerUrl,
"images/zuzalu",
"zuzalu.png"
),
imageAltText: "Zuzalu logo",
eventLocation: "Lustica Bay, Montenegro",
eventStartDate: "2023-03-11T00:00:00.000Z"
})
);
}
Expand Down Expand Up @@ -759,11 +770,18 @@ export class IssuanceService {
isRevoked: false,
ticketCategory: TicketCategory.ZuConnect,
imageUrl: urljoin(
imageServerUrl,
"images/zuzalu",
"zuconnect-landscape.webp"
),
qrCodeOverrideImageUrl: urljoin(
imageServerUrl,
"images/zuzalu",
"zuconnect.png"
),
imageAltText: "ZuConnect"
imageAltText: "ZuConnect",
eventLocation: "Istanbul, Turkey",
eventStartDate: "2023-10-29T00:00:00.000Z"
})
);
}
Expand Down
22 changes: 13 additions & 9 deletions packages/lib/passport-interface/src/genericIssuanceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ const SemaphoreGroupListSchema = z
{ message: "Semaphore group names must be unique" }
);

const ImageOptionsSchema = z.object({
imageUrl: z.string(),
requireCheckedIn: z.boolean(),
qrCodeOverrideImageUrl: z.string().optional(),
eventStartDate: z.string().optional(),
eventLocation: z.string().optional()
});

/**
* Generic Issuance-specific ticket type configuration - roughly corresponds to a
* 'Product' in Pretix-land.
Expand All @@ -206,7 +214,11 @@ const LemonadePipelineEventConfigSchema = z.object({
/**
* Roughly translates to Products in {@link EdDSATicketPCD}.
*/
ticketTypes: z.array(LemonadePipelineTicketTypeConfigSchema)
ticketTypes: z.array(LemonadePipelineTicketTypeConfigSchema),
/**
* Options to configure displaying an image instead of the QR code
*/
imageOptions: ImageOptionsSchema.optional()
});

/**
Expand Down Expand Up @@ -275,14 +287,6 @@ const FeedIssuanceOptionsSchema = z.object({

export type FeedIssuanceOptions = z.infer<typeof FeedIssuanceOptionsSchema>;

const ImageOptionsSchema = z.object({
imageUrl: z.string(),
requireCheckedIn: z.boolean(),
qrCodeOverrideImageUrl: z.string().optional(),
eventStartDate: z.string().optional(),
eventLocation: z.string().optional()
});

export type ImageOptions = z.infer<typeof ImageOptionsSchema>;

const LemonadePipelineOptionsSchema = BasePipelineOptionsSchema.extend({
Expand Down
7 changes: 3 additions & 4 deletions packages/ui/eddsa-ticket-pcd-ui/src/CardBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ function EdDSATicketPCDCardBody({

// If ticket has an `eventStartDate` render the `qrCodeOverrideImageUrl`, if it exists
// Else, render the `imageUrl`, if it existss
const imageToRender =
ticketData?.eventStartDate && idBasedVerifyURL !== undefined
? ticketData.qrCodeOverrideImageUrl
: ticketData?.imageUrl;
const imageToRender = ticketData?.eventStartDate
? ticketData.qrCodeOverrideImageUrl
: ticketData?.imageUrl;

return (
<NEW_UI__Container>
Expand Down

0 comments on commit 529f041

Please sign in to comment.