Skip to content

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

πŸ—ƒοΈ Add PollInvite, PollActivity and Participant.token for Poll Admin (#2846)

Luke Vella972058f14157
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 9b3fa23eb..81be00f01 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -205,7 +205,7 @@
"delete": "Delete",
"deleteAccount": "Delete Account",
"deleteAccountActivePolls": "{count, plural, one {# active poll} other {# active polls}}",
- "deleteAccountDataWarning": "All data associated with your account, including your polls, events, votes, and comments, will be permanently deleted.",
+ "deleteAccountDialogDataWarning": "All data associated with your account will be permanently deleted.",
"deleteAccountDialogDescription": "Are you sure you want to delete your account?",
"deleteAccountDialogImmediateWarning": "Your account and data will be deleted immediately. This cannot be undone.",
"deleteAccountDialogScheduleDescription": "Your account will be scheduled for deletion.",
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/actions.ts b/apps/web/src/app/[locale]/(space)/settings/profile/actions.ts
index a98025020..02ff9e98b 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/actions.ts
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/actions.ts
@@ -114,7 +114,7 @@ export const deleteAccountAction = authActionClient
}
await deletePostHogPerson({ distinctId: ctx.user.id });
- await hardDeleteUser({ userId: ctx.user.id, email: ctx.user.email });
+ await hardDeleteUser({ userId: ctx.user.id });
// Personless by design β€” the person this event is about was just erased.
trackSystemEvent({ event: "account_deletion_complete" });
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-dialog.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-dialog.tsx
index e76c83333..db021a930 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-dialog.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-dialog.tsx
@@ -69,8 +69,8 @@ function ScheduleAccountDeletionDialog({
<div className="space-y-3 text-sm">
<p>
<Trans
- i18nKey="deleteAccountDataWarning"
- defaults="All data associated with your account, including your polls, events, votes, and comments, will be permanently deleted."
+ i18nKey="deleteAccountDialogDataWarning"
+ defaults="All data associated with your account will be permanently deleted."
/>
</p>
{summary}
@@ -156,8 +156,8 @@ function InstantDeleteAccountDialog({
<div className="space-y-3 py-4 text-sm">
<p>
<Trans
- i18nKey="deleteAccountDataWarning"
- defaults="All data associated with your account, including your polls, events, votes, and comments, will be permanently deleted."
+ i18nKey="deleteAccountDialogDataWarning"
+ defaults="All data associated with your account will be permanently deleted."
/>
</p>
{summary}
diff --git a/apps/web/src/app/[locale]/control-panel/users/actions.ts b/apps/web/src/app/[locale]/control-panel/users/actions.ts
index 42ad282f7..4ab15d1d1 100644
--- a/apps/web/src/app/[locale]/control-panel/users/actions.ts
+++ b/apps/web/src/app/[locale]/control-panel/users/actions.ts
@@ -48,7 +48,7 @@ export const deleteUserAction = adminActionClient
await deletePostHogPerson({ distinctId: userId });
- await hardDeleteUser({ userId, email: user.email });
+ await hardDeleteUser({ userId });
return {
success: true,
diff --git a/apps/web/src/app/api/house-keeping/[...method]/route.ts b/apps/web/src/app/api/house-keeping/[...method]/route.ts
index e439f91e0..c07c99ac6 100644
--- a/apps/web/src/app/api/house-keeping/[...method]/route.ts
+++ b/apps/web/src/app/api/house-keeping/[...method]/route.ts
@@ -135,7 +135,7 @@ async function removeDeletedUsers() {
await deletePostHogPerson({ distinctId: user.id });
- await hardDeleteUser({ userId: user.id, email: user.email });
+ await hardDeleteUser({ userId: user.id });
// Personless by design β€” the person this event is about was just
// erased, so it must not create or attach to a profile.
diff --git a/apps/web/src/features/user/mutations.ts b/apps/web/src/features/user/mutations.ts
index b1d93c4b1..7bcfe51e2 100644
--- a/apps/web/src/features/user/mutations.ts
+++ b/apps/web/src/features/user/mutations.ts
@@ -122,13 +122,7 @@ export async function unbanUser({ userId }: { userId: string }) {
// Sessions are revoked through Better-Auth's internal adapter for the same
// reason as bans: with secondary storage they live in Redis, and only
// Better-Auth's own APIs delete those keys.
-export async function hardDeleteUser({
- userId,
- email,
-}: {
- userId: string;
- email: string;
-}) {
+export async function hardDeleteUser({ userId }: { userId: string }) {
const { internalAdapter } = await authLib.$context;
await internalAdapter.deleteSessions(userId);
@@ -144,16 +138,12 @@ export async function hardDeleteUser({
await deleteImageFromS3(user.image);
}
- // Cascades cover data the user owns, but their personal data also lives
- // where they took part in other users' content: participant rows carry
- // name/email (votes cascade off them, matching the promise in the delete
- // dialog) and event invites carry invitee name/email. Both relations are
- // SetNull, so the rows would otherwise outlive the account.
- await prisma.participant.deleteMany({ where: { userId } });
- await prisma.scheduledEventInvite.deleteMany({
- where: { OR: [{ inviteeId: userId }, { inviteeEmail: email }] },
- });
-
+ // Cascades cover content the user owns. Everything on other people's polls
+ // and events (participants, votes, invites, activity log) is that record's
+ // data, not the account's β€” deletion never mutates it, so finalized
+ // outcomes, attendance, and activity history can't change when an account
+ // disappears. The FK SetNulls unlink participants and event invites;
+ // PollActivity's soft refs persist as inert identity that resolves to nothing.
await prisma.user.delete({ where: { id: userId } });
}
diff --git a/packages/database/prisma/migrations/20260802224313_add_poll_invites_and_activities/migration.sql b/packages/database/prisma/migrations/20260802224313_add_poll_invites_and_activities/migration.sql
new file mode 100644
index 000000000..f92e78d86
--- /dev/null
+++ b/packages/database/prisma/migrations/20260802224313_add_poll_invites_and_activities/migration.sql
@@ -0,0 +1,67 @@
+-- AlterTable
+ALTER TABLE "participants" ADD COLUMN "token" TEXT;
+
+-- CreateTable
+CREATE TABLE "poll_invites" (
+ "id" TEXT NOT NULL,
+ "poll_id" TEXT NOT NULL,
+ "email" CITEXT NOT NULL,
+ "token" TEXT NOT NULL,
+ "opened_at" TIMESTAMP(3),
+ "reminded_at" TIMESTAMP(3),
+ "revoked_at" TIMESTAMP(3),
+ "participant_id" TEXT,
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "updated_at" TIMESTAMP(3) NOT NULL,
+
+ CONSTRAINT "poll_invites_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "poll_activities" (
+ "id" TEXT NOT NULL,
+ "poll_id" TEXT NOT NULL,
+ "type" TEXT NOT NULL,
+ "user_id" TEXT,
+ "participant_id" TEXT,
+ "invite_id" TEXT,
+ "option_id" TEXT,
+ "payload" JSONB NOT NULL DEFAULT '{}',
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+
+ CONSTRAINT "poll_activities_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "poll_invites_token_key" ON "poll_invites"("token");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "poll_invites_participant_id_key" ON "poll_invites"("participant_id");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "poll_invites_poll_id_email_key" ON "poll_invites"("poll_id", "email");
+
+-- CreateIndex
+CREATE INDEX "poll_activities_poll_id_created_at_idx" ON "poll_activities"("poll_id", "created_at" DESC);
+
+-- CreateIndex
+CREATE INDEX "poll_activities_poll_id_participant_id_idx" ON "poll_activities"("poll_id", "participant_id");
+
+-- CreateIndex
+CREATE INDEX "poll_activities_poll_id_option_id_idx" ON "poll_activities"("poll_id", "option_id");
+
+-- CreateIndex
+CREATE INDEX "poll_activities_poll_id_invite_id_idx" ON "poll_activities"("poll_id", "invite_id");
+
+-- CreateIndex
+CREATE UNIQUE INDEX "participants_token_key" ON "participants"("token");
+
+-- AddForeignKey
+ALTER TABLE "poll_invites" ADD CONSTRAINT "poll_invites_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "poll_invites" ADD CONSTRAINT "poll_invites_participant_id_fkey" FOREIGN KEY ("participant_id") REFERENCES "participants"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "poll_activities" ADD CONSTRAINT "poll_activities_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
diff --git a/packages/database/prisma/models/poll.prisma b/packages/database/prisma/models/poll.prisma
index ba3ecd3e9..a15c90ae9 100644
--- a/packages/database/prisma/models/poll.prisma
+++ b/packages/database/prisma/models/poll.prisma
@@ -58,6 +58,8 @@ model Poll {
participants Participant[]
comments Comment[]
votes Vote[]
+ invites PollInvite[]
+ activities PollActivity[]
space Space? @relation(fields: [spaceId], references: [id], onDelete: SetNull)
spaceId String? @map("space_id")
@@ -71,6 +73,8 @@ model Participant {
name String
email String?
note String?
+ /// Per person edit link: grants edit access to this response without a session. App minted, CSPRNG alphanumeric β‰₯32 chars (nanoid customAlphabet β€” url safe with no linkifier edge cases, unlike base64url); never a DB default, nullable because it's only minted when a link is issued
+ token String? @unique
userId String? @map("user_id")
pollId String @map("poll_id")
locale String?
@@ -80,7 +84,8 @@ model Participant {
deleted Boolean @default(false)
deletedAt DateTime? @map("deleted_at")
- votes Vote[]
+ votes Vote[]
+ invite PollInvite?
poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
@@ -90,6 +95,55 @@ model Participant {
@@map("participants")
}
+model PollInvite {
+ id String @id @default(cuid())
+ pollId String @map("poll_id")
+ email String @db.Citext
+ /// Per invitee link. App minted, CSPRNG alphanumeric β‰₯32 chars (nanoid customAlphabet) β€” no schema default, so forgetting to mint fails loudly. Rotated on reactivation so a revoked (possibly leaked) token never regains access
+ token String @unique
+
+ openedAt DateTime? @map("opened_at")
+ remindedAt DateTime? @map("reminded_at")
+ /// Revocation is always explicit: set on host revoke and on close/schedule, never as a side effect. Deleting a response (by anyone) clears participantId instead, reverting the invite to pending with its token intact. Never cleared by reopen; cleared only by re-inviting (reactivation)
+ revokedAt DateTime? @map("revoked_at")
+
+ /// Conversion join, merges invite history into the response timeline. Set when the invitee responds via their token, or when a generic link response's email matches a pending invite (citext) β€” responding always consumes the invite
+ participantId String? @unique @map("participant_id")
+
+ createdAt DateTime @default(now()) @map("created_at")
+ updatedAt DateTime @updatedAt @map("updated_at")
+
+ poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
+ participant Participant? @relation(fields: [participantId], references: [id], onDelete: SetNull)
+
+ @@unique([pollId, email])
+ @@map("poll_invites")
+}
+
+model PollActivity {
+ id String @id @default(cuid())
+ pollId String @map("poll_id")
+ /// Validated by a zod union in the feature, not a DB enum: the activity vocabulary grows without migrations
+ type String
+
+ /// Subject ids are soft references (no FKs): activity must outlive its subjects β€” including account deletion β€” so refs persist as identity and the payload carries the display snapshot; whether a ref still resolves is the renderer's question
+ userId String? @map("user_id")
+ participantId String? @map("participant_id")
+ inviteId String? @map("invite_id")
+ optionId String? @map("option_id")
+ payload Json @default("{}")
+
+ createdAt DateTime @default(now()) @map("created_at")
+
+ poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
+
+ @@index([pollId, createdAt(sort: Desc)])
+ @@index([pollId, participantId])
+ @@index([pollId, optionId])
+ @@index([pollId, inviteId])
+ @@map("poll_activities")
+}
+
model Option {
id String @id @default(cuid())
startTime DateTime @map("start_time") @db.Timestamp(0)