Lock down days

This commit is contained in:
Owen
2025-10-26 18:36:09 -07:00
parent f4a0f6a2e6
commit 592d085de6
3 changed files with 39 additions and 6 deletions

View File

@@ -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",

View File

@@ -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({

View File

@@ -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() {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-full">
{LOG_RETENTION_OPTIONS.map(
{LOG_RETENTION_OPTIONS.filter((option) => {
if (build == "saas" && !subscription?.subscribed && option.value > 30) {
return false
}
return true;
}).map(
(option) => (
<DropdownMenuItem
key={