Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Hard delete responses so their invite reverts to pending (#3191)

Luke Vellaaf3d9273dd55
diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.ts
index 857eea708..5831931bf 100644
--- a/apps/web/src/trpc/routers/polls/participants.ts
+++ b/apps/web/src/trpc/routers/polls/participants.ts
@@ -237,14 +237,14 @@ export const participants = router({
},
});
- await tx.participant.update({
+ // Hard delete: votes cascade, the invite's SetNull FK reverts it to
+ // pending, and the response frees the token it took from that invite
+ // so the next response through the same link can take it again. The
+ // activity row above is the historical record.
+ await tx.participant.delete({
where: {
id: participantId,
},
- data: {
- deleted: true,
- deletedAt: new Date(),
- },
});
await recordPollActivities(tx, [
diff --git a/apps/web/tests/email-invites.spec.ts b/apps/web/tests/email-invites.spec.ts
index a7b6b3f1c..6c69a36db 100644
--- a/apps/web/tests/email-invites.spec.ts
+++ b/apps/web/tests/email-invites.spec.ts
@@ -65,6 +65,26 @@ async function renameThroughInviteLink(
}
}
+/**
+ * The poll holds one response, so the menu resolves without disambiguation.
+ */
+async function deleteResponse(page: Page, name: string) {
+ await page.getByTestId("participant-menu").click();
+ await page.getByRole("menuitem", { name: "Delete" }).click();
+ const dialog = page.getByRole("dialog", { name: `Delete ${name}?` });
+ await dialog.getByRole("button", { name: "Delete" }).click();
+ await expect(dialog).toBeHidden();
+ // The list update is optimistic, so wait for the row to actually be gone
+ // before reading the invite it released.
+ await expect
+ .poll(async () =>
+ prisma.participant.count({
+ where: { name, poll: { title: POLL_TITLE } },
+ }),
+ )
+ .toBe(0);
+}
+
async function reopenShareDialog(page: Page) {
await page.reload();
await page.getByRole("button", { name: "Share" }).click();
@@ -211,6 +231,41 @@ test.describe("Email invites", () => {
});
await page.reload();
await expect(page.getByText("Renamed Guest")).toBeVisible();
+
+ // Deleting the response reverts the invite to pending: the row goes back
+ // to Opened, and the link keeps working because the response released
+ // the token it had taken from the invite.
+ await deleteResponse(page, "Renamed Guest");
+ const revertedRow = (await reopenShareDialog(page))
+ .getByRole("listitem")
+ .filter({ hasText: INVITEE });
+ await expect(revertedRow.getByText("Opened")).toBeVisible();
+ await page.keyboard.press("Escape");
+
+ const reverted = await prisma.pollInvite.findUniqueOrThrow({
+ where: { id: invite.id },
+ select: { participantId: true, token: true, revokedAt: true },
+ });
+ expect(reverted.participantId).toBeNull();
+ expect(reverted.revokedAt).toBeNull();
+ expect(reverted.token).toBe(converted.token);
+
+ // Responding through the same link a second time converts it again and
+ // takes the token back.
+ const second = await openAsGuest(browser as Browser, emailedUrl as string);
+ await new InvitePage(second.guestPage).addParticipant("Second Response");
+ await second.close();
+
+ const reconverted = await prisma.pollInvite.findUniqueOrThrow({
+ where: { id: invite.id },
+ select: { token: true, participant: { select: { token: true } } },
+ });
+ expect(reconverted.participant?.token).toBe(reconverted.token);
+
+ const respondedAgainRow = (await reopenShareDialog(page))
+ .getByRole("listitem")
+ .filter({ hasText: INVITEE });
+ await expect(respondedAgainRow.getByText("Responded")).toBeVisible();
});
test("creation opens the dialog and leaves the URL clean", async ({
diff --git a/packages/database/prisma/models/poll.prisma b/packages/database/prisma/models/poll.prisma
index 6c9d47794..3457a106e 100644
--- a/packages/database/prisma/models/poll.prisma
+++ b/packages/database/prisma/models/poll.prisma
@@ -104,7 +104,7 @@ model PollInvite {
openedAt DateTime? @map("opened_at")
remindedAt DateTime? @map("reminded_at")
- /// Revocation is always explicit: set when the host removes a pending invite, never as a side effect of close, schedule or reopen. Deleting a response clears participantId instead, reverting the invite to pending with its token intact. Cleared only by re-inviting (reactivation), which also rotates the token
+ /// Revocation is always explicit: set when the host removes a pending invite, never as a side effect of close, schedule or reopen. Deleting a response instead hard deletes the participant, so the SetNull FK clears participantId and reverts the invite to pending with its token intact — the token the deleted response held is freed with it, so the next response through the same link can take it again. Cleared only by re-inviting (reactivation), which also rotates the token
revokedAt DateTime? @map("revoked_at")
/// Conversion join, merges invite history into the response timeline. Set only when the invitee responds via their token: a typed email is unverified, so a generic link response never claims an invite