mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-06 10:46:38 +00:00
Lock down days
This commit is contained in:
@@ -1939,6 +1939,7 @@
|
|||||||
"logRetention7Days": "7 days",
|
"logRetention7Days": "7 days",
|
||||||
"logRetention14Days": "14 days",
|
"logRetention14Days": "14 days",
|
||||||
"logRetention30Days": "30 days",
|
"logRetention30Days": "30 days",
|
||||||
|
"logRetention90Days": "90 days",
|
||||||
"logRetentionForever": "Forever",
|
"logRetentionForever": "Forever",
|
||||||
"actionLogsDescription": "View a history of actions performed in this organization",
|
"actionLogsDescription": "View a history of actions performed in this organization",
|
||||||
"accessLogsDescription": "View access auth requests for resources in this organization",
|
"accessLogsDescription": "View access auth requests for resources in this organization",
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import createHttpError from "http-errors";
|
|||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import { OpenAPITags, registry } from "@server/openApi";
|
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
|
const updateOrgParamsSchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -19,9 +22,18 @@ const updateOrgParamsSchema = z
|
|||||||
const updateOrgBodySchema = z
|
const updateOrgBodySchema = z
|
||||||
.object({
|
.object({
|
||||||
name: z.string().min(1).max(255).optional(),
|
name: z.string().min(1).max(255).optional(),
|
||||||
settingsLogRetentionDaysRequest: z.number().min(-1).optional(),
|
settingsLogRetentionDaysRequest: z
|
||||||
settingsLogRetentionDaysAccess: z.number().min(-1).optional(),
|
.number()
|
||||||
settingsLogRetentionDaysAction: z.number().min(-1).optional()
|
.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()
|
.strict()
|
||||||
.refine((data) => Object.keys(data).length > 0, {
|
.refine((data) => Object.keys(data).length > 0, {
|
||||||
@@ -74,6 +86,20 @@ export async function updateOrg(
|
|||||||
|
|
||||||
const { orgId } = parsedParams.data;
|
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
|
const updatedOrg = await db
|
||||||
.update(orgs)
|
.update(orgs)
|
||||||
.set({
|
.set({
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import {
|
|||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger
|
||||||
} from "@app/components/ui/dropdown-menu";
|
} from "@app/components/ui/dropdown-menu";
|
||||||
import { ChevronDown } from "lucide-react";
|
import { ChevronDown, SubscriptIcon } from "lucide-react";
|
||||||
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
||||||
import { useSubscriptionStatusContext } from "@app/hooks/useSubscriptionStatusContext";
|
import { useSubscriptionStatusContext } from "@app/hooks/useSubscriptionStatusContext";
|
||||||
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
||||||
@@ -70,7 +70,8 @@ const LOG_RETENTION_OPTIONS = [
|
|||||||
{ label: "logRetention7Days", value: 7 },
|
{ label: "logRetention7Days", value: 7 },
|
||||||
{ label: "logRetention14Days", value: 14 },
|
{ label: "logRetention14Days", value: 14 },
|
||||||
{ label: "logRetention30Days", value: 30 },
|
{ label: "logRetention30Days", value: 30 },
|
||||||
{ label: "logRetentionForever", value: -1 }
|
{ label: "logRetention90Days", value: 90 },
|
||||||
|
...(build != "saas" ? [{ label: "logRetentionForever", value: -1 }] : [])
|
||||||
];
|
];
|
||||||
|
|
||||||
export default function GeneralPage() {
|
export default function GeneralPage() {
|
||||||
@@ -314,7 +315,12 @@ export default function GeneralPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent className="w-full">
|
<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) => (
|
(option) => (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
key={
|
key={
|
||||||
|
|||||||
Reference in New Issue
Block a user