Skip to content

Commit

Permalink
made one click links more configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ichub committed Sep 27, 2024
1 parent 9a18f3e commit 0f9f929
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { ScreenLoader } from "../../shared/ScreenLoader";

/**
* format: http://localhost:3000/#/one-click-login/:email/:code/:targetFolder
* format: http://localhost:3000/#/one-click-login/:email/:code/:targetFolder/:pipelineId?/:serverUrl?
* - `code` is the pretix or lemonade order code
* - `email` is the email address of the ticket to whom the ticket was issued
* - `targetFolder` is the folder to redirect to after login. optional.
Expand All @@ -25,7 +25,7 @@ import { ScreenLoader } from "../../shared/ScreenLoader";
export function OneClickLoginScreen(): JSX.Element | null {
const self = useSelf();
const dispatch = useDispatch();
const { email, code, targetFolder } = useParams();
const { email, code, targetFolder, pipelineId, serverUrl } = useParams();
const [ticketPreviews, setTicketPreviews] = useState<IPODTicketData[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | undefined>();
Expand All @@ -44,9 +44,10 @@ export function OneClickLoginScreen(): JSX.Element | null {
}
try {
const previewRes = await requestGenericIssuanceTicketPreviews(
appConfig.zupassServer,
serverUrl ?? appConfig.zupassServer,
email,
code
code,
pipelineId
);

setLoading(false);
Expand All @@ -64,7 +65,7 @@ export function OneClickLoginScreen(): JSX.Element | null {
}
});
}
}, [dispatch, email, code]);
}, [email, code, serverUrl, pipelineId, dispatch]);

const handleOneClickLogin = useCallback(async () => {
if (!email || !code) {
Expand Down Expand Up @@ -141,8 +142,8 @@ export function OneClickLoginScreen(): JSX.Element | null {
<div>No tickets found</div>
) : (
<>
{ticketPreviews.map((ticket) => (
<CardOutlineExpanded>
{ticketPreviews.map((ticket, i) => (
<CardOutlineExpanded key={i}>
<CardBodyContainer>
<CardHeader isMainIdentity={true}>
{ticket.eventName} ({ticket.ticketName})
Expand Down
2 changes: 1 addition & 1 deletion apps/passport-client/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function RouterImpl(): JSX.Element {
<Route path="add-email" element={<AddEmailScreen />} />
<Route path="remove-email" element={<RemoveEmailScreen />} />
<Route
path="one-click-login/:email/:code/:targetFolder"
path="one-click-login/:email/:code/:targetFolder/:pipelineId?/:serverUrl?"
element={<OneClickLoginScreen />}
/>
<Route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,16 +670,18 @@ export function initGenericIssuanceRoutes(
);

app.get(
"/generic-issuance/api/ticket-previews/:email/:orderCode",
"/generic-issuance/api/ticket-previews/:email/:orderCode/:pipelineId?",
async (req, res) => {
checkGenericIssuanceServiceStarted(genericIssuanceService);

const email = checkUrlParam(req, "email");
const orderCode = checkUrlParam(req, "orderCode");
const pipelineId = req.params.pipelineId;

const result = await genericIssuanceService.handleGetTicketPreview(
email,
orderCode
orderCode,
pipelineId
);

res.json(result satisfies TicketPreviewResultValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,28 +351,29 @@ export class GenericIssuanceService {

public async handleGetTicketPreview(
email: string,
orderCode: string
orderCode: string,
pipelineId?: string
): Promise<TicketPreviewResultValue> {
const devconPipelineId = process.env.DEVCON_PIPELINE_ID;
const devconPipeline = (await this.getAllPipelineInstances()).find(
(p) => p.id === devconPipelineId && PretixPipeline.is(p)
const requestedPipelineId = pipelineId ?? process.env.DEVCON_PIPELINE_ID;
const pipeline = (await this.getAllPipelineInstances()).find(
(p) => p.id === requestedPipelineId && PretixPipeline.is(p)
) as PretixPipeline | undefined;

if (!devconPipeline) {
if (!pipeline) {
throw new PCDHTTPError(
400,
"devcon pipeline not found " + devconPipelineId
"handleGetTicketPreview: pipeline not found " + requestedPipelineId
);
}

const tickets = await devconPipeline.getAllTickets();
const tickets = await pipeline.getAllTickets();

const matchingTickets = tickets.atoms.filter(
(atom) => atom.email === email && atom.orderCode === orderCode
);

const ticketDatas = matchingTickets.map((atom) =>
devconPipeline.atomToPODTicketData(atom, "1234")
pipeline.atomToPODTicketData(atom, "1")
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ import { APIResult } from "./apiResult";
import { httpGetSimple } from "./makeRequest";

/**
* Asks the server to fetch the pipeline definition corresponding to the
* given pipeline ID. Requires cookies, as this is part of generic issuance
* user authentication.
* Asks the server to fetch the ticket previews for the given email and order code.
*/
export async function requestGenericIssuanceTicketPreviews(
zupassServerUrl: string,
email: string,
orderCode: string
orderCode: string,
pipelineId?: string
): Promise<GenericIssuanceTicketPreviewResponse> {
return httpGetSimple(
urlJoin(
zupassServerUrl,
`/generic-issuance/api/ticket-previews`,
encodeURIComponent(email),
encodeURIComponent(orderCode)
),
) + (pipelineId ? `/${pipelineId}` : ""),
async (resText) => ({
value: JSON.parse(resText) as TicketPreviewResultValue,
success: true
Expand Down

0 comments on commit 0f9f929

Please sign in to comment.