feat(auth): enhance security and audit logging

- Integrate webhook alerts for admin login lockouts.
- Implement detailed audit logging for login, logout, and setup actions.
- Improve client revocation event tracking.
- Standardize error handling in profile updates.
- Enforce 'operator' role for event API access.
This commit is contained in:
Team Dark Devil committed 2026-11-21 00:06:55 +06:00
1 parent 5c977d6977
commit 8132087085
52 files changed
+4434 -407

No files matched your search

+8 -1
View File
@@ -32,7 +32,10 @@ interface AuditLogItem {
const ACTION_FILTER_OPTIONS = [
{ value: 'ALL', label: 'All Governance Actions' },
{ value: 'ADMIN_SETUP', label: 'ADMIN_SETUP' },
{ value: 'ADMIN_LOGIN', label: 'ADMIN_LOGIN' },
{ value: 'ADMIN_LOGOUT', label: 'ADMIN_LOGOUT' },
{ value: 'ADMIN_PROFILE_UPDATED', label: 'ADMIN_PROFILE_UPDATED' },
{ value: 'ADMIN_PASSWORD_UPDATED', label: 'ADMIN_PASSWORD_UPDATED' },
{ value: 'TEAM_MEMBER_CREATED', label: 'TEAM_MEMBER_CREATED' },
{ value: 'TEAM_MEMBER_UPDATED', label: 'TEAM_MEMBER_UPDATED' },
@@ -40,9 +43,11 @@ const ACTION_FILTER_OPTIONS = [
{ value: 'TEAM_MEMBER_DELETED', label: 'TEAM_MEMBER_DELETED' },
{ value: 'CLIENT_CREATED', label: 'CLIENT_CREATED' },
{ value: 'CLIENT_UPDATED', label: 'CLIENT_UPDATED' },
{ value: 'CLIENT_REVOKED', label: 'CLIENT_REVOKED' },
{ value: 'CLIENT_TOKEN_ROTATED', label: 'CLIENT_TOKEN_ROTATED' },
{ value: 'CLIENT_DELETED', label: 'CLIENT_DELETED' },
{ value: 'SETTINGS_UPDATED', label: 'SETTINGS_UPDATED' },
{ value: 'STORAGE_FLUSH_TRIGGERED', label: 'STORAGE_FLUSH_TRIGGERED' },
{ value: 'S3_ARCHIVE_TRIGGERED', label: 'S3_ARCHIVE_TRIGGERED' },
{ value: 'WEBHOOK_TEST_TRIGGERED', label: 'WEBHOOK_TEST_TRIGGERED' },
];
@@ -90,7 +95,9 @@ export function AuditLogViewer() {
}, [fetchAuditLogs]);
const uniqueActors = new Set(logs.map((l) => l.actorEmail)).size;
const mutationCount = logs.filter((l) => l.action !== 'ADMIN_LOGIN').length;
const mutationCount = logs.filter(
(l) => l.action !== 'ADMIN_LOGIN' && l.action !== 'ADMIN_LOGOUT',
).length;
return (
<PageShell
+66 -54
View File
@@ -14,7 +14,12 @@ import {
TableRow,
TableWrap,
} from '@/components/ui/Table';
import { useVconRole } from '@/components/layout/VconShell';
import { useToast } from '@/components/ui/Toast';
import {
formatDateForLocalInput,
getVconRoleCapabilities,
} from '@/lib/vconUiHelpers';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import type { ClientCredentials, ClientItem } from './clients/types';
@@ -22,6 +27,7 @@ import type { ClientCredentials, ClientItem } from './clients/types';
interface ClientsTableProps {
clients: ClientItem[];
now: number;
canManage?: boolean;
onStatusChange: () => Promise<void>;
}
@@ -35,9 +41,19 @@ function relativeTime(timestamp: string | undefined, now: number) {
return `${Math.floor(seconds / 86_400)}d ago`;
}
export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps) {
export function ClientsTable({
clients,
now,
canManage,
onStatusChange,
}: ClientsTableProps) {
const router = useRouter();
const { success, error } = useToast();
const currentRole = useVconRole();
const allowMutations =
canManage !== undefined
? canManage
: getVconRoleCapabilities(currentRole).canOperate;
const [credentials, setCredentials] = useState<ClientCredentials | null>(null);
const [confirmAction, setConfirmAction] = useState<{
type: 'rotate' | 'revoke' | 'delete';
@@ -59,21 +75,13 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
};
const openEditModal = (client: ClientItem) => {
if (!allowMutations) return;
setEditClient(client);
setEditName(client.name);
setEditRateLimit(String(client.rateLimit || 100));
setEditStorageQuotaMb(String(client.storageQuotaMb ?? 0));
setEditAllowedIps(client.allowedIps || '');
if (client.expiresAt) {
const parsedDate = new Date(client.expiresAt);
setEditExpiresAt(
!Number.isNaN(parsedDate.getTime())
? parsedDate.toISOString().slice(0, 16)
: '',
);
} else {
setEditExpiresAt('');
}
setEditExpiresAt(formatDateForLocalInput(client.expiresAt));
setEditError('');
};
@@ -339,49 +347,53 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
aria-label={`View events for ${client.clientId}`}
onClick={() => router.push(`/vcon/data?clientId=${encodeURIComponent(client.clientId)}`)}
/>
<Button
type="button"
variant="icon"
size="icon"
icon="Pencil"
className="h-6 w-6 border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
title={`Edit ${client.clientId}`}
aria-label={`Edit ${client.clientId}`}
onClick={() => openEditModal(client)}
/>
<Button
type="button"
variant="icon"
size="icon"
icon="RefreshCw"
className="h-6 w-6 border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
title={`Rotate key for ${client.clientId}`}
aria-label={`Rotate key for ${client.clientId}`}
onClick={() => setConfirmAction({ type: 'rotate', client })}
/>
<Button
type="button"
variant="icon"
size="icon"
icon={client.status === 'active' ? 'ShieldOff' : 'ShieldCheck'}
className={`h-6 w-6 border border-transparent ${client.status === 'active' ? 'hover:border-[var(--warning)] hover:text-[var(--warning)]' : 'hover:border-[var(--border)] hover:bg-[var(--surface-2)]'}`}
title={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
aria-label={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
onClick={() => toggleStatus(client)}
/>
<Button
type="button"
variant="icon"
size="icon"
icon="Trash2"
className="h-6 w-6 border border-transparent hover:border-[var(--danger)] hover:text-[var(--danger)]"
title={`Delete ${client.clientId}`}
aria-label={`Delete ${client.clientId}`}
onClick={() => {
setPurgeFilesOnDelete(false);
setConfirmAction({ type: 'delete', client });
}}
/>
{allowMutations && (
<>
<Button
type="button"
variant="icon"
size="icon"
icon="Pencil"
className="h-6 w-6 border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
title={`Edit ${client.clientId}`}
aria-label={`Edit ${client.clientId}`}
onClick={() => openEditModal(client)}
/>
<Button
type="button"
variant="icon"
size="icon"
icon="RefreshCw"
className="h-6 w-6 border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
title={`Rotate key for ${client.clientId}`}
aria-label={`Rotate key for ${client.clientId}`}
onClick={() => setConfirmAction({ type: 'rotate', client })}
/>
<Button
type="button"
variant="icon"
size="icon"
icon={client.status === 'active' ? 'ShieldOff' : 'ShieldCheck'}
className={`h-6 w-6 border border-transparent ${client.status === 'active' ? 'hover:border-[var(--warning)] hover:text-[var(--warning)]' : 'hover:border-[var(--border)] hover:bg-[var(--surface-2)]'}`}
title={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
aria-label={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
onClick={() => toggleStatus(client)}
/>
<Button
type="button"
variant="icon"
size="icon"
icon="Trash2"
className="h-6 w-6 border border-transparent hover:border-[var(--danger)] hover:text-[var(--danger)]"
title={`Delete ${client.clientId}`}
aria-label={`Delete ${client.clientId}`}
onClick={() => {
setPurgeFilesOnDelete(false);
setConfirmAction({ type: 'delete', client });
}}
/>
</>
)}
</div>
</TableCell>
</TableRow>
+20 -6
View File
@@ -1,6 +1,7 @@
'use client';
import { PageShell } from '@/components/layout/PageShell';
import { useVconRole } from '@/components/layout/VconShell';
import { Button } from '@/components/ui/Button';
import { ClientList, type ClientListItem } from '@/components/ui/ClientList';
import { Panel } from '@/components/ui/Panel';
@@ -21,6 +22,8 @@ import {
countMatchingBufferedEvents,
extractContentDispositionFilename,
formatEventTimeLabel,
getVconRoleCapabilities,
isUiClientExpired,
type BufferedSummary,
} from '@/lib/vconUiHelpers';
import Link from 'next/link';
@@ -36,6 +39,7 @@ type EventItem = {
type DashboardMetrics = {
activeSockets?: number;
activeClients: number;
expiredClients?: number;
totalClients: number;
bufferStats: {
currentBufferSize: number;
@@ -65,6 +69,8 @@ type StorageFile = {
export const DashboardOverview: React.FC = () => {
const { error, info } = useToast();
const currentRole = useVconRole();
const { canOperate } = getVconRoleCapabilities(currentRole);
const [metrics, setMetrics] = useState<DashboardMetrics | null>(() =>
getCached<DashboardMetrics | null>('vcon:metrics', null)
);
@@ -179,7 +185,13 @@ export const DashboardOverview: React.FC = () => {
const eventsToday = storedRecordsToday + bufferedTodayCount;
const activeClients =
metrics?.activeClients ??
clients.filter((client) => client.status === 'active').length;
clients.filter(
(client) =>
client.status === 'active' &&
!isUiClientExpired(
(client as ClientListItem & { expiresAt?: string | null }).expiresAt,
),
).length;
const totalClients = metrics?.totalClients ?? clients.length;
const activeSockets = metrics?.activeSockets ?? 0;
const bridgeStatus = metrics?.runtime?.ingestionBridgeStatus;
@@ -263,11 +275,13 @@ export const DashboardOverview: React.FC = () => {
>
Export
</Button>
<Link href="/vcon/clients">
<Button size="xs" variant="primary" icon="Plus">
New client
</Button>
</Link>
{canOperate && (
<Link href="/vcon/clients">
<Button size="xs" variant="primary" icon="Plus">
New client
</Button>
</Link>
)}
</>
}
>
+9 -3
View File
@@ -31,6 +31,7 @@ interface StorageFile {
sizeBytes: number;
linesCount: number;
modifiedAt: string;
compressed?: boolean;
}
type ExportFormat = 'csv' | 'json' | 'ndjson';
@@ -487,13 +488,17 @@ export function ExportWorkspace() {
No files
</p>
) : (
sortedRecentFiles.map((file) => (
sortedRecentFiles.map((file) => {
const isCompressed = Boolean(
file.compressed || file.filename.toLowerCase().endsWith('.csv.gz')
);
return (
<div
key={`${file.clientId}/${file.filename}`}
className="flex items-center gap-2 px-3 py-2 transition-colors hover:bg-[var(--surface-2)]"
>
<span className="shrink-0 border border-[var(--border-strong)] px-1 py-0.5 font-mono text-[9px] uppercase tracking-wider text-[var(--text-muted)]">
CSV
{isCompressed ? 'CSV.GZ' : 'CSV'}
</span>
<div className="min-w-0 flex-1">
<div className="truncate font-mono text-[11.5px] text-[var(--text)]">
@@ -516,7 +521,8 @@ export function ExportWorkspace() {
onClick={() => downloadFile(file)}
/>
</div>
))
);
})
)}
</Panel>
</div>
+79 -12
View File
@@ -1,6 +1,7 @@
'use client';
import { PageShell } from '@/components/layout/PageShell';
import { useVconRole } from '@/components/layout/VconShell';
import { Button } from '@/components/ui/Button';
import { FormSwitch } from '@/components/ui/Form';
import { Input } from '@/components/ui/Input';
@@ -22,6 +23,7 @@ import {
DEFAULT_S3_SETTINGS,
describeSettingsBridgeSync,
type EditableSettings,
getVconRoleCapabilities,
mapBridgeStatusToSocketUiState,
normalizeAlertingSettings,
normalizeEditableSettings,
@@ -56,11 +58,12 @@ interface PublicSettings
}
interface DiskUsageSummary {
available: boolean;
available?: boolean;
usedPct: number;
freeBytes: number;
freeBytes?: number;
availableBytes?: number;
totalBytes: number;
checkedAt?: string;
checkedAt?: string | number;
}
const TABS = [
@@ -90,6 +93,8 @@ function formatGiB(bytes: number): string {
}
export function SettingsWorkspace() {
const currentRole = useVconRole();
const { canAdminSettings, canOperate } = getVconRoleCapabilities(currentRole);
const { success, warning, error } = useToast();
const [savedSettings, setSavedSettings] = useState<EditableSettings>(() =>
normalizeEditableSettings(
@@ -333,7 +338,20 @@ export function SettingsWorkspace() {
)
);
if (storageData.diskUsage && typeof storageData.diskUsage === 'object') {
setDiskUsage(storageData.diskUsage as DiskUsageSummary);
const rawDisk = storageData.diskUsage as DiskUsageSummary;
const totalBytes = Number(rawDisk.totalBytes) || 0;
const freeBytes = Number(rawDisk.freeBytes ?? rawDisk.availableBytes) || 0;
setDiskUsage({
...rawDisk,
available:
rawDisk.available !== undefined
? Boolean(rawDisk.available)
: totalBytes > 0,
usedPct: Number(rawDisk.usedPct) || 0,
freeBytes,
availableBytes: freeBytes,
totalBytes,
});
}
if (metricsData) {
setActiveSockets(Number(metricsData.activeSockets) || 0);
@@ -535,6 +553,7 @@ export function SettingsWorkspace() {
};
const handleTestWebhookAlert = async () => {
if (!canAdminSettings) return;
setTestingWebhook(true);
setWebhookTestStatus(null);
try {
@@ -574,6 +593,7 @@ export function SettingsWorkspace() {
};
const handleTestS3Connection = async () => {
if (!canAdminSettings) return;
setTestingS3(true);
setS3ActionStatus(null);
try {
@@ -617,6 +637,7 @@ export function SettingsWorkspace() {
};
const handleArchiveNow = async () => {
if (!canOperate) return;
if (s3ConfigDirty) {
warning('Unsaved S3 settings', 'Save your S3 credentials before archiving.');
return;
@@ -657,6 +678,7 @@ export function SettingsWorkspace() {
const handleFormSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
if (!canAdminSettings) return;
const validation = validateEditableSettingsDraft(
numericDrafts,
enableIdempotency
@@ -787,6 +809,15 @@ export function SettingsWorkspace() {
]}
/>
{!canAdminSettings && (
<div
role="status"
className="border border-[var(--border)] bg-[var(--surface-2)] px-3 py-2 text-[12px] text-[var(--text-muted)]"
>
Read-only configuration ({currentRole}) — only owners can modify platform settings, credentials, or run credential diagnostics.
</div>
)}
<div className="w-full">
<SettingsTabs
items={TABS}
@@ -827,6 +858,7 @@ export function SettingsWorkspace() {
type="number"
min={SETTINGS_LIMITS.maxEventsPerSec.min}
max={SETTINGS_LIMITS.maxEventsPerSec.max}
disabled={!canAdminSettings}
value={numericDrafts.maxEventsPerSec}
error={fieldErrors.maxEventsPerSec}
onChange={(event) =>
@@ -838,6 +870,7 @@ export function SettingsWorkspace() {
<FormSwitch
label="Deduplicate events"
checked={enableIdempotency}
disabled={!canAdminSettings}
onChange={setEnableIdempotency}
/>
</SettingsField>
@@ -916,6 +949,7 @@ export function SettingsWorkspace() {
type="number"
min={SETTINGS_LIMITS.batchFlushThreshold.min}
max={SETTINGS_LIMITS.batchFlushThreshold.max}
disabled={!canAdminSettings}
value={numericDrafts.batchFlushThreshold}
error={fieldErrors.batchFlushThreshold}
onChange={(event) =>
@@ -930,6 +964,7 @@ export function SettingsWorkspace() {
min={SETTINGS_LIMITS.batchFlushIntervalMs.min}
max={SETTINGS_LIMITS.batchFlushIntervalMs.max}
suffix="ms"
disabled={!canAdminSettings}
value={numericDrafts.batchFlushIntervalMs}
error={fieldErrors.batchFlushIntervalMs}
onChange={(event) =>
@@ -963,7 +998,7 @@ export function SettingsWorkspace() {
</span>
{diskUsage?.available && (
<span className="text-[10.5px] text-[var(--text-muted)]">
{formatGiB(diskUsage.freeBytes)} free /{' '}
{formatGiB(diskUsage.freeBytes ?? diskUsage.availableBytes ?? 0)} free /{' '}
{formatGiB(diskUsage.totalBytes)}
</span>
)}
@@ -995,6 +1030,7 @@ export function SettingsWorkspace() {
min={SETTINGS_LIMITS.fileRotationMb.min}
max={SETTINGS_LIMITS.fileRotationMb.max}
suffix="MB"
disabled={!canAdminSettings}
value={numericDrafts.fileRotationMb}
error={fieldErrors.fileRotationMb}
onChange={(event) =>
@@ -1010,6 +1046,7 @@ export function SettingsWorkspace() {
min={SETTINGS_LIMITS.autoPruneDays.min}
max={SETTINGS_LIMITS.autoPruneDays.max}
suffix="days"
disabled={!canAdminSettings}
value={numericDrafts.autoPruneDays}
error={fieldErrors.autoPruneDays}
onChange={(event) =>
@@ -1025,6 +1062,7 @@ export function SettingsWorkspace() {
min={SETTINGS_LIMITS.compressAfterDays.min}
max={SETTINGS_LIMITS.compressAfterDays.max}
suffix="days"
disabled={!canAdminSettings}
value={numericDrafts.compressAfterDays}
error={fieldErrors.compressAfterDays}
onChange={(event) =>
@@ -1040,6 +1078,7 @@ export function SettingsWorkspace() {
min={SETTINGS_LIMITS.diskPauseThresholdPct.min}
max={SETTINGS_LIMITS.diskPauseThresholdPct.max}
suffix="%"
disabled={!canAdminSettings}
value={numericDrafts.diskPauseThresholdPct}
error={fieldErrors.diskPauseThresholdPct}
onChange={(event) =>
@@ -1055,6 +1094,7 @@ export function SettingsWorkspace() {
<FormSwitch
label="Enable off-site S3 / R2 backup"
checked={s3Draft.enableS3Backup}
disabled={!canAdminSettings}
onChange={(checked) =>
setS3Draft((prev) => ({ ...prev, enableS3Backup: checked }))
}
@@ -1064,6 +1104,7 @@ export function SettingsWorkspace() {
<Input
compact
placeholder="https://<account>.r2.cloudflarestorage.com"
disabled={!canAdminSettings}
value={s3Draft.s3Endpoint}
onChange={(event) =>
setS3Draft((prev) => ({
@@ -1078,6 +1119,7 @@ export function SettingsWorkspace() {
<Input
compact
placeholder="auto"
disabled={!canAdminSettings}
value={s3Draft.s3Region}
onChange={(event) =>
setS3Draft((prev) => ({
@@ -1092,6 +1134,7 @@ export function SettingsWorkspace() {
<Input
compact
placeholder="my-datastack-archive"
disabled={!canAdminSettings}
value={s3Draft.s3Bucket}
onChange={(event) =>
setS3Draft((prev) => ({
@@ -1106,6 +1149,7 @@ export function SettingsWorkspace() {
<Input
compact
placeholder="datastack/"
disabled={!canAdminSettings}
value={s3Draft.s3Prefix}
onChange={(event) =>
setS3Draft((prev) => ({
@@ -1120,6 +1164,7 @@ export function SettingsWorkspace() {
<Input
compact
placeholder="AKIA... / R2 Access Key ID"
disabled={!canAdminSettings}
value={s3Draft.s3AccessKeyId}
onChange={(event) =>
setS3Draft((prev) => ({
@@ -1136,6 +1181,7 @@ export function SettingsWorkspace() {
compact
type="password"
autoComplete="new-password"
disabled={!canAdminSettings}
value={s3SecretAccessKey}
onChange={(event) => {
setS3SecretAccessKey(event.target.value);
@@ -1155,6 +1201,7 @@ export function SettingsWorkspace() {
type="button"
size="xs"
variant={clearS3SecretKey ? 'danger' : 'ghost'}
disabled={!canAdminSettings}
onClick={() => {
setClearS3SecretKey((prev) => !prev);
setS3SecretAccessKey('');
@@ -1174,7 +1221,7 @@ export function SettingsWorkspace() {
variant="secondary"
icon="Plug"
loading={testingS3}
disabled={testingS3 || archivingNow}
disabled={!canAdminSettings || testingS3 || archivingNow}
onClick={() => void handleTestS3Connection()}
>
Test S3 Connection
@@ -1185,7 +1232,7 @@ export function SettingsWorkspace() {
variant="secondary"
icon="UploadCloud"
loading={archivingNow}
disabled={testingS3 || archivingNow || s3ConfigDirty}
disabled={!canOperate || testingS3 || archivingNow || s3ConfigDirty}
onClick={() => void handleArchiveNow()}
>
Archive Now
@@ -1233,6 +1280,7 @@ export function SettingsWorkspace() {
compact
type="password"
autoComplete="new-password"
disabled={!canAdminSettings}
value={jwtSecret}
error={jwtError}
onChange={(event) => {
@@ -1252,6 +1300,7 @@ export function SettingsWorkspace() {
min={SETTINGS_LIMITS.maxPayloadSizeKb.min}
max={SETTINGS_LIMITS.maxPayloadSizeKb.max}
suffix="KB"
disabled={!canAdminSettings}
value={numericDrafts.maxPayloadSizeKb}
error={fieldErrors.maxPayloadSizeKb}
onChange={(event) =>
@@ -1267,6 +1316,7 @@ export function SettingsWorkspace() {
<FormSwitch
label="Enable webhook alerts (Slack / Discord / JSON)"
checked={alertingDraft.enableWebhookAlerts}
disabled={!canAdminSettings}
onChange={(checked) =>
setAlertingDraft((prev) => ({
...prev,
@@ -1279,6 +1329,7 @@ export function SettingsWorkspace() {
<Input
compact
placeholder="https://hooks.slack.com/services/..."
disabled={!canAdminSettings}
value={alertingDraft.webhookUrl}
onChange={(event) =>
setAlertingDraft((prev) => ({
@@ -1295,6 +1346,7 @@ export function SettingsWorkspace() {
compact
type="password"
autoComplete="new-password"
disabled={!canAdminSettings}
value={webhookSecret}
onChange={(event) => {
setWebhookSecret(event.target.value);
@@ -1314,6 +1366,7 @@ export function SettingsWorkspace() {
type="button"
size="xs"
variant={clearWebhookSecret ? 'danger' : 'ghost'}
disabled={!canAdminSettings}
onClick={() => {
setClearWebhookSecret((prev) => !prev);
setWebhookSecret('');
@@ -1331,6 +1384,7 @@ export function SettingsWorkspace() {
min={SETTINGS_LIMITS.webhookCooldownSec.min}
max={SETTINGS_LIMITS.webhookCooldownSec.max}
suffix="sec"
disabled={!canAdminSettings}
value={numericDrafts.webhookCooldownSec}
error={fieldErrors.webhookCooldownSec}
onChange={(event) =>
@@ -1348,7 +1402,7 @@ export function SettingsWorkspace() {
variant="secondary"
icon="Bell"
loading={testingWebhook}
disabled={testingWebhook}
disabled={!canAdminSettings || testingWebhook}
onClick={() => void handleTestWebhookAlert()}
>
Send Test Alert
@@ -1375,6 +1429,7 @@ export function SettingsWorkspace() {
<FormSwitch
label="Enable /api/prometheus scrape endpoint"
checked={alertingDraft.enablePrometheusMetrics}
disabled={!canAdminSettings}
onChange={(checked) =>
setAlertingDraft((prev) => ({
...prev,
@@ -1397,6 +1452,7 @@ export function SettingsWorkspace() {
compact
type="password"
autoComplete="new-password"
disabled={!canAdminSettings}
value={prometheusMetricsToken}
onChange={(event) => {
setPrometheusMetricsToken(event.target.value);
@@ -1416,6 +1472,7 @@ export function SettingsWorkspace() {
type="button"
size="xs"
variant={clearPrometheusToken ? 'danger' : 'ghost'}
disabled={!canAdminSettings}
onClick={() => {
setClearPrometheusToken((prev) => !prev);
setPrometheusMetricsToken('');
@@ -1435,11 +1492,21 @@ export function SettingsWorkspace() {
<>
<span
className={`h-1.5 w-1.5 ${
isDirty ? 'bg-[var(--warning)]' : 'bg-[var(--accent)]'
!canAdminSettings
? 'bg-[var(--text-faint)]'
: isDirty
? 'bg-[var(--warning)]'
: 'bg-[var(--accent)]'
}`}
/>
<span>
{loading ? 'Loading' : isDirty ? 'Unsaved changes' : 'Saved'}
{loading
? 'Loading'
: !canAdminSettings
? `Read-only (${currentRole})`
: isDirty
? 'Unsaved changes'
: 'Saved'}
</span>
</>
}
@@ -1447,7 +1514,7 @@ export function SettingsWorkspace() {
<Button
type="button"
size="xs"
disabled={!isDirty || saving}
disabled={!canAdminSettings || !isDirty || saving}
onClick={discardChanges}
>
Discard
@@ -1458,7 +1525,7 @@ export function SettingsWorkspace() {
size="xs"
icon="Save"
loading={saving}
disabled={loading || !isDirty}
disabled={!canAdminSettings || loading || !isDirty}
>
Save
</Button>