Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32221311
D11142.1765197677.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D11142.1765197677.diff
View Options
diff --git a/web/settings/account-settings.react.js b/web/settings/account-settings.react.js
--- a/web/settings/account-settings.react.js
+++ b/web/settings/account-settings.react.js
@@ -12,6 +12,7 @@
import css from './account-settings.css';
import AppearanceChangeModal from './appearance-change-modal.react.js';
+import BackupTestRestoreModal from './backup-test-restore-modal.react.js';
import PasswordChangeModal from './password-change-modal.js';
import BlockListModal from './relationship/block-list-modal.react.js';
import FriendListModal from './relationship/friend-list-modal.react.js';
@@ -76,6 +77,11 @@
[addListener, popModal, pushModal, removeListener],
);
+ const openBackupTestRestoreModal = React.useCallback(
+ () => pushModal(<BackupTestRestoreModal onClose={popModal} />),
+ [popModal, pushModal],
+ );
+
const showAppearanceModal = React.useCallback(
() => pushModal(<AppearanceChangeModal />),
[pushModal],
@@ -146,6 +152,24 @@
</div>
);
}
+ let backup;
+ if (staffCanSee) {
+ backup = (
+ <div className={css.preferencesContainer}>
+ <h4 className={css.preferencesHeader}>Backup menu</h4>
+ <div className={css.content}>
+ <ul>
+ <li>
+ <span>Test backup restore</span>
+ <Button variant="text" onClick={openBackupTestRestoreModal}>
+ <p className={css.buttonText}>Insert data</p>
+ </Button>
+ </li>
+ </ul>
+ </div>
+ </div>
+ );
+ }
return (
<div className={css.container}>
@@ -180,6 +204,7 @@
</div>
{preferences}
{tunnelbroker}
+ {backup}
</div>
</div>
);
diff --git a/web/settings/backup-test-restore-modal.css b/web/settings/backup-test-restore-modal.css
new file mode 100644
--- /dev/null
+++ b/web/settings/backup-test-restore-modal.css
@@ -0,0 +1,25 @@
+.modalBody {
+ padding: 24px 40px 32px;
+ color: var(--fg);
+}
+
+.content {
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+}
+
+.footer {
+ display: flex;
+ flex-direction: row-reverse;
+ justify-content: space-between;
+ padding-top: 8px;
+}
+
+.modalError {
+ font-size: var(--xs-font-12);
+ color: var(--error);
+ font-style: italic;
+ padding-left: 6px;
+ align-self: center;
+}
diff --git a/web/settings/backup-test-restore-modal.react.js b/web/settings/backup-test-restore-modal.react.js
new file mode 100644
--- /dev/null
+++ b/web/settings/backup-test-restore-modal.react.js
@@ -0,0 +1,118 @@
+// @flow
+
+import invariant from 'invariant';
+import * as React from 'react';
+
+import { IdentityClientContext } from 'lib/shared/identity-client-context.js';
+
+import css from './backup-test-restore-modal.css';
+import Button from '../components/button.react.js';
+import { getDatabaseModule } from '../database/database-module-provider.js';
+import Input from '../modals/input.react.js';
+import Modal from '../modals/modal.react.js';
+import { workerRequestMessageTypes } from '../types/worker-types.js';
+
+type Props = {
+ +onClose: () => void,
+};
+
+function BackupTestRestoreModal(props: Props): React.Node {
+ const { onClose } = props;
+ const [backupID, setBackupID] = React.useState('');
+ const [backupDataKey, setBackupDataKey] = React.useState('');
+ const [backupLogDataKey, setBackupLogDataKey] = React.useState('');
+ const [inProgress, setInProgress] = React.useState(false);
+ const [errorMessage, setErrorMessage] = React.useState('');
+
+ const client = React.useContext(IdentityClientContext);
+
+ const onSubmit = React.useCallback(
+ async (event: SyntheticEvent<HTMLButtonElement>) => {
+ event.preventDefault();
+
+ setInProgress(true);
+ void (async () => {
+ try {
+ if (!client) {
+ throw new Error('No identity client');
+ }
+
+ const authMetadata = await client.getAuthMetadata();
+
+ const databaseModule = await getDatabaseModule();
+ await databaseModule.schedule({
+ type: workerRequestMessageTypes.BACKUP_RESTORE,
+ authMetadata,
+ backupID,
+ backupDataKey,
+ backupLogDataKey,
+ });
+ } catch (e) {
+ setErrorMessage(e.message);
+ }
+ setInProgress(false);
+ })();
+ },
+ [backupDataKey, backupID, backupLogDataKey, client],
+ );
+
+ let errorMsg;
+ if (errorMessage) {
+ errorMsg = <div className={css.modalError}>{errorMessage}</div>;
+ }
+
+ return (
+ <Modal name="Test backup restore" onClose={onClose} size="large">
+ <div className={css.modalBody}>
+ <div className={css.content}>
+ <Input
+ type="text"
+ value={backupID}
+ onChange={(event: SyntheticEvent<HTMLInputElement>) => {
+ const target = event.target;
+ invariant(target instanceof HTMLInputElement, 'target not input');
+ setBackupID(target.value);
+ }}
+ disabled={inProgress}
+ label="Backup ID"
+ />
+ <Input
+ type="text"
+ value={backupDataKey}
+ onChange={(event: SyntheticEvent<HTMLInputElement>) => {
+ const target = event.target;
+ invariant(target instanceof HTMLInputElement, 'target not input');
+ setBackupDataKey(target.value);
+ }}
+ disabled={inProgress}
+ label="Backup Data Encryption Key"
+ />
+ <Input
+ type="text"
+ value={backupLogDataKey}
+ onChange={(event: SyntheticEvent<HTMLInputElement>) => {
+ const target = event.target;
+ invariant(target instanceof HTMLInputElement, 'target not input');
+ setBackupLogDataKey(target.value);
+ }}
+ disabled={inProgress}
+ label="Backup Logs Encryption Key"
+ />
+ </div>
+ <div className={css.footer}>
+ <Button
+ type="submit"
+ variant="filled"
+ onClick={onSubmit}
+ disabled={!backupID || !backupDataKey || inProgress}
+ >
+ Restore
+ </Button>
+ {errorMsg}
+ </div>
+ </div>
+ </Modal>
+ );
+}
+
+export default BackupTestRestoreModal;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 8, 12:41 PM (12 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5848250
Default Alt Text
D11142.1765197677.diff (6 KB)
Attached To
Mode
D11142: [web] Add backup testing screen
Attached
Detach File
Event Timeline
Log In to Comment