mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-03 17:26:38 +00:00
Added better notifications for users when templates are updated.
Added confirmation dialogs for destructive actions. Other improvements/changes When deleting rule templates, we now clean up all resource rules that were created from the template.
This commit is contained in:
@@ -31,7 +31,26 @@ export async function deleteRuleTemplate(req: any, res: any) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete template rules first (due to foreign key constraint)
|
// Get all template rules for this template
|
||||||
|
const templateRulesToDelete = await db
|
||||||
|
.select({ ruleId: templateRules.ruleId })
|
||||||
|
.from(templateRules)
|
||||||
|
.where(eq(templateRules.templateId, templateId));
|
||||||
|
|
||||||
|
// Delete resource rules that reference these template rules first
|
||||||
|
if (templateRulesToDelete.length > 0) {
|
||||||
|
const { resourceRules } = await import("@server/db");
|
||||||
|
const templateRuleIds = templateRulesToDelete.map(rule => rule.ruleId);
|
||||||
|
|
||||||
|
// Delete all resource rules that reference any of the template rules
|
||||||
|
for (const ruleId of templateRuleIds) {
|
||||||
|
await db
|
||||||
|
.delete(resourceRules)
|
||||||
|
.where(eq(resourceRules.templateRuleId, ruleId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete template rules
|
||||||
await db
|
await db
|
||||||
.delete(templateRules)
|
.delete(templateRules)
|
||||||
.where(eq(templateRules.templateId, templateId));
|
.where(eq(templateRules.templateId, templateId));
|
||||||
|
|||||||
@@ -67,15 +67,20 @@ export async function deleteTemplateRule(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the rule
|
// Count affected resources for the response message
|
||||||
await db
|
let affectedResourcesCount = 0;
|
||||||
.delete(templateRules)
|
|
||||||
.where(and(eq(templateRules.templateId, templateId), eq(templateRules.ruleId, parseInt(ruleId))));
|
|
||||||
|
|
||||||
// Also delete all resource rules that were created from this template rule
|
|
||||||
try {
|
try {
|
||||||
const { resourceRules } = await import("@server/db");
|
const { resourceRules } = await import("@server/db");
|
||||||
|
|
||||||
|
// Get affected resource rules before deletion for counting
|
||||||
|
const affectedResourceRules = await db
|
||||||
|
.select()
|
||||||
|
.from(resourceRules)
|
||||||
|
.where(eq(resourceRules.templateRuleId, parseInt(ruleId)));
|
||||||
|
|
||||||
|
affectedResourcesCount = affectedResourceRules.length;
|
||||||
|
|
||||||
|
// Delete the resource rules first (due to foreign key constraint)
|
||||||
await db
|
await db
|
||||||
.delete(resourceRules)
|
.delete(resourceRules)
|
||||||
.where(eq(resourceRules.templateRuleId, parseInt(ruleId)));
|
.where(eq(resourceRules.templateRuleId, parseInt(ruleId)));
|
||||||
@@ -84,11 +89,20 @@ export async function deleteTemplateRule(
|
|||||||
// Don't fail the template rule deletion if resource rule deletion fails, just log it
|
// Don't fail the template rule deletion if resource rule deletion fails, just log it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete the template rule after resource rules are deleted
|
||||||
|
await db
|
||||||
|
.delete(templateRules)
|
||||||
|
.where(and(eq(templateRules.templateId, templateId), eq(templateRules.ruleId, parseInt(ruleId))));
|
||||||
|
|
||||||
|
const message = affectedResourcesCount > 0
|
||||||
|
? `Template rule deleted successfully. Removed from ${affectedResourcesCount} assigned resource${affectedResourcesCount > 1 ? 's' : ''}.`
|
||||||
|
: "Template rule deleted successfully.";
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
data: null,
|
data: null,
|
||||||
success: true,
|
success: true,
|
||||||
error: false,
|
error: false,
|
||||||
message: "Template rule deleted successfully",
|
message,
|
||||||
status: HttpCode.OK
|
status: HttpCode.OK
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -9,6 +9,14 @@ 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";
|
||||||
|
|
||||||
|
export type GetRuleTemplateResponse = {
|
||||||
|
templateId: string;
|
||||||
|
orgId: string;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
createdAt: number;
|
||||||
|
};
|
||||||
|
|
||||||
const getRuleTemplateParamsSchema = z
|
const getRuleTemplateParamsSchema = z
|
||||||
.object({
|
.object({
|
||||||
orgId: z.string().min(1),
|
orgId: z.string().min(1),
|
||||||
|
|||||||
@@ -144,8 +144,8 @@ export async function updateTemplateRule(
|
|||||||
|
|
||||||
// Remove undefined values
|
// Remove undefined values
|
||||||
Object.keys(propagationData).forEach(key => {
|
Object.keys(propagationData).forEach(key => {
|
||||||
if (propagationData[key] === undefined) {
|
if ((propagationData as any)[key] === undefined) {
|
||||||
delete propagationData[key];
|
delete (propagationData as any)[key];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -161,11 +161,28 @@ export async function updateTemplateRule(
|
|||||||
// Don't fail the template rule update if propagation fails, just log it
|
// Don't fail the template rule update if propagation fails, just log it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Count affected resources for the response message
|
||||||
|
let affectedResourcesCount = 0;
|
||||||
|
try {
|
||||||
|
const { resourceTemplates } = await import("@server/db");
|
||||||
|
const affectedResources = await db
|
||||||
|
.select()
|
||||||
|
.from(resourceTemplates)
|
||||||
|
.where(eq(resourceTemplates.templateId, templateId));
|
||||||
|
affectedResourcesCount = affectedResources.length;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error counting affected resources:", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = affectedResourcesCount > 0
|
||||||
|
? `Template rule updated successfully. Changes propagated to ${affectedResourcesCount} assigned resource${affectedResourcesCount > 1 ? 's' : ''}.`
|
||||||
|
: "Template rule updated successfully.";
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
data: updatedRule,
|
data: updatedRule,
|
||||||
success: true,
|
success: true,
|
||||||
error: false,
|
error: false,
|
||||||
message: "Template rule updated successfully",
|
message,
|
||||||
status: HttpCode.OK
|
status: HttpCode.OK
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ import { useEnvContext } from "@app/hooks/useEnvContext";
|
|||||||
import {
|
import {
|
||||||
SettingsContainer,
|
SettingsContainer,
|
||||||
SettingsSection,
|
SettingsSection,
|
||||||
SettingsSectionHeader,
|
SettingsSectionHeader
|
||||||
SettingsSectionTitle
|
|
||||||
} from "@app/components/Settings";
|
} from "@app/components/Settings";
|
||||||
|
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
||||||
import { Button } from "@app/components/ui/button";
|
import { Button } from "@app/components/ui/button";
|
||||||
import { Input } from "@app/components/ui/input";
|
import { Input } from "@app/components/ui/input";
|
||||||
import { Textarea } from "@app/components/ui/textarea";
|
import { Textarea } from "@app/components/ui/textarea";
|
||||||
@@ -79,8 +79,9 @@ export default function GeneralPage() {
|
|||||||
data
|
data
|
||||||
);
|
);
|
||||||
toast({
|
toast({
|
||||||
title: t("ruleTemplateUpdated"),
|
title: "Template Updated",
|
||||||
description: t("ruleTemplateUpdatedDescription")
|
description: "Template details have been updated successfully. Changes to template rules will automatically propagate to all assigned resources.",
|
||||||
|
variant: "default"
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import { useParams } from "next/navigation";
|
|||||||
import {
|
import {
|
||||||
SettingsContainer,
|
SettingsContainer,
|
||||||
SettingsSection,
|
SettingsSection,
|
||||||
SettingsSectionHeader,
|
SettingsSectionHeader
|
||||||
SettingsSectionTitle
|
|
||||||
} from "@app/components/Settings";
|
} from "@app/components/Settings";
|
||||||
|
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
||||||
import { TemplateRulesManager } from "@app/components/ruleTemplate/TemplateRulesManager";
|
import { TemplateRulesManager } from "@app/components/ruleTemplate/TemplateRulesManager";
|
||||||
|
|
||||||
export default function RulesPage() {
|
export default function RulesPage() {
|
||||||
|
|||||||
78
src/components/ConfirmationDialog.tsx
Normal file
78
src/components/ConfirmationDialog.tsx
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle
|
||||||
|
} from "@app/components/ui/dialog";
|
||||||
|
import { Button } from "@app/components/ui/button";
|
||||||
|
import { AlertTriangle } from "lucide-react";
|
||||||
|
|
||||||
|
interface ConfirmationDialogProps {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
confirmText?: string;
|
||||||
|
cancelText?: string;
|
||||||
|
variant?: "destructive" | "default";
|
||||||
|
onConfirm: () => Promise<void> | void;
|
||||||
|
loading?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ConfirmationDialog({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
confirmText = "Confirm",
|
||||||
|
cancelText = "Cancel",
|
||||||
|
variant = "destructive",
|
||||||
|
onConfirm,
|
||||||
|
loading = false
|
||||||
|
}: ConfirmationDialogProps) {
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
try {
|
||||||
|
await onConfirm();
|
||||||
|
onOpenChange(false);
|
||||||
|
} catch (error) {
|
||||||
|
// Error handling is done by the calling component
|
||||||
|
console.error("Confirmation action failed:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="flex items-center gap-2">
|
||||||
|
<AlertTriangle className="h-5 w-5 text-destructive" />
|
||||||
|
{title}
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
{description}
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{cancelText}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant={variant}
|
||||||
|
onClick={handleConfirm}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{loading ? "Processing..." : confirmText}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import { useToast } from "@app/hooks/useToast";
|
|||||||
import { Trash2 } from "lucide-react";
|
import { Trash2 } from "lucide-react";
|
||||||
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { ConfirmationDialog } from "@app/components/ConfirmationDialog";
|
||||||
|
|
||||||
interface RuleTemplate {
|
interface RuleTemplate {
|
||||||
templateId: string;
|
templateId: string;
|
||||||
@@ -38,6 +39,9 @@ export function ResourceRulesManager({
|
|||||||
const [resourceTemplates, setResourceTemplates] = useState<ResourceTemplate[]>([]);
|
const [resourceTemplates, setResourceTemplates] = useState<ResourceTemplate[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [selectedTemplate, setSelectedTemplate] = useState<string>("");
|
const [selectedTemplate, setSelectedTemplate] = useState<string>("");
|
||||||
|
const [unassignDialogOpen, setUnassignDialogOpen] = useState(false);
|
||||||
|
const [templateToUnassign, setTemplateToUnassign] = useState<string | null>(null);
|
||||||
|
const [unassigning, setUnassigning] = useState(false);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { env } = useEnvContext();
|
const { env } = useEnvContext();
|
||||||
const api = createApiClient({ env });
|
const api = createApiClient({ env });
|
||||||
@@ -79,8 +83,9 @@ export function ResourceRulesManager({
|
|||||||
|
|
||||||
if (response.status === 200 || response.status === 201) {
|
if (response.status === 200 || response.status === 201) {
|
||||||
toast({
|
toast({
|
||||||
title: "Success",
|
title: "Template Assigned",
|
||||||
description: "Template assigned successfully"
|
description: "Template has been assigned to this resource. All template rules have been applied and will be automatically updated when the template changes.",
|
||||||
|
variant: "default"
|
||||||
});
|
});
|
||||||
|
|
||||||
setSelectedTemplate("");
|
setSelectedTemplate("");
|
||||||
@@ -105,17 +110,22 @@ export function ResourceRulesManager({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleUnassignTemplate = async (templateId: string) => {
|
const handleUnassignTemplate = async (templateId: string) => {
|
||||||
if (!confirm("Are you sure you want to unassign this template?")) {
|
setTemplateToUnassign(templateId);
|
||||||
return;
|
setUnassignDialogOpen(true);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const confirmUnassignTemplate = async () => {
|
||||||
|
if (!templateToUnassign) return;
|
||||||
|
|
||||||
|
setUnassigning(true);
|
||||||
try {
|
try {
|
||||||
const response = await api.delete(`/resource/${resourceId}/templates/${templateId}`);
|
const response = await api.delete(`/resource/${resourceId}/templates/${templateToUnassign}`);
|
||||||
|
|
||||||
if (response.status === 200 || response.status === 201) {
|
if (response.status === 200 || response.status === 201) {
|
||||||
toast({
|
toast({
|
||||||
title: "Success",
|
title: "Template Unassigned",
|
||||||
description: "Template unassigned successfully"
|
description: "Template has been unassigned from this resource. All template-managed rules have been removed from this resource.",
|
||||||
|
variant: "default"
|
||||||
});
|
});
|
||||||
|
|
||||||
await fetchData();
|
await fetchData();
|
||||||
@@ -124,17 +134,20 @@ export function ResourceRulesManager({
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toast({
|
toast({
|
||||||
title: "Error",
|
title: "Unassign Failed",
|
||||||
description: response.data.message || "Failed to unassign template",
|
description: response.data.message || "Failed to unassign template. Please try again.",
|
||||||
variant: "destructive"
|
variant: "destructive"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
title: "Error",
|
title: "Unassign Failed",
|
||||||
description: formatAxiosError(error, "Failed to unassign template"),
|
description: formatAxiosError(error, "Failed to unassign template. Please try again."),
|
||||||
variant: "destructive"
|
variant: "destructive"
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setUnassigning(false);
|
||||||
|
setTemplateToUnassign(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -199,6 +212,18 @@ export function ResourceRulesManager({
|
|||||||
)}
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<ConfirmationDialog
|
||||||
|
open={unassignDialogOpen}
|
||||||
|
onOpenChange={setUnassignDialogOpen}
|
||||||
|
title="Unassign Template"
|
||||||
|
description="Are you sure you want to unassign this template? This will remove all template-managed rules from this resource. This action cannot be undone."
|
||||||
|
confirmText="Unassign Template"
|
||||||
|
cancelText="Cancel"
|
||||||
|
variant="destructive"
|
||||||
|
onConfirm={confirmUnassignTemplate}
|
||||||
|
loading={unassigning}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import {
|
|||||||
} from "@app/components/ui/table";
|
} from "@app/components/ui/table";
|
||||||
import { isValidCIDR, isValidIP, isValidUrlGlobPattern } from "@server/lib/validators";
|
import { isValidCIDR, isValidIP, isValidUrlGlobPattern } from "@server/lib/validators";
|
||||||
import { ArrowUpDown, Trash2, ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from "lucide-react";
|
import { ArrowUpDown, Trash2, ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from "lucide-react";
|
||||||
|
import { ConfirmationDialog } from "@app/components/ConfirmationDialog";
|
||||||
|
|
||||||
const addRuleSchema = z.object({
|
const addRuleSchema = z.object({
|
||||||
action: z.enum(["ACCEPT", "DROP"]),
|
action: z.enum(["ACCEPT", "DROP"]),
|
||||||
@@ -79,6 +80,9 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
pageIndex: 0,
|
pageIndex: 0,
|
||||||
pageSize: 25
|
pageSize: 25
|
||||||
});
|
});
|
||||||
|
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||||
|
const [ruleToDelete, setRuleToDelete] = useState<number | null>(null);
|
||||||
|
const [deletingRule, setDeletingRule] = useState(false);
|
||||||
|
|
||||||
const RuleAction = {
|
const RuleAction = {
|
||||||
ACCEPT: t('alwaysAllow'),
|
ACCEPT: t('alwaysAllow'),
|
||||||
@@ -151,18 +155,19 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await api.post(`/org/${orgId}/rule-templates/${templateId}/rules`, data);
|
const response = await api.post(`/org/${orgId}/rule-templates/${templateId}/rules`, data);
|
||||||
toast({
|
toast({
|
||||||
title: "Success",
|
title: "Template Rule Added",
|
||||||
description: "Rule added successfully"
|
description: "A new rule has been added to the template. It will be available for assignment to resources.",
|
||||||
|
variant: "default"
|
||||||
});
|
});
|
||||||
form.reset();
|
form.reset();
|
||||||
fetchRules();
|
fetchRules();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
title: "Error",
|
title: "Add Rule Failed",
|
||||||
description: formatAxiosError(error, "Failed to add rule")
|
description: formatAxiosError(error, "Failed to add rule. Please check your input and try again.")
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setAddingRule(false);
|
setAddingRule(false);
|
||||||
@@ -170,28 +175,54 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
};
|
};
|
||||||
|
|
||||||
const removeRule = async (ruleId: number) => {
|
const removeRule = async (ruleId: number) => {
|
||||||
|
setRuleToDelete(ruleId);
|
||||||
|
setDeleteDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmDeleteRule = async () => {
|
||||||
|
if (!ruleToDelete) return;
|
||||||
|
|
||||||
|
setDeletingRule(true);
|
||||||
try {
|
try {
|
||||||
await api.delete(`/org/${orgId}/rule-templates/${templateId}/rules/${ruleId}`);
|
await api.delete(`/org/${orgId}/rule-templates/${templateId}/rules/${ruleToDelete}`);
|
||||||
toast({
|
toast({
|
||||||
title: "Success",
|
title: "Template Rule Removed",
|
||||||
description: "Rule removed successfully"
|
description: "The rule has been removed from the template and from all assigned resources.",
|
||||||
|
variant: "default"
|
||||||
});
|
});
|
||||||
fetchRules();
|
fetchRules();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
title: "Error",
|
title: "Removal Failed",
|
||||||
description: formatAxiosError(error, "Failed to remove rule")
|
description: formatAxiosError(error, "Failed to remove template rule")
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setDeletingRule(false);
|
||||||
|
setRuleToDelete(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateRule = async (ruleId: number, data: Partial<TemplateRule>) => {
|
const updateRule = async (ruleId: number, data: Partial<TemplateRule>) => {
|
||||||
try {
|
try {
|
||||||
await api.put(`/org/${orgId}/rule-templates/${templateId}/rules/${ruleId}`, data);
|
const response = await api.put(`/org/${orgId}/rule-templates/${templateId}/rules/${ruleId}`, data);
|
||||||
|
|
||||||
|
// Show success notification with propagation info if available
|
||||||
|
const message = response.data?.message || "The template rule has been updated and changes have been propagated to all assigned resources.";
|
||||||
|
toast({
|
||||||
|
title: "Template Rule Updated",
|
||||||
|
description: message,
|
||||||
|
variant: "default"
|
||||||
|
});
|
||||||
|
|
||||||
fetchRules();
|
fetchRules();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to update rule:", error);
|
console.error("Failed to update rule:", error);
|
||||||
|
toast({
|
||||||
|
title: "Update Failed",
|
||||||
|
description: formatAxiosError(error, "Failed to update template rule. Please try again."),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -348,7 +379,7 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
name="action"
|
name="action"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Action</FormLabel>
|
<FormLabel>{t('rulesAction')}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Select
|
<Select
|
||||||
value={field.value}
|
value={field.value}
|
||||||
@@ -358,8 +389,10 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
<SelectValue />
|
<SelectValue />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="ACCEPT">Accept</SelectItem>
|
<SelectItem value="ACCEPT">
|
||||||
<SelectItem value="DROP">Drop</SelectItem>
|
{RuleAction.ACCEPT}
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem value="DROP">{RuleAction.DROP}</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -373,7 +406,7 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
name="match"
|
name="match"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Match</FormLabel>
|
<FormLabel>{t('rulesMatchType')}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Select
|
<Select
|
||||||
value={field.value}
|
value={field.value}
|
||||||
@@ -383,9 +416,9 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
<SelectValue />
|
<SelectValue />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="IP">IP</SelectItem>
|
<SelectItem value="PATH">{RuleMatch.PATH}</SelectItem>
|
||||||
<SelectItem value="CIDR">CIDR</SelectItem>
|
<SelectItem value="IP">{RuleMatch.IP}</SelectItem>
|
||||||
<SelectItem value="PATH">Path</SelectItem>
|
<SelectItem value="CIDR">{RuleMatch.CIDR}</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -399,7 +432,7 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
name="value"
|
name="value"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Value</FormLabel>
|
<FormLabel>{t('value')}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="Enter value" {...field} />
|
<Input placeholder="Enter value" {...field} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -413,7 +446,7 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
name="priority"
|
name="priority"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Priority (optional)</FormLabel>
|
<FormLabel>{t('rulesPriority')} (optional)</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
type="number"
|
type="number"
|
||||||
@@ -556,6 +589,19 @@ export function TemplateRulesManager({ templateId, orgId }: TemplateRulesManager
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Confirmation Dialog */}
|
||||||
|
<ConfirmationDialog
|
||||||
|
open={deleteDialogOpen}
|
||||||
|
onOpenChange={setDeleteDialogOpen}
|
||||||
|
title="Delete Template Rule"
|
||||||
|
description="Are you sure you want to delete this rule? This action will remove the rule from the template and from all assigned resources. This action cannot be undone."
|
||||||
|
confirmText="Delete Rule"
|
||||||
|
cancelText="Cancel"
|
||||||
|
variant="destructive"
|
||||||
|
onConfirm={confirmDeleteRule}
|
||||||
|
loading={deletingRule}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user