diff --git a/messages/en-US.json b/messages/en-US.json index 80875b96..34ef3d7a 100644 --- a/messages/en-US.json +++ b/messages/en-US.json @@ -1939,6 +1939,7 @@ "logRetention7Days": "7 days", "logRetention14Days": "14 days", "logRetention30Days": "30 days", + "logRetention90Days": "90 days", "logRetentionForever": "Forever", "actionLogsDescription": "View a history of actions performed in this organization", "accessLogsDescription": "View access auth requests for resources in this organization", diff --git a/server/routers/org/updateOrg.ts b/server/routers/org/updateOrg.ts index a517ed17..f96ac8a3 100644 --- a/server/routers/org/updateOrg.ts +++ b/server/routers/org/updateOrg.ts @@ -9,6 +9,9 @@ import createHttpError from "http-errors"; import logger from "@server/logger"; import { fromError } from "zod-validation-error"; import { OpenAPITags, registry } from "@server/openApi"; +import { build } from "@server/build"; +import { getOrgTierData } from "@server/lib/billing"; +import { TierId } from "@server/lib/billing/tiers"; const updateOrgParamsSchema = z .object({ @@ -19,9 +22,18 @@ const updateOrgParamsSchema = z const updateOrgBodySchema = z .object({ name: z.string().min(1).max(255).optional(), - settingsLogRetentionDaysRequest: z.number().min(-1).optional(), - settingsLogRetentionDaysAccess: z.number().min(-1).optional(), - settingsLogRetentionDaysAction: z.number().min(-1).optional() + settingsLogRetentionDaysRequest: z + .number() + .min(build === "saas" ? 0 : -1) + .optional(), + settingsLogRetentionDaysAccess: z + .number() + .min(build === "saas" ? 0 : -1) + .optional(), + settingsLogRetentionDaysAction: z + .number() + .min(build === "saas" ? 0 : -1) + .optional() }) .strict() .refine((data) => Object.keys(data).length > 0, { @@ -74,6 +86,20 @@ export async function updateOrg( const { orgId } = parsedParams.data; + const { tier } = await getOrgTierData(orgId); // returns null in oss + if ( + tier != TierId.STANDARD && + parsedBody.data.settingsLogRetentionDaysRequest && + parsedBody.data.settingsLogRetentionDaysRequest > 30 + ) { + return next( + createHttpError( + HttpCode.FORBIDDEN, + "You are not allowed to set log retention days greater than 30 because you are not subscribed to the Standard tier" + ) + ); + } + const updatedOrg = await db .update(orgs) .set({ diff --git a/src/app/[orgId]/settings/general/page.tsx b/src/app/[orgId]/settings/general/page.tsx index 2599ec74..00d8f3a0 100644 --- a/src/app/[orgId]/settings/general/page.tsx +++ b/src/app/[orgId]/settings/general/page.tsx @@ -48,7 +48,7 @@ import { DropdownMenuItem, DropdownMenuTrigger } from "@app/components/ui/dropdown-menu"; -import { ChevronDown } from "lucide-react"; +import { ChevronDown, SubscriptIcon } from "lucide-react"; import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext"; import { useSubscriptionStatusContext } from "@app/hooks/useSubscriptionStatusContext"; import { Alert, AlertDescription } from "@app/components/ui/alert"; @@ -70,7 +70,8 @@ const LOG_RETENTION_OPTIONS = [ { label: "logRetention7Days", value: 7 }, { label: "logRetention14Days", value: 14 }, { label: "logRetention30Days", value: 30 }, - { label: "logRetentionForever", value: -1 } + { label: "logRetention90Days", value: 90 }, + ...(build != "saas" ? [{ label: "logRetentionForever", value: -1 }] : []) ]; export default function GeneralPage() { @@ -314,7 +315,12 @@ export default function GeneralPage() { - {LOG_RETENTION_OPTIONS.map( + {LOG_RETENTION_OPTIONS.filter((option) => { + if (build == "saas" && !subscription?.subscribed && option.value > 30) { + return false + } + return true; + }).map( (option) => (