@rapidmx/web-client 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/admin/audit-log/index.tsx +35 -8
- package/apps/admin/data-requests/index.tsx +480 -485
- package/apps/admin/distribution-lists/[uid].tsx +19 -1
- package/apps/admin/escrow-scopes/[uid].tsx +348 -237
- package/apps/admin/escrow-scopes/new/index.tsx +8 -2
- package/apps/admin/index.tsx +19 -1
- package/apps/admin/ingest-queue/index.tsx +44 -5
- package/apps/admin/mailboxes/[uid].tsx +211 -184
- package/apps/admin/quarantine/index.tsx +46 -14
- package/apps/admin/transport-rules/[uid].tsx +30 -1
- package/apps/admin/transport-rules/_transportRuleConfig.tsx +38 -2
- package/apps/admin/transport-rules/index.tsx +24 -6
- package/apps/admin/transport-rules/new/index.tsx +30 -1
- package/apps/escrow/_layout.tsx +2 -3
- package/apps/escrow/audit-log/index.tsx +196 -168
- package/apps/escrow/matters/[uid].tsx +621 -521
- package/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.tsx +22 -1
- package/apps/shared/components/admin/layout/AdminShell.tsx +3 -1
- package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -0
- package/apps/shared/components/admin/mailboxes/ResourceSettingsCard.tsx +3 -3
- package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +55 -11
- package/apps/shared/components/admin/settings/BrandingForm.tsx +15 -4
- package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +18 -7
- package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +10 -2
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +6 -0
- package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +45 -12
- package/apps/shared/components/admin/settings/PluginsManager.tsx +1235 -595
- package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +174 -98
- package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +49 -13
- package/apps/shared/components/admin/setup/SetupWizard.tsx +150 -34
- package/apps/shared/components/admin/signOut.ts +79 -0
- package/apps/shared/components/admin/usePagedList.tsx +129 -0
- package/apps/shared/components/calendar/EventModal.tsx +717 -549
- package/apps/shared/components/calendar/MonthView.tsx +173 -139
- package/apps/shared/components/calendar/RecurrenceEditor.tsx +222 -180
- package/apps/shared/components/calendar/SplitDayView.tsx +143 -137
- package/apps/shared/components/calendar/TimeGridView.tsx +244 -198
- package/apps/shared/components/calendar/allDay.ts +124 -0
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +1 -1
- package/apps/shared/components/contacts/ContactDetailPane.tsx +100 -21
- package/apps/shared/components/contacts/ContactForm.tsx +377 -348
- package/apps/shared/components/contacts/ContactsSidebar.tsx +6 -2
- package/apps/shared/components/contacts/KeyChangeReview.tsx +192 -0
- package/apps/shared/components/contacts/contactKeys.ts +78 -0
- package/apps/shared/components/escrow/layout/EscrowShell.tsx +148 -134
- package/apps/shared/components/layout/AppShell.tsx +87 -15
- package/apps/shared/components/layout/BrandingChrome.tsx +48 -10
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +389 -298
- package/apps/shared/components/layout/MailboxProvisioning.tsx +19 -3
- package/apps/shared/components/layout/RecoveryCodeUnlock.tsx +350 -0
- package/apps/shared/components/layout/UnlockPromptProvider.tsx +257 -128
- package/apps/shared/components/mail/ConversationThreadPane.tsx +216 -181
- package/apps/shared/components/mail/MessageDetailPane.tsx +1318 -630
- package/apps/shared/components/mail/compose/ComposeContext.tsx +20 -15
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +854 -132
- package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +12 -2
- package/apps/shared/components/mail/pinnedSigners.ts +124 -0
- package/apps/shared/components/mail/verificationSeals.ts +125 -0
- package/apps/shared/components/mail/writableMailboxes.ts +101 -0
- package/apps/shared/components/rules/RuleBuilder.tsx +311 -276
- package/apps/shared/mail/listAllPages.ts +39 -0
- package/apps/shared/search/LocalIndexLifecycle.tsx +64 -55
- package/apps/shared/search/localIndexBuilder.ts +481 -179
- package/apps/shared/search/localIndexRpcClient.ts +228 -28
- package/apps/shared/search/localIndexSchema.ts +15 -6
- package/apps/shared/search/localIndexStorage.ts +98 -0
- package/apps/shared/search/localIndexVFS.ts +32 -1
- package/apps/shared/search/localIndexWorker.ts +648 -186
- package/apps/www/calendar/index.tsx +438 -417
- package/apps/www/contacts/[uid].tsx +21 -2
- package/apps/www/contacts/index.tsx +116 -12
- package/apps/www/index.tsx +1314 -1041
- package/apps/www/messages/[uid].tsx +18 -6
- package/apps/www/settings/auto-reply/index.tsx +134 -129
- package/apps/www/settings/booking-types/[uid].tsx +306 -300
- package/apps/www/settings/encryption/index.tsx +739 -216
- package/apps/www/settings/filters/[uid].tsx +171 -155
- package/apps/www/settings/filters/new/index.tsx +8 -1
- package/apps/www/settings/focused-inbox/index.tsx +150 -148
- package/apps/www/settings/privacy/index.tsx +494 -436
- package/apps/www/settings/read-receipts/index.tsx +148 -125
- package/apps/www/settings/sharing/index.tsx +17 -14
- package/apps/www/tasks/index.tsx +638 -579
- package/dist/apps/admin/audit-log/index.js +38 -8
- package/dist/apps/admin/data-requests/index.js +52 -72
- package/dist/apps/admin/distribution-lists/[uid].js +1 -1
- package/dist/apps/admin/escrow-scopes/[uid].js +91 -12
- package/dist/apps/admin/escrow-scopes/new/index.js +8 -3
- package/dist/apps/admin/index.js +4 -1
- package/dist/apps/admin/ingest-queue/index.js +24 -6
- package/dist/apps/admin/mailboxes/[uid].js +20 -4
- package/dist/apps/admin/quarantine/index.js +20 -11
- package/dist/apps/admin/transport-rules/[uid].js +18 -2
- package/dist/apps/admin/transport-rules/_transportRuleConfig.js +19 -0
- package/dist/apps/admin/transport-rules/index.js +22 -6
- package/dist/apps/admin/transport-rules/new/index.js +18 -2
- package/dist/apps/escrow/_layout.js +3 -3
- package/dist/apps/escrow/audit-log/index.js +26 -1
- package/dist/apps/escrow/matters/[uid].js +77 -42
- package/dist/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.js +11 -2
- package/dist/apps/shared/components/admin/layout/AdminShell.js +3 -1
- package/dist/apps/shared/components/admin/mailboxes/EscrowScopeCard.js +72 -0
- package/dist/apps/shared/components/admin/mailboxes/ResourceSettingsCard.js +3 -3
- package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +22 -4
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +15 -4
- package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +13 -7
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +7 -2
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +6 -0
- package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.js +34 -12
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +390 -78
- package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.js +40 -11
- package/dist/apps/shared/components/admin/setup/EscrowSetupStep.js +29 -13
- package/dist/apps/shared/components/admin/setup/SetupWizard.js +87 -21
- package/dist/apps/shared/components/admin/signOut.js +75 -0
- package/dist/apps/shared/components/admin/usePagedList.js +99 -0
- package/dist/apps/shared/components/calendar/EventModal.js +142 -21
- package/dist/apps/shared/components/calendar/MonthView.js +12 -5
- package/dist/apps/shared/components/calendar/RecurrenceEditor.js +40 -5
- package/dist/apps/shared/components/calendar/SplitDayView.js +10 -4
- package/dist/apps/shared/components/calendar/TimeGridView.js +23 -7
- package/dist/apps/shared/components/calendar/allDay.js +111 -0
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +1 -1
- package/dist/apps/shared/components/contacts/ContactDetailPane.js +43 -5
- package/dist/apps/shared/components/contacts/ContactForm.js +32 -10
- package/dist/apps/shared/components/contacts/ContactsSidebar.js +2 -2
- package/dist/apps/shared/components/contacts/KeyChangeReview.js +63 -0
- package/dist/apps/shared/components/contacts/contactKeys.js +64 -0
- package/dist/apps/shared/components/escrow/layout/EscrowShell.js +24 -5
- package/dist/apps/shared/components/layout/AppShell.js +83 -14
- package/dist/apps/shared/components/layout/BrandingChrome.js +45 -10
- package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +49 -12
- package/dist/apps/shared/components/layout/MailboxProvisioning.js +10 -2
- package/dist/apps/shared/components/layout/RecoveryCodeUnlock.js +174 -0
- package/dist/apps/shared/components/layout/UnlockPromptProvider.js +73 -14
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +50 -12
- package/dist/apps/shared/components/mail/MessageDetailPane.js +441 -36
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +9 -6
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +699 -128
- package/dist/apps/shared/components/mail/compose/composeFlushRegistry.js +50 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +12 -3
- package/dist/apps/shared/components/mail/pinnedSigners.js +98 -0
- package/dist/apps/shared/components/mail/verificationSeals.js +112 -0
- package/dist/apps/shared/components/mail/writableMailboxes.js +87 -0
- package/dist/apps/shared/components/rules/RuleBuilder.js +34 -6
- package/dist/apps/shared/mail/listAllPages.js +25 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.js +58 -54
- package/dist/apps/shared/search/localIndexBuilder.js +292 -37
- package/dist/apps/shared/search/localIndexRpcClient.js +188 -25
- package/dist/apps/shared/search/localIndexSchema.js +12 -6
- package/dist/apps/shared/search/localIndexStorage.js +86 -0
- package/dist/apps/shared/search/localIndexVFS.js +68 -40
- package/dist/apps/shared/search/localIndexWorker.js +519 -173
- package/dist/apps/www/calendar/index.js +28 -10
- package/dist/apps/www/contacts/[uid].js +13 -2
- package/dist/apps/www/contacts/index.js +80 -10
- package/dist/apps/www/index.js +339 -108
- package/dist/apps/www/messages/[uid].js +18 -6
- package/dist/apps/www/settings/auto-reply/index.js +9 -4
- package/dist/apps/www/settings/booking-types/[uid].js +17 -12
- package/dist/apps/www/settings/encryption/index.js +514 -97
- package/dist/apps/www/settings/filters/[uid].js +22 -7
- package/dist/apps/www/settings/filters/new/index.js +8 -2
- package/dist/apps/www/settings/focused-inbox/index.js +3 -1
- package/dist/apps/www/settings/privacy/index.js +57 -22
- package/dist/apps/www/settings/read-receipts/index.js +10 -3
- package/dist/apps/www/settings/sharing/index.js +7 -11
- package/dist/apps/www/tasks/index.js +50 -10
- package/package.json +2 -2
|
@@ -31,6 +31,8 @@ export interface EscrowScopeKeyAndHoldersFieldsProps {
|
|
|
31
31
|
value: EscrowScopeKeyAndHoldersValue;
|
|
32
32
|
onChange: (value: EscrowScopeKeyAndHoldersValue) => void;
|
|
33
33
|
disabled?: boolean;
|
|
34
|
+
/** Shows the public key fields without letting them be edited, e.g. for keys generated in the browser. */
|
|
35
|
+
keyReadOnly?: boolean;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/** Builds an all-zeroes starting point for the "new" page — `notBefore`/`notAfter` default to "now" so an
|
|
@@ -49,7 +51,21 @@ export function emptyEscrowScopeKeyAndHoldersValue(): EscrowScopeKeyAndHoldersVa
|
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
/** The message shown when an administrator tries to make themselves a holder: whoever configures a scope must not
|
|
55
|
+
* also be able to approve access under it (separation of duties - the server refuses it too). Holders who were
|
|
56
|
+
* already on the scope (`existingHolderUserUids`) aren't treated as newly added. */
|
|
57
|
+
export function selfAsHolderError(
|
|
58
|
+
holderUserUids: string[],
|
|
59
|
+
adminUid: string | undefined,
|
|
60
|
+
existingHolderUserUids: string[] = [],
|
|
61
|
+
): string | null {
|
|
62
|
+
if (!adminUid || !holderUserUids.includes(adminUid) || existingHolderUserUids.includes(adminUid)) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return "You can't add yourself as a holder of an escrow scope you configure. Ask another administrator to add you, or choose different holders.";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default function EscrowScopeKeyAndHoldersFields({ value, onChange, disabled, keyReadOnly }: EscrowScopeKeyAndHoldersFieldsProps) {
|
|
53
69
|
function set<K extends keyof EscrowScopeKeyAndHoldersValue>(key: K, next: EscrowScopeKeyAndHoldersValue[K]) {
|
|
54
70
|
onChange({ ...value, [key]: next });
|
|
55
71
|
}
|
|
@@ -70,6 +86,7 @@ export default function EscrowScopeKeyAndHoldersFields({ value, onChange, disabl
|
|
|
70
86
|
rows={4}
|
|
71
87
|
value={value.publicKey}
|
|
72
88
|
disabled={disabled}
|
|
89
|
+
readOnly={keyReadOnly}
|
|
73
90
|
onChange={(e) => set("publicKey", e.target.value)}
|
|
74
91
|
/>
|
|
75
92
|
</FormField>
|
|
@@ -81,6 +98,7 @@ export default function EscrowScopeKeyAndHoldersFields({ value, onChange, disabl
|
|
|
81
98
|
className={INPUT_CLASS}
|
|
82
99
|
value={value.keyType}
|
|
83
100
|
disabled={disabled}
|
|
101
|
+
readOnly={keyReadOnly}
|
|
84
102
|
onChange={(e) => set("keyType", e.target.value)}
|
|
85
103
|
placeholder="x509"
|
|
86
104
|
/>
|
|
@@ -93,6 +111,7 @@ export default function EscrowScopeKeyAndHoldersFields({ value, onChange, disabl
|
|
|
93
111
|
className={`${INPUT_CLASS} font-mono`}
|
|
94
112
|
value={value.fingerprint}
|
|
95
113
|
disabled={disabled}
|
|
114
|
+
readOnly={keyReadOnly}
|
|
96
115
|
onChange={(e) => set("fingerprint", e.target.value)}
|
|
97
116
|
/>
|
|
98
117
|
</FormField>
|
|
@@ -105,6 +124,7 @@ export default function EscrowScopeKeyAndHoldersFields({ value, onChange, disabl
|
|
|
105
124
|
className={INPUT_CLASS}
|
|
106
125
|
value={value.notBefore}
|
|
107
126
|
disabled={disabled}
|
|
127
|
+
readOnly={keyReadOnly}
|
|
108
128
|
onChange={(e) => set("notBefore", e.target.value)}
|
|
109
129
|
/>
|
|
110
130
|
</FormField>
|
|
@@ -116,6 +136,7 @@ export default function EscrowScopeKeyAndHoldersFields({ value, onChange, disabl
|
|
|
116
136
|
className={INPUT_CLASS}
|
|
117
137
|
value={value.notAfter}
|
|
118
138
|
disabled={disabled}
|
|
139
|
+
readOnly={keyReadOnly}
|
|
119
140
|
onChange={(e) => set("notAfter", e.target.value)}
|
|
120
141
|
/>
|
|
121
142
|
</FormField>
|
|
@@ -29,6 +29,7 @@ import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
|
29
29
|
import BottomTabBar, { NavItem } from "@rapidmx/react-shared/components/navigation/BottomTabBar.js";
|
|
30
30
|
import { BrandingFooter, BrandingHeader } from "../../layout/BrandingChrome.js";
|
|
31
31
|
import UserMenu from "../../layout/UserMenu.js";
|
|
32
|
+
import { signOutOfConsole } from "../signOut.js";
|
|
32
33
|
|
|
33
34
|
export type AdminSection =
|
|
34
35
|
| "mailboxes"
|
|
@@ -174,7 +175,8 @@ export default function AdminShell({ active, userUid, authServerUrl, children }:
|
|
|
174
175
|
}, [userUid]);
|
|
175
176
|
|
|
176
177
|
function handleSignOut() {
|
|
177
|
-
|
|
178
|
+
// Ends the auth-server session and tells other tabs, not just navigates - see `signOutOfConsole()`.
|
|
179
|
+
void signOutOfConsole(authServerUrl);
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
let content: ReactNode;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { FormEvent, useEffect, useState } from "react";
|
|
6
|
+
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
7
|
+
import { EscrowScope, listEscrowScopes } from "@rapidmx/react-shared/admin/escrowScopesApi.js";
|
|
8
|
+
import { Mailbox, updateMailbox } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
9
|
+
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
10
|
+
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
11
|
+
import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
|
|
12
|
+
|
|
13
|
+
const SELECT_CLASS =
|
|
14
|
+
"text-sm py-2 px-3 border border-border rounded-sm bg-surface text-text focus:outline-none focus:border-primary";
|
|
15
|
+
|
|
16
|
+
/** Enough for any realistic deployment's scopes in one list. */
|
|
17
|
+
const SCOPE_LIST_LIMIT = 200;
|
|
18
|
+
|
|
19
|
+
export interface EscrowScopeCardProps {
|
|
20
|
+
mailbox: Mailbox;
|
|
21
|
+
/** Called with the saved mailbox, same push-up pattern as `ResourceSettingsCard`. */
|
|
22
|
+
onUpdate: (mailbox: Mailbox) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Assigns a mailbox to an escrow scope (or none), which decides whose holders can recover its encrypted mail. Only
|
|
27
|
+
* shown in the admin console, whose trusted-role gate the server enforces again for `escrowScopeId`.
|
|
28
|
+
*/
|
|
29
|
+
export default function EscrowScopeCard({ mailbox, onUpdate }: EscrowScopeCardProps) {
|
|
30
|
+
const [scopes, setScopes] = useState<EscrowScope[] | null>(null);
|
|
31
|
+
const [loadError, setLoadError] = useState<string | null>(null);
|
|
32
|
+
const [escrowScopeId, setEscrowScopeId] = useState(mailbox.escrowScopeId ?? "");
|
|
33
|
+
const [saving, setSaving] = useState(false);
|
|
34
|
+
const [saveError, setSaveError] = useState<string | null>(null);
|
|
35
|
+
const [saved, setSaved] = useState(false);
|
|
36
|
+
const [confirming, setConfirming] = useState(false);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
listEscrowScopes({ limit: SCOPE_LIST_LIMIT })
|
|
40
|
+
.then(setScopes)
|
|
41
|
+
.catch((err) => setLoadError(err instanceof ApiRequestError ? err.message : "Could not load escrow scopes."));
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
// Changing the scope changes who can recover this mailbox's encrypted mail, so it's confirmed first.
|
|
45
|
+
function handleSubmit(e: FormEvent) {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
setConfirming(true);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function save() {
|
|
51
|
+
setConfirming(false);
|
|
52
|
+
setSaveError(null);
|
|
53
|
+
setSaved(false);
|
|
54
|
+
setSaving(true);
|
|
55
|
+
try {
|
|
56
|
+
const updated = await updateMailbox({ uid: mailbox.uid, version: mailbox.version, escrowScopeId: escrowScopeId || null });
|
|
57
|
+
onUpdate(updated);
|
|
58
|
+
setSaved(true);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
setSaveError(err instanceof ApiRequestError ? err.message : "Could not save the escrow scope.");
|
|
61
|
+
} finally {
|
|
62
|
+
setSaving(false);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const current = mailbox.escrowScopeId ?? "";
|
|
67
|
+
const unknownCurrent = !!current && !!scopes && !scopes.some((scope) => scope.uid === current);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div className="bg-surface border border-border rounded-md p-6">
|
|
71
|
+
<h2 className="text-base font-bold uppercase tracking-wide mb-1">Escrow scope</h2>
|
|
72
|
+
<p className="text-sm text-text-muted mb-4">
|
|
73
|
+
The holders of this scope can jointly recover this mailbox’s encrypted mail, for example for legal
|
|
74
|
+
discovery. With no scope, nobody can.
|
|
75
|
+
</p>
|
|
76
|
+
|
|
77
|
+
{loadError && <Alert>{loadError}</Alert>}
|
|
78
|
+
{saveError && <Alert>{saveError}</Alert>}
|
|
79
|
+
{saved && !saveError && <div className="mb-4 text-sm text-success font-medium">Saved.</div>}
|
|
80
|
+
|
|
81
|
+
{scopes && (
|
|
82
|
+
<form onSubmit={handleSubmit} className="flex items-end gap-3 flex-wrap">
|
|
83
|
+
<label className="flex flex-col gap-1.5 text-sm">
|
|
84
|
+
<span className="font-semibold">Scope</span>
|
|
85
|
+
<select
|
|
86
|
+
aria-label="Escrow scope"
|
|
87
|
+
className={SELECT_CLASS}
|
|
88
|
+
value={escrowScopeId}
|
|
89
|
+
onChange={(e) => {
|
|
90
|
+
setEscrowScopeId(e.target.value);
|
|
91
|
+
setSaved(false);
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
<option value="">No escrow</option>
|
|
95
|
+
{unknownCurrent && <option value={current}>Unknown scope ({current})</option>}
|
|
96
|
+
{scopes.map((scope) => (
|
|
97
|
+
<option key={scope.uid} value={scope.uid}>
|
|
98
|
+
{scope.name}
|
|
99
|
+
</option>
|
|
100
|
+
))}
|
|
101
|
+
</select>
|
|
102
|
+
</label>
|
|
103
|
+
<Button type="submit" className="!w-auto" loading={saving} disabled={saving || escrowScopeId === current}>
|
|
104
|
+
Save escrow scope
|
|
105
|
+
</Button>
|
|
106
|
+
</form>
|
|
107
|
+
)}
|
|
108
|
+
|
|
109
|
+
<Modal open={confirming} onClose={() => setConfirming(false)} title="Change escrow scope">
|
|
110
|
+
<p className="text-sm mb-3">
|
|
111
|
+
This changes who can jointly recover <strong className="break-all">{mailbox.primarySmtpAddress}</strong>
|
|
112
|
+
’s encrypted mail.
|
|
113
|
+
</p>
|
|
114
|
+
<dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-sm mb-4">
|
|
115
|
+
<dt className="text-text-muted">From</dt>
|
|
116
|
+
<dd className="break-all">
|
|
117
|
+
<ScopeSummary uid={current} scopes={scopes ?? []} />
|
|
118
|
+
</dd>
|
|
119
|
+
<dt className="text-text-muted">To</dt>
|
|
120
|
+
<dd className="break-all">
|
|
121
|
+
<ScopeSummary uid={escrowScopeId} scopes={scopes ?? []} />
|
|
122
|
+
</dd>
|
|
123
|
+
</dl>
|
|
124
|
+
<div className="flex gap-3 justify-end">
|
|
125
|
+
<Button type="button" variant="secondary" className="!w-auto" onClick={() => setConfirming(false)}>
|
|
126
|
+
Cancel
|
|
127
|
+
</Button>
|
|
128
|
+
<Button type="button" className="!w-auto" onClick={() => void save()}>
|
|
129
|
+
Confirm and save
|
|
130
|
+
</Button>
|
|
131
|
+
</div>
|
|
132
|
+
</Modal>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** A scope's name, holders and required approvals - or what having no (or an unlisted) scope means. */
|
|
138
|
+
function ScopeSummary({ uid, scopes }: { uid: string; scopes: EscrowScope[] }) {
|
|
139
|
+
if (!uid) {
|
|
140
|
+
return <span>No escrow - nobody can recover this mailbox’s encrypted mail</span>;
|
|
141
|
+
}
|
|
142
|
+
const scope = scopes.find((candidate) => candidate.uid === uid);
|
|
143
|
+
if (!scope) {
|
|
144
|
+
return <span>Unknown scope ({uid})</span>;
|
|
145
|
+
}
|
|
146
|
+
return (
|
|
147
|
+
<span>
|
|
148
|
+
<strong>{scope.name}</strong> - holders {scope.holderUserUids.join(", ")}; {scope.requiredHolders} of{" "}
|
|
149
|
+
{scope.holderUserUids.length} must approve
|
|
150
|
+
</span>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
@@ -51,11 +51,11 @@ export default function ResourceSettingsCard({ mailbox, onUpdate }: ResourceSett
|
|
|
51
51
|
uid: mailbox.uid,
|
|
52
52
|
version: mailbox.version,
|
|
53
53
|
resourceType,
|
|
54
|
-
resourceCapacity: resourceCapacity ? Number(resourceCapacity) :
|
|
54
|
+
resourceCapacity: resourceCapacity ? Number(resourceCapacity) : null,
|
|
55
55
|
autoAcceptBookings,
|
|
56
56
|
allowConflicts,
|
|
57
|
-
bookingWindowDays: bookingWindowDays ? Number(bookingWindowDays) :
|
|
58
|
-
maxDurationMinutes: maxDurationMinutes ? Number(maxDurationMinutes) :
|
|
57
|
+
bookingWindowDays: bookingWindowDays ? Number(bookingWindowDays) : null,
|
|
58
|
+
maxDurationMinutes: maxDurationMinutes ? Number(maxDurationMinutes) : null,
|
|
59
59
|
});
|
|
60
60
|
onUpdate(updated);
|
|
61
61
|
setSaved(true);
|
|
@@ -7,11 +7,14 @@ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
|
7
7
|
import { AccessControlList, getMailboxAcl, grantMailboxAccess, revokeMailboxAccess } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
8
8
|
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
9
9
|
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
10
|
+
import Modal from "@rapidmx/react-shared/components/overlays/Modal.js";
|
|
10
11
|
|
|
11
12
|
const DEFAULT_DELEGATE_ACTIONS = ["read", "list", "count", "exists"];
|
|
12
13
|
|
|
13
14
|
export interface ShareAccessCardProps {
|
|
14
15
|
mailboxUid: string;
|
|
16
|
+
/** The mailbox's owner - their own grant is shown but can't be revoked from here. */
|
|
17
|
+
ownerUserUid?: string;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
/**
|
|
@@ -19,12 +22,14 @@ export interface ShareAccessCardProps {
|
|
|
19
22
|
* mechanism behind Exchange-style shared mailboxes. `records` on a mailbox's own ACL doubles as both the
|
|
20
23
|
* owner's grant (if any) and every delegate's — see `BaseMailboxRoute`'s doc comment in `@rapidmx/restapi`.
|
|
21
24
|
*/
|
|
22
|
-
export default function ShareAccessCard({ mailboxUid }: ShareAccessCardProps) {
|
|
25
|
+
export default function ShareAccessCard({ mailboxUid, ownerUserUid }: ShareAccessCardProps) {
|
|
23
26
|
const [acl, setAcl] = useState<AccessControlList | null>(null);
|
|
24
27
|
const [loading, setLoading] = useState(true);
|
|
25
28
|
const [error, setError] = useState<string | null>(null);
|
|
29
|
+
const [notice, setNotice] = useState<string | null>(null);
|
|
26
30
|
const [newUserUid, setNewUserUid] = useState("");
|
|
27
31
|
const [saving, setSaving] = useState(false);
|
|
32
|
+
const [revokeTarget, setRevokeTarget] = useState<string | null>(null);
|
|
28
33
|
|
|
29
34
|
function reload() {
|
|
30
35
|
setLoading(true);
|
|
@@ -45,8 +50,19 @@ export default function ShareAccessCard({ mailboxUid }: ShareAccessCardProps) {
|
|
|
45
50
|
}
|
|
46
51
|
setSaving(true);
|
|
47
52
|
setError(null);
|
|
53
|
+
setNotice(null);
|
|
48
54
|
try {
|
|
49
|
-
|
|
55
|
+
// `grantMailboxAccess()` replaces any existing record for this uid, so granting read access to someone
|
|
56
|
+
// who already has more (e.g. the owner) would silently downgrade them. Merge with their current actions.
|
|
57
|
+
const current = await getMailboxAcl(mailboxUid);
|
|
58
|
+
const existing = current.records.find((record) => record.userOrRoleId === userUid)?.actions ?? [];
|
|
59
|
+
const missing = DEFAULT_DELEGATE_ACTIONS.filter((action) => !existing.includes(action));
|
|
60
|
+
if (missing.length === 0) {
|
|
61
|
+
setNotice(`${userUid} already has this access.`);
|
|
62
|
+
setNewUserUid("");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
await grantMailboxAccess(mailboxUid, userUid, [...existing, ...missing]);
|
|
50
66
|
setNewUserUid("");
|
|
51
67
|
reload();
|
|
52
68
|
} catch (err) {
|
|
@@ -56,9 +72,13 @@ export default function ShareAccessCard({ mailboxUid }: ShareAccessCardProps) {
|
|
|
56
72
|
}
|
|
57
73
|
}
|
|
58
74
|
|
|
59
|
-
|
|
75
|
+
// Only ever invoked from the revoke-confirmation modal below, which only renders once `revokeTarget` is set.
|
|
76
|
+
async function handleRevoke() {
|
|
77
|
+
const userOrRoleId = revokeTarget!;
|
|
78
|
+
setRevokeTarget(null);
|
|
60
79
|
setSaving(true);
|
|
61
80
|
setError(null);
|
|
81
|
+
setNotice(null);
|
|
62
82
|
try {
|
|
63
83
|
await revokeMailboxAccess(mailboxUid, userOrRoleId);
|
|
64
84
|
reload();
|
|
@@ -77,6 +97,7 @@ export default function ShareAccessCard({ mailboxUid }: ShareAccessCardProps) {
|
|
|
77
97
|
</p>
|
|
78
98
|
|
|
79
99
|
{error && <Alert>{error}</Alert>}
|
|
100
|
+
{notice && !error && <div className="mb-4 text-sm text-text-muted">{notice}</div>}
|
|
80
101
|
|
|
81
102
|
{loading ? (
|
|
82
103
|
<p className="text-sm text-text-muted">Loading…</p>
|
|
@@ -94,14 +115,18 @@ export default function ShareAccessCard({ mailboxUid }: ShareAccessCardProps) {
|
|
|
94
115
|
<div className="text-sm font-medium">{record.userOrRoleId}</div>
|
|
95
116
|
<div className="text-xs text-text-muted">{record.actions.join(", ")}</div>
|
|
96
117
|
</div>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
118
|
+
{record.userOrRoleId === ownerUserUid ? (
|
|
119
|
+
<span className="text-xs font-bold uppercase tracking-wide text-text-muted">Owner</span>
|
|
120
|
+
) : (
|
|
121
|
+
<button
|
|
122
|
+
type="button"
|
|
123
|
+
onClick={() => setRevokeTarget(record.userOrRoleId)}
|
|
124
|
+
disabled={saving}
|
|
125
|
+
className="text-sm text-danger hover:underline disabled:opacity-55"
|
|
126
|
+
>
|
|
127
|
+
Revoke
|
|
128
|
+
</button>
|
|
129
|
+
)}
|
|
105
130
|
</li>
|
|
106
131
|
))}
|
|
107
132
|
</ul>
|
|
@@ -119,6 +144,25 @@ export default function ShareAccessCard({ mailboxUid }: ShareAccessCardProps) {
|
|
|
119
144
|
Grant
|
|
120
145
|
</Button>
|
|
121
146
|
</form>
|
|
147
|
+
|
|
148
|
+
<Modal open={revokeTarget !== null} onClose={() => setRevokeTarget(null)} title="Revoke access">
|
|
149
|
+
<p className="text-sm mb-5">
|
|
150
|
+
Revoke <strong className="break-all">{revokeTarget}</strong>’s access to this mailbox? They lose it
|
|
151
|
+
immediately.
|
|
152
|
+
</p>
|
|
153
|
+
<div className="flex gap-3 justify-end">
|
|
154
|
+
<Button type="button" variant="secondary" className="!w-auto" onClick={() => setRevokeTarget(null)}>
|
|
155
|
+
Cancel
|
|
156
|
+
</Button>
|
|
157
|
+
<Button
|
|
158
|
+
type="button"
|
|
159
|
+
className="!w-auto !bg-none !bg-danger !border-danger hover:!bg-danger"
|
|
160
|
+
onClick={() => void handleRevoke()}
|
|
161
|
+
>
|
|
162
|
+
Revoke
|
|
163
|
+
</Button>
|
|
164
|
+
</div>
|
|
165
|
+
</Modal>
|
|
122
166
|
</div>
|
|
123
167
|
);
|
|
124
168
|
}
|
|
@@ -22,6 +22,13 @@ const INPUT_CLASS =
|
|
|
22
22
|
|
|
23
23
|
const MAX_UPLOAD_BYTES = 5 * 1024 * 1024;
|
|
24
24
|
|
|
25
|
+
/** SVG logo/icon uploads are refused (the server refuses them too): an SVG served from this origin can carry script. */
|
|
26
|
+
export function isSvgFile(file: File): boolean {
|
|
27
|
+
return file.type === "image/svg+xml" || file.name.toLowerCase().endsWith(".svg");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const RASTER_IMAGE_ACCEPT = "image/png,image/jpeg,image/gif,image/webp,image/x-icon,image/vnd.microsoft.icon";
|
|
31
|
+
|
|
25
32
|
/** The branding editor, shared by the Branding page and the setup wizard. */
|
|
26
33
|
export default function BrandingForm({ branding, onChange }: { branding: Branding; onChange: (b: Branding) => void }) {
|
|
27
34
|
const [companyName, setCompanyName] = useState(branding.companyName);
|
|
@@ -58,7 +65,9 @@ export default function BrandingForm({ branding, onChange }: { branding: Brandin
|
|
|
58
65
|
function handleLogoFileChange(e: ChangeEvent<HTMLInputElement>) {
|
|
59
66
|
const file = e.target.files?.[0];
|
|
60
67
|
if (!file) return;
|
|
61
|
-
if (file
|
|
68
|
+
if (isSvgFile(file)) {
|
|
69
|
+
setError(`"${file.name}" is an SVG — upload a PNG, JPEG, GIF, or WebP logo instead.`);
|
|
70
|
+
} else if (file.size > MAX_UPLOAD_BYTES) {
|
|
62
71
|
setError(`"${file.name}" is too large — logos must be 5MB or smaller.`);
|
|
63
72
|
} else {
|
|
64
73
|
void runAsset("logo-upload", () => uploadBrandingLogo(file));
|
|
@@ -69,7 +78,9 @@ export default function BrandingForm({ branding, onChange }: { branding: Brandin
|
|
|
69
78
|
function handleIconFileChange(e: ChangeEvent<HTMLInputElement>) {
|
|
70
79
|
const file = e.target.files?.[0];
|
|
71
80
|
if (!file) return;
|
|
72
|
-
if (file
|
|
81
|
+
if (isSvgFile(file)) {
|
|
82
|
+
setError(`"${file.name}" is an SVG — upload a PNG, JPEG, GIF, WebP, or ICO icon instead.`);
|
|
83
|
+
} else if (file.size > MAX_UPLOAD_BYTES) {
|
|
73
84
|
setError(`"${file.name}" is too large — icons must be 5MB or smaller.`);
|
|
74
85
|
} else {
|
|
75
86
|
void runAsset("icon-upload", () => uploadBrandingIcon(file));
|
|
@@ -140,7 +151,7 @@ export default function BrandingForm({ branding, onChange }: { branding: Brandin
|
|
|
140
151
|
<input
|
|
141
152
|
ref={logoFileRef}
|
|
142
153
|
type="file"
|
|
143
|
-
accept=
|
|
154
|
+
accept={RASTER_IMAGE_ACCEPT}
|
|
144
155
|
aria-label="Upload logo"
|
|
145
156
|
className="hidden"
|
|
146
157
|
onChange={handleLogoFileChange}
|
|
@@ -212,7 +223,7 @@ export default function BrandingForm({ branding, onChange }: { branding: Brandin
|
|
|
212
223
|
<input
|
|
213
224
|
ref={iconFileRef}
|
|
214
225
|
type="file"
|
|
215
|
-
accept=
|
|
226
|
+
accept={RASTER_IMAGE_ACCEPT}
|
|
216
227
|
aria-label="Upload icon"
|
|
217
228
|
className="hidden"
|
|
218
229
|
onChange={handleIconFileChange}
|
|
@@ -32,12 +32,13 @@ export default function DomainDnsSetup({ uid, onLoaded }: DomainDnsSetupProps) {
|
|
|
32
32
|
const [loading, setLoading] = useState(true);
|
|
33
33
|
const [error, setError] = useState<string | null>(null);
|
|
34
34
|
const [verifying, setVerifying] = useState(false);
|
|
35
|
+
const [verifyError, setVerifyError] = useState<string | null>(null);
|
|
35
36
|
const [copied, setCopied] = useState(false);
|
|
36
37
|
|
|
37
38
|
function reload(id: string) {
|
|
38
39
|
setLoading(true);
|
|
39
40
|
setError(null);
|
|
40
|
-
Promise.all([getDomain(id), getDnsSetup(id)])
|
|
41
|
+
return Promise.all([getDomain(id), getDnsSetup(id)])
|
|
41
42
|
.then(([d, checks]) => {
|
|
42
43
|
setDomain(d);
|
|
43
44
|
setDnsSetup(checks);
|
|
@@ -48,18 +49,23 @@ export default function DomainDnsSetup({ uid, onLoaded }: DomainDnsSetupProps) {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
useEffect(() => {
|
|
51
|
-
reload(uid);
|
|
52
|
+
void reload(uid);
|
|
52
53
|
}, [uid]);
|
|
53
54
|
|
|
54
|
-
// Only ever invoked from the "Verify now" button below, which only renders once `domain` is loaded.
|
|
55
|
+
// Only ever invoked from the "Verify now" button below, which only renders once `domain` is loaded. Any failure -
|
|
56
|
+
// verifying, or refreshing afterwards - is shown next to the button with the panel kept, so it can be retried
|
|
57
|
+
// (e.g. once a DNS record has propagated) instead of the whole panel being replaced by an error.
|
|
55
58
|
async function handleVerify() {
|
|
56
59
|
setVerifying(true);
|
|
57
|
-
|
|
60
|
+
setVerifyError(null);
|
|
58
61
|
try {
|
|
59
62
|
await verifyDomain(domain!.uid);
|
|
60
|
-
|
|
63
|
+
const [d, checks] = await Promise.all([getDomain(domain!.uid), getDnsSetup(domain!.uid)]);
|
|
64
|
+
setDomain(d);
|
|
65
|
+
setDnsSetup(checks);
|
|
66
|
+
onLoaded?.(d);
|
|
61
67
|
} catch (err) {
|
|
62
|
-
|
|
68
|
+
setVerifyError(err instanceof ApiRequestError ? err.message : "Could not verify this domain.");
|
|
63
69
|
} finally {
|
|
64
70
|
setVerifying(false);
|
|
65
71
|
}
|
|
@@ -120,8 +126,13 @@ export default function DomainDnsSetup({ uid, onLoaded }: DomainDnsSetupProps) {
|
|
|
120
126
|
{copied ? "Copied" : "Copy"}
|
|
121
127
|
</Button>
|
|
122
128
|
</div>
|
|
129
|
+
{verifyError && (
|
|
130
|
+
<div className="mt-3">
|
|
131
|
+
<Alert>{verifyError}</Alert>
|
|
132
|
+
</div>
|
|
133
|
+
)}
|
|
123
134
|
<Button type="button" className="!w-auto mt-3" loading={verifying} disabled={verifying} onClick={handleVerify}>
|
|
124
|
-
Verify now
|
|
135
|
+
{verifyError ? "Try again" : "Verify now"}
|
|
125
136
|
</Button>
|
|
126
137
|
</div>
|
|
127
138
|
)}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
3
|
// SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { FormEvent, useState } from "react";
|
|
5
|
+
import React, { FormEvent, useEffect, useState } from "react";
|
|
6
6
|
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
7
7
|
import { EncryptionPolicy, PolicyState, updateEncryptionPolicy } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
|
|
8
8
|
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
@@ -35,15 +35,22 @@ export function isEncryptionEnabled(policy: EncryptionPolicy): boolean {
|
|
|
35
35
|
export interface EncryptionPolicyFormProps {
|
|
36
36
|
policy: EncryptionPolicy;
|
|
37
37
|
onChange: (policy: EncryptionPolicy) => void;
|
|
38
|
+
/** Told whether the form has edits that haven't been saved. */
|
|
39
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/** The end-to-end encryption policy editor, shared by the Encryption Policy page and the setup wizard. */
|
|
41
|
-
export default function EncryptionPolicyForm({ policy, onChange }: EncryptionPolicyFormProps) {
|
|
43
|
+
export default function EncryptionPolicyForm({ policy, onChange, onDirtyChange }: EncryptionPolicyFormProps) {
|
|
42
44
|
const [values, setValues] = useState<EncryptionPolicy>(policy);
|
|
43
45
|
const [error, setError] = useState<string | null>(null);
|
|
44
46
|
const [saving, setSaving] = useState(false);
|
|
45
47
|
const [saved, setSaved] = useState(false);
|
|
46
48
|
|
|
49
|
+
// Edits are unsaved until they match what was loaded or last saved.
|
|
50
|
+
const [savedValues, setSavedValues] = useState<EncryptionPolicy>(policy);
|
|
51
|
+
const dirty: boolean = TIERS.some((tier) => values[tier.key] !== savedValues[tier.key]);
|
|
52
|
+
useEffect(() => onDirtyChange?.(dirty), [dirty]);
|
|
53
|
+
|
|
47
54
|
async function handleSubmit(e: FormEvent) {
|
|
48
55
|
e.preventDefault();
|
|
49
56
|
setError(null);
|
|
@@ -52,6 +59,7 @@ export default function EncryptionPolicyForm({ policy, onChange }: EncryptionPol
|
|
|
52
59
|
try {
|
|
53
60
|
const updated = await updateEncryptionPolicy(values);
|
|
54
61
|
onChange(updated);
|
|
62
|
+
setSavedValues(values);
|
|
55
63
|
setSaved(true);
|
|
56
64
|
} catch (err) {
|
|
57
65
|
setError(err instanceof ApiRequestError ? err.message : "Could not save the encryption policy.");
|
|
@@ -84,6 +84,12 @@ export default function MailboxCreateForm({ onCreated, defaults, submitLabel = "
|
|
|
84
84
|
setError("A display name is required.");
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
|
+
// restapi refuses these (400): a display name shown in From must not look like an address. The fullwidth and
|
|
88
|
+
// small look-alike @ signs are refused too (restapi's `AT_SIGN_LIKE`).
|
|
89
|
+
if (/[@@﹫\r\n]/.test(displayName)) {
|
|
90
|
+
setError("A display name can't contain \"@\" (or a look-alike) or line breaks.");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
87
93
|
|
|
88
94
|
setSaving(true);
|
|
89
95
|
try {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
3
|
// SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { FormEvent, useState } from "react";
|
|
5
|
+
import React, { FormEvent, useEffect, useState } from "react";
|
|
6
6
|
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
7
7
|
import { MailboxPolicy, updateMailboxPolicy } from "@rapidmx/react-shared/admin/mailboxPolicyApi.js";
|
|
8
8
|
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
@@ -13,17 +13,27 @@ const INPUT_CLASS =
|
|
|
13
13
|
|
|
14
14
|
const GB = 1_000_000_000;
|
|
15
15
|
|
|
16
|
+
/** Unrounded, so a quota that isn't a whole number of hundredths of a GB (say 4 MB) is shown as it is. */
|
|
16
17
|
function toGb(bytes: number): string {
|
|
17
|
-
return String(
|
|
18
|
+
return String(bytes / GB);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The form's values as they were loaded or last saved. */
|
|
22
|
+
interface Baseline {
|
|
23
|
+
defaultQuotaGb: string;
|
|
24
|
+
autoProvisionEnabled: boolean;
|
|
25
|
+
autoProvisionQuotaGb: string;
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
export interface MailboxPolicyFormProps {
|
|
21
29
|
policy: MailboxPolicy;
|
|
22
30
|
onChange: (policy: MailboxPolicy) => void;
|
|
31
|
+
/** Told whether the form has edits that haven't been saved. */
|
|
32
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
/** The mailbox defaults editor, shared by the Mailbox Policy page and the setup wizard. */
|
|
26
|
-
export default function MailboxPolicyForm({ policy, onChange }: MailboxPolicyFormProps) {
|
|
36
|
+
export default function MailboxPolicyForm({ policy, onChange, onDirtyChange }: MailboxPolicyFormProps) {
|
|
27
37
|
const [defaultQuotaGb, setDefaultQuotaGb] = useState(toGb(policy.defaultQuotaBytes));
|
|
28
38
|
const [autoProvisionEnabled, setAutoProvisionEnabled] = useState(policy.autoProvisionEnabled);
|
|
29
39
|
const [autoProvisionQuotaGb, setAutoProvisionQuotaGb] = useState(toGb(policy.autoProvisionQuotaBytes));
|
|
@@ -31,24 +41,47 @@ export default function MailboxPolicyForm({ policy, onChange }: MailboxPolicyFor
|
|
|
31
41
|
const [saving, setSaving] = useState(false);
|
|
32
42
|
const [saved, setSaved] = useState(false);
|
|
33
43
|
|
|
44
|
+
// Edits are unsaved until they match what was loaded or last saved.
|
|
45
|
+
const [baseline, setBaseline] = useState<Baseline>({ defaultQuotaGb, autoProvisionEnabled, autoProvisionQuotaGb });
|
|
46
|
+
const dirty: boolean =
|
|
47
|
+
defaultQuotaGb !== baseline.defaultQuotaGb ||
|
|
48
|
+
autoProvisionEnabled !== baseline.autoProvisionEnabled ||
|
|
49
|
+
autoProvisionQuotaGb !== baseline.autoProvisionQuotaGb;
|
|
50
|
+
useEffect(() => onDirtyChange?.(dirty), [dirty]);
|
|
51
|
+
|
|
34
52
|
async function handleSubmit(e: FormEvent) {
|
|
35
53
|
e.preventDefault();
|
|
36
54
|
setError(null);
|
|
37
55
|
setSaved(false);
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
// Only fields the administrator changed are sent, so a quota left alone keeps its exact stored bytes.
|
|
57
|
+
const patch: Partial<MailboxPolicy> = {};
|
|
58
|
+
for (const [field, text, base] of [
|
|
59
|
+
["defaultQuotaBytes", defaultQuotaGb, baseline.defaultQuotaGb],
|
|
60
|
+
["autoProvisionQuotaBytes", autoProvisionQuotaGb, baseline.autoProvisionQuotaGb],
|
|
61
|
+
] as const) {
|
|
62
|
+
if (text === base) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const bytes: number = Math.round(Number(text) * GB);
|
|
66
|
+
if (!(bytes >= 1)) {
|
|
67
|
+
setError("Quotas must be more than 0 GB.");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
patch[field] = bytes;
|
|
71
|
+
}
|
|
72
|
+
if (autoProvisionEnabled !== baseline.autoProvisionEnabled) {
|
|
73
|
+
patch.autoProvisionEnabled = autoProvisionEnabled;
|
|
74
|
+
}
|
|
75
|
+
const current: Baseline = { defaultQuotaGb, autoProvisionEnabled, autoProvisionQuotaGb };
|
|
76
|
+
if (Object.keys(patch).length === 0) {
|
|
77
|
+
setSaved(true);
|
|
42
78
|
return;
|
|
43
79
|
}
|
|
44
80
|
setSaving(true);
|
|
45
81
|
try {
|
|
46
|
-
const updated = await updateMailboxPolicy(
|
|
47
|
-
defaultQuotaBytes: Math.round(defaultQuota * GB),
|
|
48
|
-
autoProvisionEnabled,
|
|
49
|
-
autoProvisionQuotaBytes: Math.round(autoQuota * GB),
|
|
50
|
-
});
|
|
82
|
+
const updated = await updateMailboxPolicy(patch);
|
|
51
83
|
onChange(updated);
|
|
84
|
+
setBaseline(current);
|
|
52
85
|
setSaved(true);
|
|
53
86
|
} catch (err) {
|
|
54
87
|
setError(err instanceof ApiRequestError ? err.message : "Could not save the mailbox policy.");
|