Skip to content

Open-source status page, incident response and uptime monitoring

fix: workspace limits (#950)

Maximilian Kaske9ad3b6234d03
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/domain/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/domain/page.tsx
index 6d1d7502a..fd4f66aad 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/domain/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/domain/page.tsx
@@ -15,7 +15,7 @@ export default async function CustomDomainPage({
const page = await api.page.getPageById.query({ id });
const workspace = await api.workspace.getWorkspace.query();
- const isValid = allPlans[workspace.plan].limits["custom-domain"];
+ const isValid = workspace.limits["custom-domain"];
if (!page) return notFound();
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/subscribers/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/subscribers/page.tsx
index 07ea7eea4..cd95e8cd1 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/subscribers/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/subscribers/page.tsx
@@ -1,7 +1,5 @@
import { notFound } from "next/navigation";
-import { allPlans } from "@openstatus/db/src/schema/plan/config";
-
import { ProFeatureAlert } from "@/components/billing/pro-feature-alert";
import { columns } from "@/components/data-table/page-subscriber/columns";
import { DataTable } from "@/components/data-table/page-subscriber/data-table";
@@ -18,7 +16,7 @@ export default async function CustomDomainPage({
if (!page) return notFound();
- const isValid = allPlans[workspace.plan].limits["status-subscribers"];
+ const isValid = workspace.limits["status-subscribers"];
if (!isValid) return <ProFeatureAlert feature={"Status page subscribers"} />;
const data = await api.pageSubscriber.getPageSubscribersByPageId.query({
diff --git a/apps/web/src/app/status-page/[domain]/_components/footer.tsx b/apps/web/src/app/status-page/[domain]/_components/footer.tsx
index f0b0d2cfc..12da9f3f5 100644
--- a/apps/web/src/app/status-page/[domain]/_components/footer.tsx
+++ b/apps/web/src/app/status-page/[domain]/_components/footer.tsx
@@ -9,7 +9,7 @@ interface Props {
}
export function Footer({ plan, timeZone }: Props) {
- const isWhiteLabel = allPlans[plan].limits["white-label"];
+ const isWhiteLabel = allPlans[plan].limits["white-label"]; // FIXME: use the workspace.limits
return (
<footer className="z-10 mx-auto grid w-full grid-cols-5 items-center justify-between gap-4">
<p className="truncate font-light text-muted-foreground text-xs">
diff --git a/apps/web/src/components/dashboard/limit.tsx b/apps/web/src/components/dashboard/limit.tsx
index f1417550b..4cfa4ab85 100644
--- a/apps/web/src/components/dashboard/limit.tsx
+++ b/apps/web/src/components/dashboard/limit.tsx
@@ -3,9 +3,12 @@ import Link from "next/link";
export function Limit() {
return (
<div className="col-span-full text-center">
- <p className="text-foreground text-sm">
+ <p className="text-muted-foreground text-sm">
You have reached the account limits. Please{" "}
- <Link href={"./settings/billing"} className="underline">
+ <Link
+ href={"./settings/billing"}
+ className="text-foreground underline underline-offset-4 hover:no-underline"
+ >
upgrade
</Link>{" "}
your account.
diff --git a/packages/api/src/router/invitation.ts b/packages/api/src/router/invitation.ts
index 20e5116c9..451af3de8 100644
--- a/packages/api/src/router/invitation.ts
+++ b/packages/api/src/router/invitation.ts
@@ -20,7 +20,7 @@ export const invitationRouter = createTRPCRouter({
.mutation(async (opts) => {
const { email } = opts.input;
- const _members = allPlans[opts.ctx.workspace.plan].limits.members;
+ const _members = opts.ctx.workspace.limits.members;
const membersLimit = _members === "Unlimited" ? 420 : _members;
const usersToWorkspacesNumbers = (
diff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.ts
index 5b48471c9..b7420620a 100644
--- a/packages/api/src/router/monitor.ts
+++ b/packages/api/src/router/monitor.ts
@@ -34,10 +34,9 @@ export const monitorRouter = createTRPCRouter({
.input(insertMonitorSchema)
.output(selectMonitorSchema)
.mutation(async (opts) => {
- const monitorLimit = allPlans[opts.ctx.workspace.plan].limits.monitors;
- const periodicityLimit =
- allPlans[opts.ctx.workspace.plan].limits.periodicity;
- const regionsLimit = allPlans[opts.ctx.workspace.plan].limits.regions;
+ const monitorLimit = opts.ctx.workspace.limits.monitors;
+ const periodicityLimit = opts.ctx.workspace.limits.periodicity;
+ const regionsLimit = opts.ctx.workspace.limits.regions;
const monitorNumbers = (
await opts.ctx.db.query.monitor.findMany({
@@ -252,10 +251,9 @@ export const monitorRouter = createTRPCRouter({
.mutation(async (opts) => {
if (!opts.input.id) return;
- const periodicityLimit =
- allPlans[opts.ctx.workspace.plan].limits.periodicity;
+ const periodicityLimit = opts.ctx.workspace.limits.periodicity;
- const regionsLimit = allPlans[opts.ctx.workspace.plan].limits.regions;
+ const regionsLimit = opts.ctx.workspace.limits.regions;
// the user is not allowed to use the cron job
if (
@@ -729,7 +727,7 @@ export const monitorRouter = createTRPCRouter({
}),
isMonitorLimitReached: protectedProcedure.query(async (opts) => {
- const monitorLimit = allPlans[opts.ctx.workspace.plan].limits.monitors;
+ const monitorLimit = opts.ctx.workspace.limits.monitors;
const monitorNumbers = (
await opts.ctx.db.query.monitor.findMany({
where: and(
diff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.ts
index 48623e04a..15a0d685c 100644
--- a/packages/api/src/router/page.ts
+++ b/packages/api/src/router/page.ts
@@ -42,7 +42,7 @@ export const pageRouter = createTRPCRouter({
})
).length;
- const limit = allPlans[opts.ctx.workspace.plan].limits;
+ const limit = opts.ctx.workspace.limits;
// the user has reached the status page number limits
if (pageNumbers >= limit["status-pages"]) {
@@ -123,7 +123,7 @@ export const pageRouter = createTRPCRouter({
const monitorIds = monitors?.map((item) => item.monitorId) || [];
- const limit = allPlans[opts.ctx.workspace.plan].limits;
+ const limit = opts.ctx.workspace.limits;
// the user is not eligible for password protection
if (
@@ -369,7 +369,7 @@ export const pageRouter = createTRPCRouter({
}),
isPageLimitReached: protectedProcedure.query(async (opts) => {
- const pageLimit = allPlans[opts.ctx.workspace.plan].limits["status-pages"];
+ const pageLimit = opts.ctx.workspace.limits["status-pages"];
const pageNumbers = (
await opts.ctx.db.query.page.findMany({
where: eq(monitor.workspaceId, opts.ctx.workspace.id),
diff --git a/packages/db/src/schema/workspaces/validation.ts b/packages/db/src/schema/workspaces/validation.ts
index a4d1d494b..97a913320 100644
--- a/packages/db/src/schema/workspaces/validation.ts
+++ b/packages/db/src/schema/workspaces/validation.ts
@@ -9,7 +9,36 @@ import { workspace } from "./workspace";
export const workspacePlanSchema = z.enum(workspacePlans);
export const workspaceRoleSchema = z.enum(workspaceRole);
-export const selectWorkspaceSchema = createSelectSchema(workspace).extend({
+/**
+ * Workspace schema with limits and plan
+ * If not available in the db, the limits will be taken from the workspace plan
+ */
+const selectWorkspaceSchemaDevelopment = createSelectSchema(workspace)
+ .extend({
+ limits: z.string().transform((val) => {
+ const parsed = JSON.parse(val);
+ const result = limitsV1.partial().safeParse(parsed);
+ if (result.error) return {};
+ return result.data;
+ }),
+ plan: z
+ .enum(workspacePlans)
+ .nullable()
+ .default("free")
+ .transform((val) => val ?? "free"),
+ })
+ .transform((val) => {
+ return {
+ ...val,
+ limits: limitsV1.parse({ ...allPlans[val.plan].limits, ...val.limits }),
+ };
+ });
+
+/**
+ * Workspace schema with limits and plan
+ * The limits for paid users have to be defined within the db otherwise, fallbacks to free plan limits
+ */
+const selectWorkspaceSchemaProduction = createSelectSchema(workspace).extend({
limits: z.string().transform((val) => {
const parsed = JSON.parse(val);
const result = limitsV1.safeParse(parsed);
@@ -29,6 +58,11 @@ export const selectWorkspaceSchema = createSelectSchema(workspace).extend({
.transform((val) => val ?? "free"),
});
+export const selectWorkspaceSchema =
+ process.env.NODE_ENV === "development"
+ ? selectWorkspaceSchemaDevelopment
+ : selectWorkspaceSchemaProduction;
+
export const insertWorkspaceSchema = createSelectSchema(workspace);
export type Workspace = z.infer<typeof selectWorkspaceSchema>;