Skip to content

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

🔥 Remove legacy adminUrlId admin token (#2313)

Luke Vellae63d63886ff2
diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-details/page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-details/page.tsx
index 6b9e4d6a5..4d02c7c6f 100644
--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-details/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-details/page.tsx
@@ -21,7 +21,6 @@ import { Trans } from "@/i18n/client";
const Page = () => {
const { poll } = usePoll();
- const urlId = poll.adminUrlId;
const { mutate: updatePollMutation, isPending: isUpdating } =
useUpdatePollMutation();
const router = useRouter();
@@ -46,7 +45,7 @@ const Page = () => {
onSubmit={form.handleSubmit((data) => {
//submit
updatePollMutation(
- { urlId, ...data },
+ { pollId: poll.id, ...data },
{
onSuccess: (res) => {
if (res.ok) {
diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
index 90afa0a05..5e32c768c 100644
--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-options/page.tsx
@@ -108,7 +108,7 @@ const Page = () => {
const onOk = () => {
updatePollMutation(
{
- urlId: poll.adminUrlId,
+ pollId: poll.id,
timeZone: data.timeZone,
optionsToDelete: optionsToDelete.map(({ id }) => id),
optionsToAdd,
diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-settings/page.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-settings/page.tsx
index a155b3348..032dc1d0e 100644
--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-settings/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/edit-settings/page.tsx
@@ -40,7 +40,7 @@ const Page = () => {
onSubmit={form.handleSubmit(async (data) => {
//submit
const res = await update.mutateAsync({
- urlId: poll.adminUrlId,
+ pollId: poll.id,
...data,
});
if (res.ok) {
diff --git a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/layout.tsx b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/layout.tsx
index ee213fdf4..6f27776ba 100644
--- a/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/layout.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/poll/[urlId]/layout.tsx
@@ -16,21 +16,24 @@ export default async function Layout(
const trpc = await createPublicSSRHelper();
- const [poll] = await Promise.all([
- trpc.polls.get.fetch({ urlId: params.urlId }).catch((e) => {
+ const poll = await trpc.polls.get
+ .fetch({ urlId: params.urlId })
+ .catch((e) => {
if (e instanceof TRPCError && e.code === "NOT_FOUND") {
notFound();
}
throw e;
- }),
- trpc.polls.participants.list.prefetch({ pollId: params.urlId }),
- trpc.polls.comments.list.prefetch({ pollId: params.urlId }),
- ]);
+ });
- if (!poll.adminUrlId) {
+ if (!poll.canManage) {
redirect(`/invite/${params.urlId}`);
}
+ await Promise.all([
+ trpc.polls.participants.list.prefetch({ pollId: params.urlId }),
+ trpc.polls.comments.list.prefetch({ pollId: params.urlId }),
+ ]);
+
return (
<HydrationBoundary state={dehydrate(trpc.queryClient)}>
<PollLayout>{children}</PollLayout>
diff --git a/apps/web/src/trpc/client/types.ts b/apps/web/src/trpc/client/types.ts
index 8fb8c3158..3dc04bba5 100644
--- a/apps/web/src/trpc/client/types.ts
+++ b/apps/web/src/trpc/client/types.ts
@@ -13,7 +13,7 @@ export type GetPollApiResponse = {
banned: boolean;
} | null;
timeZone: string | null;
- adminUrlId: string;
+ canManage: boolean;
status: PollStatus;
participantUrlId: string;
createdAt: Date;
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index dc5f5e24e..3e00b789e 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -30,23 +30,6 @@ import { participants } from "./polls/participants";
const collapseNewlines = (s: string) => s.replace(/\n{3,}/g, "\n\n");
-const getPollIdFromAdminUrlId = async (urlId: string) => {
- const res = await prisma.poll.findUnique({
- select: {
- id: true,
- },
- where: { adminUrlId: urlId },
- });
-
- if (!res) {
- throw new TRPCError({
- code: "NOT_FOUND",
- message: "Poll not found",
- });
- }
- return res.id;
-};
-
export const polls = router({
participants,
comments,
@@ -289,7 +272,7 @@ export const polls = router({
modify: possiblyPublicProcedure
.input(
z.object({
- urlId: z.string(),
+ pollId: z.string(),
title: z.string().trim().optional(),
timeZone: z.string().optional(),
location: z.string().trim().optional(),
@@ -305,7 +288,7 @@ export const polls = router({
.use(requireUserMiddleware)
.use(createRateLimitMiddleware("update_poll", 10, "1 m"))
.mutation(async ({ input, ctx }) => {
- const pollId = await getPollIdFromAdminUrlId(input.urlId);
+ const pollId = input.pollId;
if (!(await hasPollAdminAccess(pollId, ctx.user.id))) {
throw new TRPCError({
@@ -570,7 +553,6 @@ export const polls = router({
.input(
z.object({
urlId: z.string(),
- adminToken: z.string().optional(),
}),
)
.query(async ({ input, ctx }) => {
@@ -582,7 +564,6 @@ export const polls = router({
location: true,
description: true,
createdAt: true,
- adminUrlId: true,
participantUrlId: true,
status: true,
hideParticipants: true,
@@ -652,7 +633,7 @@ export const polls = router({
}
const inviteLink = shortUrl(`/invite/${res.id}`);
- const canManagePoll = ctx.user
+ const canManage = ctx.user
? await canUserManagePoll(ctx.user, res)
: false;
@@ -680,15 +661,12 @@ export const polls = router({
}
: null;
- if (canManagePoll || res.adminUrlId === input.adminToken) {
- return {
- ...res,
- inviteLink,
- event,
- };
- } else {
- return { ...res, adminUrlId: "", inviteLink, event };
- }
+ return {
+ ...res,
+ canManage,
+ inviteLink,
+ event,
+ };
}),
book: proProcedure
.input(