Skip to content

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

🔒 Hide deleted poll data from unauthenticated callers (#2599)

Luke Vella6b23372f3c80
diff --git a/apps/web/src/components/poll-context.tsx b/apps/web/src/components/poll-context.tsx
index 74fbbe290..8d01733fe 100644
--- a/apps/web/src/components/poll-context.tsx
+++ b/apps/web/src/components/poll-context.tsx
@@ -1,7 +1,5 @@
import type { TimeFormat, VoteType } from "@rallly/database";
-import { TrashIcon } from "lucide-react";
import React from "react";
-import { useTranslation } from "@/i18n/client";
import { useDateTimeConfig } from "@/lib/datetime/client";
import {
formatDateParts,
@@ -43,7 +41,6 @@ export const PollContextProvider: React.FunctionComponent<{
poll: GetPollApiResponse;
children?: React.ReactNode;
}> = ({ poll, children }) => {
- const { t } = useTranslation();
const { participants } = useParticipants();
const getScore = React.useCallback(
@@ -95,19 +92,6 @@ export const PollContextProvider: React.FunctionComponent<{
};
}, [getScore, participants, poll]);
- if (poll.deleted) {
- return (
- <div className="flex h-[calc(100vh-100px)] w-full items-center justify-center">
- <div className="space-y-4 text-center">
- <TrashIcon className="mb-4 inline-block size-24 text-muted-foreground" />
- <div className="mb-2 font-bold text-3xl text-foreground">
- {t("deletedPoll")}
- </div>
- <p className="text-muted-foreground">{t("deletedPollInfo")}</p>
- </div>
- </div>
- );
- }
return (
<PollContext.Provider value={contextValue}>{children}</PollContext.Provider>
);
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index 024bf6ce4..132c9ea3f 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -672,7 +672,9 @@ export const polls = router({
},
});
- if (!res) {
+ // A deleted poll is treated as if it never existed, for everyone
+ // including its owner and space managers.
+ if (!res || res.deleted) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Poll not found",
diff --git a/apps/web/src/trpc/routers/polls/comments.ts b/apps/web/src/trpc/routers/polls/comments.ts
index dc6c7a582..6820f99b1 100644
--- a/apps/web/src/trpc/routers/polls/comments.ts
+++ b/apps/web/src/trpc/routers/polls/comments.ts
@@ -35,12 +35,18 @@ export const comments = router({
select: {
userId: true,
hideParticipants: true,
+ deleted: true,
},
});
- const isOwner = poll?.userId === ctx.user?.id;
+ // A deleted poll never exposes its comments.
+ if (!poll || poll.deleted) {
+ throw new TRPCError({ code: "NOT_FOUND", message: "Poll not found" });
+ }
+
+ const isOwner = poll.userId === ctx.user?.id;
- const hideParticipants = poll?.hideParticipants && !isOwner;
+ const hideParticipants = poll.hideParticipants && !isOwner;
if (hideParticipants && !isOwner) {
// if hideParticipants is enabled and the user is not the owner
diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.ts
index 726a26ad8..a7ad125b8 100644
--- a/apps/web/src/trpc/routers/polls/participants.ts
+++ b/apps/web/src/trpc/routers/polls/participants.ts
@@ -121,10 +121,12 @@ export const participants = router({
where: { id: pollId },
select: {
hideParticipants: true,
+ deleted: true,
},
});
- if (!poll) {
+ // A deleted poll never exposes its participants.
+ if (!poll || poll.deleted) {
throw new TRPCError({ code: "NOT_FOUND", message: "Poll not found" });
}