Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
📈 Report adoption over the open poll limit, document it, fix an empty dialog (#3490)
Luke Vella58ad79f0d079
diff --git a/apps/docs/faq.mdx b/apps/docs/faq.mdxindex e030724e1..ba574b1f6 100644--- a/apps/docs/faq.mdx+++ b/apps/docs/faq.mdx@@ -13,14 +13,29 @@ description: "Frequently asked questions about Rallly."<Accordion title="Do I need to create an account to use Rallly?">No, you don't! You can create and share polls without creating an account.- However, some features (like email notifications) are only available to users- with an account.+ Without an account you can have one open poll at a time, and some features+ (like email notifications) are only available to users with an account.</Accordion><Accordion title="Are there any limits to the number of polls, participants and options I can make?">- No, there are no limits to the number of polls, participants or options you- make. There are technical limits in place to prevent misuse but these are very- generous and should not affect normal usage.+ There is no limit to the number of polls you can create, the number of+ participants who can vote or the number of options in a poll. What depends on+ your plan is how many polls can be open, collecting votes, at the same time:++ - **Guests** (no account): 1 open poll+ - **Hobby** (free): 3 open polls+ - **Pro**: unlimited open polls++ Finalize or close a poll to make room for another. There are also technical+ limits in place to prevent misuse but these are very generous and should not+ affect normal usage. Self-hosted instances have no open poll limit.+</Accordion>++<Accordion title="What counts as an open poll?">+ A poll is open while it's collecting votes. Polls you have finalized, closed or+ deleted don't count towards your limit, and polls close automatically once all+ their dates have passed. On Hobby the limit applies to the polls you created in+ each space.</Accordion><Accordion title="How long will Rallly keep my poll?">diff --git a/apps/docs/spaces/billing.mdx b/apps/docs/spaces/billing.mdxindex 19fa1f335..b8185dfb2 100644--- a/apps/docs/spaces/billing.mdx+++ b/apps/docs/spaces/billing.mdx@@ -119,6 +119,6 @@ As a space owner, you have full access to Stripe's customer portal for:</Accordion><Accordion title="What happens to my polls if I cancel?">- Pro spaces that cancel will revert to Hobby tier limitations. Polls may be subject to automatic deletion based on inactivity rules.+ Pro spaces that cancel will revert to Hobby tier limitations, including the limit of 3 open polls per organizer. Polls you already have stay open, but you can't open more until you're under the limit. Polls may be subject to automatic deletion based on inactivity rules.</Accordion></AccordionGroup>\ No newline at end of filediff --git a/apps/web/src/features/auth/mutations.ts b/apps/web/src/features/auth/mutations.tsindex ce99b2f3c..3eb11e8c5 100644--- a/apps/web/src/features/auth/mutations.ts+++ b/apps/web/src/features/auth/mutations.ts@@ -2,6 +2,10 @@ import "server-only";import { prisma } from "@rallly/database";import { createLogger } from "@rallly/logger";import * as Sentry from "@sentry/nextjs";+import {+ countAdoptableOpenPolls,+ reportAdoptionOverLimit,+} from "@/features/poll/limit/mutations";import { effectiveSpaceMemberWhere } from "@/features/space/member/utils";import { posthog } from "@/lib/posthog";@@ -66,6 +70,10 @@ export const linkAnonymousUser = async ();}+ const adoptedOpenCount = spaceId+ ? await countAdoptableOpenPolls({ userId: anonymousUserId })+ : 0;+await prisma.$transaction(async (tx) => {// Transfer space-scoped data from anonymous user to authenticated userawait Promise.all([@@ -116,6 +124,16 @@ export const linkAnonymousUser = async (]);});+ // Without a space, setup adopts the polls later and reports then.+ if (spaceId) {+ await reportAdoptionOverLimit({+ userId: authenticatedUserId,+ spaceId,+ adoptedOpenCount,+ source: "login",+ });+ }+// Merge user identities in PostHogposthog()?.capture({distinctId: authenticatedUserId,diff --git a/apps/web/src/features/poll/limit/client.tsx b/apps/web/src/features/poll/limit/client.tsxindex 2426bb4d0..522b381d5 100644--- a/apps/web/src/features/poll/limit/client.tsx+++ b/apps/web/src/features/poll/limit/client.tsx@@ -6,10 +6,12 @@ import type { OpenPollUsage } from "./types";export type OpenPollLimitSource = "create" | "reopen" | "duplicate";type OpenPollLimitStore = {- open: {+ isOpen: boolean;+ /** Kept after closing, so the dialog still has content while it animates out */+ content: {source: OpenPollLimitSource;usage: OpenPollUsage;- /** The page it was opened on: leaving it closes the dialog */+ /** The page it was opened on: only that page shows it */pathname: string;} | null;show: (source: OpenPollLimitSource, usage: OpenPollUsage) => void;@@ -17,10 +19,14 @@ type OpenPollLimitStore = {};export const useOpenPollLimitStore = create<OpenPollLimitStore>((set) => ({- open: null,+ isOpen: false,+ content: null,show: (source, usage) =>- set({ open: { source, usage, pathname: window.location.pathname } }),- hide: () => set({ open: null }),+ set({+ isOpen: true,+ content: { source, usage, pathname: window.location.pathname },+ }),+ hide: () => set({ isOpen: false }),}));/**diff --git a/apps/web/src/features/poll/limit/components/open-poll-limit-dialog.tsx b/apps/web/src/features/poll/limit/components/open-poll-limit-dialog.tsxindex 3660839c8..52a5ff580 100644--- a/apps/web/src/features/poll/limit/components/open-poll-limit-dialog.tsx+++ b/apps/web/src/features/poll/limit/components/open-poll-limit-dialog.tsx@@ -32,27 +32,28 @@ import { Trans, useTranslation } from "@/i18n/client";* `showOpenPollLimit()`.*/export function OpenPollLimitDialog() {- const open = useOpenPollLimitStore((state) => state.open);+ const isOpen = useOpenPollLimitStore((state) => state.isOpen);+ const content = useOpenPollLimitStore((state) => state.content);const hide = useOpenPollLimitStore((state) => state.hide);// A refused reopen or duplicate leaves the organizer on a page that still// works, so it can be dismissed. On /new there is nothing left to do but// make room, register or upgrade, so the only ways out are its own links.- const dismissible = open !== null && open.source !== "create";+ const dismissible = content !== null && content.source !== "create";- // The dialog's links close it by leaving the page. Clearing the store on- // the route change rather than on click keeps it up if that navigation- // fails or is cancelled. Each layout mounts its own instance, so the page- // it was opened on comes from the store, not from this instance's mount.+ // The dialog's links close it by leaving the page, which keeps it up if+ // that navigation fails or is cancelled. Each layout mounts its own+ // instance, so one on another page must never open, even for a moment.const pathname = usePathname();+ const isOnOpeningPage = content !== null && content.pathname === pathname;React.useEffect(() => {- if (open && pathname !== open.pathname) {+ if (isOpen && !isOnOpeningPage) {hide();}- }, [open, pathname, hide]);+ }, [isOpen, isOnOpeningPage, hide]);return (<Dialog- open={open !== null}+ open={isOpen && isOnOpeningPage}disablePointerDismissal={!dismissible}onOpenChange={(open) => {if (!open && dismissible) {@@ -61,8 +62,8 @@ export function OpenPollLimitDialog() {}}><DialogContent size="md" showCloseButton={dismissible}>- {open ? (- <OpenPollLimitContent source={open.source} usage={open.usage} />+ {content ? (+ <OpenPollLimitContent source={content.source} usage={content.usage} />) : null}</DialogContent></Dialog>diff --git a/apps/web/src/features/poll/limit/mutations.ts b/apps/web/src/features/poll/limit/mutations.tsindex 22709407e..9e7ee0cd5 100644--- a/apps/web/src/features/poll/limit/mutations.ts+++ b/apps/web/src/features/poll/limit/mutations.ts@@ -1,8 +1,10 @@import "server-only";import type { Prisma } from "@rallly/database";+import { prisma } from "@rallly/database";+import { track } from "@/lib/posthog";import { isOpenPollLimitEnabled } from "./constants";-import { countOpenPolls } from "./data";+import { countOpenPolls, getOpenPollUsage } from "./data";import type { OpenPollUsage } from "./types";import { getOpenPollLimit, getOpenPollTier, isAtOpenPollLimit } from "./utils";@@ -61,3 +63,77 @@ export async function assertOpenPollCapacity(throw new OpenPollLimitError(capacity.usage);}}++/**+ * Open polls a guest is about to hand over to an account. Read before the+ * hand-over, so `reportAdoptionOverLimit` can tell what it added.+ */+export function countAdoptableOpenPolls(+ where: { userId: string; spaceId: null } | { userId: string },+) {+ if (!isOpenPollLimitEnabled) {+ return Promise.resolve(0);+ }+ return prisma.poll.count({+ where: { ...where, status: "open", deleted: false },+ });+}++/**+ * Adopting guest polls is never blocked, so signing in can leave an+ * organizer over the limit. Reported so the open poll limit's log in+ * loophole (log out, create as a guest, log back in) can be measured.+ * Never throws: it runs inside sign in and setup.+ */+export async function reportAdoptionOverLimit({+ userId,+ spaceId,+ adoptedOpenCount,+ source,+}: {+ userId: string;+ spaceId: string;+ adoptedOpenCount: number;+ source: "login" | "setup";+}) {+ if (!isOpenPollLimitEnabled || adoptedOpenCount === 0) {+ return;+ }++ try {+ const space = await prisma.space.findUnique({+ where: { id: spaceId },+ select: { tier: true },+ });+ if (!space) {+ return;+ }++ const usage = await getOpenPollUsage({+ userId,+ spaceId,+ tier: getOpenPollTier(space.tier),+ });+ if (usage.limit === null || usage.openCount <= usage.limit) {+ return;+ }++ track(+ { id: userId, isGuest: false },+ {+ event: "poll_limit:adopted_over_limit",+ properties: {+ tier: usage.tier,+ open_count: usage.openCount,+ limit: usage.limit,+ adopted_open_count: adoptedOpenCount,+ over_by: usage.openCount - usage.limit,+ source,+ },+ groups: { space: spaceId },+ },+ );+ } catch {+ // Reporting only; adoption already succeeded.+ }+}diff --git a/apps/web/src/features/poll/mutations.ts b/apps/web/src/features/poll/mutations.tsindex 092f12873..4f4cd4aa2 100644--- a/apps/web/src/features/poll/mutations.ts+++ b/apps/web/src/features/poll/mutations.ts@@ -7,7 +7,11 @@ import { revalidatePath } from "next/cache";import { recordPollActivities } from "@/features/activity/mutations";import { parsePollConferencing } from "@/features/conferencing/data";import type { PollConferencing } from "@/features/conferencing/schema";-import { assertOpenPollCapacity } from "@/features/poll/limit/mutations";+import {+ assertOpenPollCapacity,+ countAdoptableOpenPolls,+ reportAdoptionOverLimit,+} from "@/features/poll/limit/mutations";import type { AuthorizedSpaceId } from "@/features/space/types";import { scheduleWebhookDispatch } from "@/features/webhook/mutations";@@ -272,6 +276,11 @@ export async function adoptOrphanedPolls({userId: string;spaceId: string;}) {+ const adoptedOpenCount = await countAdoptableOpenPolls({+ userId,+ spaceId: null,+ });+await prisma.poll.updateMany({where: {userId,@@ -281,6 +290,13 @@ export async function adoptOrphanedPolls({spaceId,},});++ await reportAdoptionOverLimit({+ userId,+ spaceId,+ adoptedOpenCount,+ source: "setup",+ });}/**diff --git a/apps/web/tests/open-poll-limit.spec.ts b/apps/web/tests/open-poll-limit.spec.tsindex 489022a72..1a8387519 100644--- a/apps/web/tests/open-poll-limit.spec.ts+++ b/apps/web/tests/open-poll-limit.spec.ts@@ -190,9 +190,8 @@ test.describe("free organizer", () => {.getByRole("link", { name: "Go to polls" }).click();await expect(page).toHaveURL(/\/polls/);- await expect(- page.getByRole("dialog", { name: "Open poll limit reached" }),- ).toBeHidden();+ // Any dialog, titled or not: an empty shell has no accessible name.+ await expect(page.getByRole("dialog")).toHaveCount(0);});test("is shown the limit when reopening from the poll page", async () => {