feat: Add settings overview page with getAllPolicySettings
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 1s
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 1s
- Add new /settings-overview route displaying all policy settings in table - Implement getAllPolicySettings() server action with tenant isolation - Add 'All Settings' navigation item with Database icon - Use date-fns for relative time display (lastSyncedAt) - Server-side rendering for optimal performance
This commit is contained in:
parent
8b36902767
commit
2592b89bc6
100
app/(app)/settings-overview/page.tsx
Normal file
100
app/(app)/settings-overview/page.tsx
Normal file
@ -0,0 +1,100 @@
|
||||
import { getAllPolicySettings } from '@/lib/actions/policySettings';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@/components/ui/table';
|
||||
import { formatDistanceToNow } from 'date-fns';
|
||||
import { de } from 'date-fns/locale';
|
||||
|
||||
export default async function SettingsOverviewPage() {
|
||||
const result = await getAllPolicySettings();
|
||||
|
||||
if (!result.success) {
|
||||
return (
|
||||
<main className="flex flex-1 flex-col gap-4 p-4 md:gap-8 md:p-8">
|
||||
<div className="mx-auto w-full max-w-6xl">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Policy Settings Overview</CardTitle>
|
||||
<CardDescription>
|
||||
{result.error || 'Failed to load settings'}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
const settings = result.data || [];
|
||||
|
||||
return (
|
||||
<main className="flex flex-1 flex-col gap-4 p-4 md:gap-8 md:p-8">
|
||||
<div className="mx-auto w-full max-w-6xl">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Policy Settings Overview</CardTitle>
|
||||
<CardDescription>
|
||||
{settings.length} policy setting{settings.length !== 1 ? 's' : ''} found
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{settings.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<p className="text-muted-foreground">No policy settings found</p>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
Try syncing your policies first
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Policy Name</TableHead>
|
||||
<TableHead>Policy Type</TableHead>
|
||||
<TableHead>Setting Name</TableHead>
|
||||
<TableHead>Setting Value</TableHead>
|
||||
<TableHead className="text-right">Last Synced</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{settings.map((setting) => (
|
||||
<TableRow key={setting.id}>
|
||||
<TableCell className="font-medium">
|
||||
{setting.policyName}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="inline-flex items-center rounded-md bg-blue-50 px-2 py-1 text-xs font-medium text-blue-700 ring-1 ring-inset ring-blue-700/10">
|
||||
{setting.policyType}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-xs">
|
||||
{setting.settingName}
|
||||
</TableCell>
|
||||
<TableCell className="max-w-md truncate">
|
||||
{setting.settingValue}
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-sm text-muted-foreground">
|
||||
{formatDistanceToNow(new Date(setting.lastSyncedAt), {
|
||||
addSuffix: true,
|
||||
locale: de,
|
||||
})}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import { SidebarLink } from "@/components/SidebarItems";
|
||||
import { Cog, Globe, User, HomeIcon, Search } from "lucide-react";
|
||||
import { Cog, Globe, User, HomeIcon, Search, Database } from "lucide-react";
|
||||
|
||||
type AdditionalLinks = {
|
||||
title: string;
|
||||
@ -9,6 +9,7 @@ type AdditionalLinks = {
|
||||
export const defaultLinks: SidebarLink[] = [
|
||||
{ href: "/dashboard", title: "Home", icon: HomeIcon },
|
||||
{ href: "/search", title: "Search", icon: Search },
|
||||
{ href: "/settings-overview", title: "All Settings", icon: Database },
|
||||
{ href: "/account", title: "Account", icon: User },
|
||||
{ href: "/settings", title: "Settings", icon: Cog },
|
||||
];
|
||||
|
||||
@ -33,6 +33,13 @@ export interface RecentSettingsResult {
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface AllSettingsResult {
|
||||
success: boolean;
|
||||
data?: PolicySettingSearchResult[];
|
||||
error?: string;
|
||||
totalCount?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search policy settings by keyword across settingName and settingValue
|
||||
*
|
||||
@ -207,6 +214,53 @@ export async function getRecentPolicySettings(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all policy settings for the current user's tenant
|
||||
*
|
||||
* **Security**: Enforces tenant isolation with explicit WHERE tenantId filter
|
||||
*
|
||||
* @returns All policy settings for user's tenant
|
||||
*/
|
||||
export async function getAllPolicySettings(): Promise<AllSettingsResult> {
|
||||
try {
|
||||
const { session } = await getUserAuth();
|
||||
|
||||
// T017: Explicit security check
|
||||
if (!session?.user) {
|
||||
return { success: false, error: 'Unauthorized' };
|
||||
}
|
||||
|
||||
// T017: Explicit security check
|
||||
const tenantId = session.user.tenantId;
|
||||
if (!tenantId) {
|
||||
return { success: false, error: 'Tenant not found' };
|
||||
}
|
||||
|
||||
// T017: Query filtered by tenantId for security
|
||||
const results = await db
|
||||
.select({
|
||||
id: policySettings.id,
|
||||
policyName: policySettings.policyName,
|
||||
policyType: policySettings.policyType,
|
||||
settingName: policySettings.settingName,
|
||||
settingValue: policySettings.settingValue,
|
||||
lastSyncedAt: policySettings.lastSyncedAt,
|
||||
})
|
||||
.from(policySettings)
|
||||
.where(eq(policySettings.tenantId, tenantId)) // CRITICAL: Tenant isolation
|
||||
.orderBy(desc(policySettings.lastSyncedAt));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: results,
|
||||
totalCount: results.length,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Get all settings failed:', error);
|
||||
return { success: false, error: 'Failed to fetch settings' };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TEMPORARY: Seed test data for the current user's tenant
|
||||
* This is a development helper to populate realistic policy settings
|
||||
|
||||
Loading…
Reference in New Issue
Block a user