💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[infra] Add Staff account recovery actions (#11643)
neeraj-pilot6c3a7e11782b
diff --git a/infra/staff/src/App.css b/infra/staff/src/App.cssindex 63d4de0256..060b652b81 100644--- a/infra/staff/src/App.css+++ b/infra/staff/src/App.css@@ -47,10 +47,13 @@}.fetch-button-container {+ display: flex;+ align-items: center;+ gap: 6px;margin: 0 10px;}-.fetch-button-container button {+.fetch-button-container .fetch-button {width: 150px;height: 56px;border: none;@@ -58,11 +61,37 @@background-color: #1db954;}-.fetch-button-container button:hover {+.fetch-button-container .fetch-button:hover {background-color: #00b33c;}+.fetch-button-container .ad-hoc-actions-button {+ height: 40px;+ border: 1px solid rgb(0 0 0 / 14%);+ border-radius: 8px;+ color: #4a4a4a;+ font-weight: 600;+ text-transform: none;+}++.fetch-button-container .ad-hoc-actions-button:hover {+ background-color: rgb(29 185 84 / 8%);+ border-color: rgb(29 185 84 / 42%);+ color: #168f40;+}+@media (prefers-color-scheme: dark) {+ .fetch-button-container .ad-hoc-actions-button {+ border-color: rgb(255 255 255 / 35%);+ color: rgb(255 255 255 / 87%);+ }++ .fetch-button-container .ad-hoc-actions-button:hover {+ background-color: rgb(29 185 84 / 16%);+ border-color: #1db954;+ color: #5cdb89;+ }+.horizontal-group .MuiInputLabel-root {color: rgb(255 255 255 / 70%);}diff --git a/infra/staff/src/App.tsx b/infra/staff/src/App.tsxindex d85cf8d1a8..5e8f61ef9f 100644--- a/infra/staff/src/App.tsx+++ b/infra/staff/src/App.tsx@@ -6,14 +6,26 @@ import {Tabs,TextField,} from "@mui/material";-import React, { useCallback, useEffect, useMemo, useState } from "react";+import React, {+ useCallback,+ useEffect,+ useMemo,+ useRef,+ useState,+} from "react";import "./App.css";+import { AdHocActions } from "./components/AdHocActions";import { FamilyTable } from "./components/FamilyTable";import { StorageBonusTableComponent } from "./components/StorageBonusTableComponent";import { TokensTableComponent } from "./components/TokenTableComponent";import { UserDetails, type UserDetailsData } from "./components/UserDetails";import duckieimage from "./components/duckie.png";-import { getUser, type UserResponse } from "./services/admin-user";+import {+ getScheduledDeletions,+ getUser,+ type ScheduledDeletion,+ type UserResponse,+} from "./services/admin-user";import { StaffSessionProvider } from "./services/session";import {dateFromMicroseconds,@@ -35,6 +47,15 @@ export const App: React.FC = () => {const [fetchSuccess, setFetchSuccess] = useState(false);const [tabValue, setTabValue] = useState(0);const [userData, setUserData] = useState<UserDetailsData | null>(null);+ const [activeUserID, setActiveUserID] = useState<number>();+ const [scheduledDeletions, setScheduledDeletions] = useState<+ ScheduledDeletion[]+ >([]);+ const [scheduledDeletionsLoading, setScheduledDeletionsLoading] =+ useState(false);+ const [scheduledDeletionsLoaded, setScheduledDeletionsLoaded] =+ useState(false);+ const searchRequestID = useRef(0);useEffect(() => {if (authToken) {@@ -45,26 +66,91 @@ export const App: React.FC = () => {}, [authToken]);const fetchData = useCallback(async (input: string, authToken: string) => {+ const requestID = ++searchRequestID.current;setLoading(true);setError("");setFetchSuccess(false);+ setUserData(null);+ setActiveUserID(undefined);+ setScheduledDeletions([]);+ setScheduledDeletionsLoading(false);+ setScheduledDeletionsLoaded(false);try {const userSearchInput = input.trim();- const userDetailsData = buildUserDetailsData(- await getUser({ token: authToken }, userSearchInput),+ const userResult = await getUser(+ { token: authToken },userSearchInput,- );- setSelectedUserEmail(userDetailsData.email);- setUserData(userDetailsData);+ ).catch((error: unknown) => {+ if (+ error instanceof Error &&+ error.message === "User not found"+ ) {+ return undefined;+ }+ throw error;+ });+ if (requestID !== searchRequestID.current) return;+ if (userResult) {+ const userDetailsData = buildUserDetailsData(+ userResult,+ userSearchInput,+ );+ setSelectedUserEmail(userDetailsData.email);+ setUserData(userDetailsData);+ setActiveUserID(userResult.user.ID);+ } else {+ if (!userSearchInput.includes("@")) {+ throw new Error("User not found");+ }+ const scheduled = await getScheduledDeletions(+ { token: authToken },+ userSearchInput,+ );+ if (requestID !== searchRequestID.current) return;+ if (scheduled.length === 0) {+ throw new Error(noSearchableAccountMessage);+ }+ setSelectedUserEmail(userSearchInput);+ setScheduledDeletions(scheduled);+ setScheduledDeletionsLoaded(true);+ }setFetchSuccess(true);} catch (error) {+ if (requestID !== searchRequestID.current) return;console.error("Error fetching data:", error);setError(fetchErrorMessage(error));} finally {- setLoading(false);+ if (requestID === searchRequestID.current) setLoading(false);}}, []);+ const loadScheduledDeletions = useCallback(async () => {+ if (scheduledDeletionsLoaded || scheduledDeletionsLoading) return;+ const requestID = searchRequestID.current;+ setScheduledDeletionsLoading(true);+ try {+ const scheduled = await getScheduledDeletions(+ { token: authToken },+ selectedUserEmail,+ );+ if (requestID !== searchRequestID.current) return;+ setScheduledDeletions(scheduled);+ setScheduledDeletionsLoaded(true);+ } catch (error) {+ if (requestID !== searchRequestID.current) return;+ throw error;+ } finally {+ if (requestID === searchRequestID.current) {+ setScheduledDeletionsLoading(false);+ }+ }+ }, [+ authToken,+ scheduledDeletionsLoaded,+ scheduledDeletionsLoading,+ selectedUserEmail,+ ]);+useEffect(() => {const { email, token } = urlCredentials;if (email && token) {@@ -76,13 +162,11 @@ export const App: React.FC = () => {}}, [fetchData, urlCredentials]);- const handleKeyDown = (event: React.KeyboardEvent<HTMLFormElement>) => {- if (event.key === "Enter") {- event.preventDefault();- fetchData(searchInput, authToken).catch((error: unknown) =>- console.error("Fetch data error:", error),- );- }+ const handleSubmit = (event: React.SubmitEvent<HTMLFormElement>) => {+ event.preventDefault();+ fetchData(searchInput, authToken).catch((error: unknown) =>+ console.error("Fetch data error:", error),+ );};const handleTabChange = (@@ -100,7 +184,7 @@ export const App: React.FC = () => {return (<StaffSessionProvider session={session}><div className="container">- <form className="input-form" onKeyDown={handleKeyDown}>+ <form className="input-form" onSubmit={handleSubmit}><div className="horizontal-group"><ahref="https://staff.ente.sh"@@ -122,20 +206,29 @@ export const App: React.FC = () => {</div><div className="fetch-button-container"><Button+ className="fetch-button"+ type="submit"variant="contained"- onClick={() => {- fetchData(searchInput, authToken).catch(- (error: unknown) =>- console.error(- "Fetch data error:",- error,- ),- );- }}sx={{ px: 2 }}>FETCH</Button>+ <AdHocActions+ email={selectedUserEmail}+ activeUserID={activeUserID}+ scheduledDeletions={scheduledDeletions}+ scheduledDeletionsLoading={+ scheduledDeletionsLoading+ }+ scheduledDeletionsLoaded={+ scheduledDeletionsLoaded+ }+ disabled={!fetchSuccess || loading}+ onOpen={loadScheduledDeletions}+ onRecovered={() =>+ fetchData(selectedUserEmail, authToken)+ }+ /></div></div></form>@@ -152,60 +245,62 @@ export const App: React.FC = () => {<div className="error-message">{error}</div>) : fetchSuccess ? (<>- <Box- sx={{- width: "100%",- maxWidth: "600px",- bgcolor: "#FAFAFA",- borderRadius: "7px",- position: "relative",- zIndex: 1000,- }}- >- <Tabs- value={tabValue}- onChange={handleTabChange}- centered+ {userData && (+ <Boxsx={{- "& .MuiTabs-indicator": {- backgroundColor: SUCCESS_COLOR,- height: "5px",- borderRadius: "20px",- },- "& .MuiTab-root": {- textTransform: "none",- },+ width: "100%",+ maxWidth: "600px",+ bgcolor: "#FAFAFA",+ borderRadius: "7px",+ position: "relative",+ zIndex: 1000,}}>- <Tab label="User" />- <Tab label="Family" />- <Tab label="Bonuses" />- <Tab label="Devices" />- </Tabs>- </Box>- <Box- sx={{- width: "100%",- maxWidth: "900px",- bgcolor: "#FAFAFA",- borderRadius: "7px",- padding: "20px",- position: "relative",- zIndex: 999,- marginTop: "16px",- }}- >- {tabValue === 0 && userData && (- <UserDetails userData={userData} />- )}- {tabValue === 1 && userData && <FamilyTable />}- {tabValue === 2 && userData && (- <StorageBonusTableComponent />- )}- {tabValue === 3 && userData && (- <TokensTableComponent />- )}- </Box>+ <Tabs+ value={tabValue}+ onChange={handleTabChange}+ centered+ sx={{+ "& .MuiTabs-indicator": {+ backgroundColor: SUCCESS_COLOR,+ height: "5px",+ borderRadius: "20px",+ },+ "& .MuiTab-root": {+ textTransform: "none",+ },+ }}+ >+ <Tab label="User" />+ <Tab label="Family" />+ <Tab label="Bonuses" />+ <Tab label="Devices" />+ </Tabs>+ </Box>+ )}+ {userData && (+ <Box+ sx={{+ width: "100%",+ maxWidth: "900px",+ bgcolor: "#FAFAFA",+ borderRadius: "7px",+ padding: "20px",+ position: "relative",+ zIndex: 999,+ marginTop: "16px",+ }}+ >+ {tabValue === 0 && (+ <UserDetails userData={userData} />+ )}+ {tabValue === 1 && <FamilyTable />}+ {tabValue === 2 && (+ <StorageBonusTableComponent />+ )}+ {tabValue === 3 && <TokensTableComponent />}+ </Box>+ )}</>) : (<img@@ -227,6 +322,9 @@ const readUrlCredentials = () => {const subscriptionDataNotFoundMessage = "No subscription record for this user";+const noSearchableAccountMessage =+ "No active account or searchable scheduled deletion found. For older deletions, find the user ID in logs and use the existing recovery flow.";+const fetchErrorMessage = (error: unknown) =>error instanceof Error ? error.message : "Invalid token or email/user id";diff --git a/infra/staff/src/components/AdHocActions.tsx b/infra/staff/src/components/AdHocActions.tsxnew file mode 100644index 0000000000..86ef192b5e--- /dev/null+++ b/infra/staff/src/components/AdHocActions.tsx@@ -0,0 +1,376 @@+import MoreVertIcon from "@mui/icons-material/MoreVert";+import RestoreRoundedIcon from "@mui/icons-material/RestoreRounded";+import StorageRoundedIcon from "@mui/icons-material/StorageRounded";+import {+ Box,+ Button,+ Divider,+ ListSubheader,+ Menu,+ MenuItem,+ Tooltip,+ Typography,+} from "@mui/material";+import React, { useState } from "react";+import type { ScheduledDeletion } from "../services/admin-user";+import {+ recoverScheduledDeletion,+ unblockStorageWarningLogin,+} from "../services/admin-user";+import { useStaffSession } from "../services/session";+import { dateFromMicroseconds, formatStorageSize } from "../utils";+import { ConfirmationDialog } from "./ConfirmationDialog";++interface AdHocActionsProps {+ email: string;+ activeUserID?: number | undefined;+ scheduledDeletions: ScheduledDeletion[];+ scheduledDeletionsLoading: boolean;+ scheduledDeletionsLoaded: boolean;+ disabled: boolean;+ onOpen: () => Promise<void>;+ onRecovered: () => Promise<void>;+}++export const AdHocActions: React.FC<AdHocActionsProps> = ({+ email,+ activeUserID,+ scheduledDeletions,+ scheduledDeletionsLoading,+ scheduledDeletionsLoaded,+ disabled,+ onOpen,+ onRecovered,+}) => {+ const session = useStaffSession();+ const [anchorEl, setAnchorEl] = useState<HTMLElement>();+ const [recovering, setRecovering] = useState<ScheduledDeletion>();+ const [unblocking, setUnblocking] = useState(false);+ const [loading, setLoading] = useState(false);+ const [scheduledDeletionError, setScheduledDeletionError] =+ useState<string>();++ const closeMenu = () => setAnchorEl(undefined);+ const recoveryAvailable = activeUserID === undefined;++ const loadScheduledDeletions = async () => {+ setScheduledDeletionError(undefined);+ if (scheduledDeletionsLoaded || scheduledDeletionsLoading) return;+ try {+ await onOpen();+ } catch (error) {+ setScheduledDeletionError(+ error instanceof Error+ ? error.message+ : "Failed to check scheduled deletion",+ );+ }+ };++ const openMenu = (event: React.MouseEvent<HTMLButtonElement>) => {+ setAnchorEl(event.currentTarget);+ loadScheduledDeletions().catch(console.error);+ };++ const recover = async () => {+ if (!recovering) return;+ setLoading(true);+ try {+ await recoverScheduledDeletion(session, recovering.userID, email);+ setRecovering(undefined);+ await onRecovered();+ } catch (error) {+ alert(+ error instanceof Error+ ? error.message+ : "Failed to recover account",+ );+ } finally {+ setLoading(false);+ }+ };++ const unblock = async () => {+ if (activeUserID === undefined) return;+ setLoading(true);+ try {+ await unblockStorageWarningLogin(session, activeUserID);+ setUnblocking(false);+ alert(+ "Unblock request completed. If the account was storage-warning blocked, temporary login grace is now active.",+ );+ } catch (error) {+ alert(+ error instanceof Error+ ? error.message+ : "Failed to unblock login",+ );+ } finally {+ setLoading(false);+ }+ };++ return (+ <>+ <Tooltip+ title={disabled ? "Fetch an account first" : "Account actions"}+ >+ <span>+ <Button+ aria-label="Account actions"+ className="ad-hoc-actions-button"+ disabled={disabled}+ endIcon={<MoreVertIcon />}+ onClick={openMenu}+ type="button"+ variant="outlined"+ >+ Actions+ </Button>+ </span>+ </Tooltip>+ <Menu+ anchorEl={anchorEl}+ open={anchorEl !== undefined}+ onClose={closeMenu}+ slotProps={{+ paper: {+ sx: {+ width: 390,+ mt: 1,+ borderRadius: 2,+ boxShadow: "0 12px 28px rgb(0 0 0 / 18%)",+ },+ },+ }}+ >+ <Box sx={{ px: 2, pt: 1.75, pb: 1.25 }}>+ <Typography sx={{ fontWeight: 700 }} variant="subtitle1">+ Account actions+ </Typography>+ <Typography color="text.secondary" variant="body2">+ {email}+ </Typography>+ </Box>+ <Divider />+ <ListSubheader disableSticky>Scheduled deletion</ListSubheader>+ {scheduledDeletionsLoading ? (+ <MenuItem disabled sx={{ py: 1.25 }}>+ <Typography variant="body2">+ Checking for scheduled deletion…+ </Typography>+ </MenuItem>+ ) : scheduledDeletionError ? (+ <MenuItem+ onClick={() => {+ loadScheduledDeletions().catch(console.error);+ }}+ sx={{+ alignItems: "flex-start",+ gap: 1.5,+ py: 1.25,+ whiteSpace: "normal",+ }}+ >+ <Box sx={{ flex: 1, minWidth: 0 }}>+ <Typography color="error" variant="body2">+ Could not check scheduled deletion.+ </Typography>+ <Typography+ color="text.secondary"+ sx={{ display: "block" }}+ variant="caption"+ >+ {scheduledDeletionError}+ </Typography>+ </Box>+ <Typography+ color="success.main"+ component="span"+ sx={{ flexShrink: 0, fontWeight: 600 }}+ variant="button"+ >+ Retry+ </Typography>+ </MenuItem>+ ) : scheduledDeletions.length === 0 ? (+ <MenuItem disabled sx={{ py: 1.25 }}>+ <Typography variant="body2">+ No scheduled deletion found for this email.+ </Typography>+ </MenuItem>+ ) : (+ scheduledDeletions.map((deletion) => (+ <MenuItem+ key={deletion.userID}+ disableRipple+ disabled={!recoveryAvailable}+ onClick={() => {+ closeMenu();+ setRecovering(deletion);+ }}+ sx={{+ alignItems: "flex-start",+ gap: 1.5,+ py: 1.25,+ whiteSpace: "normal",+ "&.Mui-disabled": { opacity: 0.55 },+ }}+ >+ <RestoreRoundedIcon+ color="success"+ sx={{ mt: 0.25 }}+ />+ <Box+ sx={{ flex: 1, minWidth: 0, textAlign: "left" }}+ >+ <Typography+ sx={{ fontWeight: 600 }}+ variant="body2"+ >+ Account #{deletion.userID}+ </Typography>+ <Typography+ color="text.secondary"+ sx={{ display: "block" }}+ variant="caption"+ >+ Scheduled {formatDate(deletion.scheduledAt)}+ </Typography>+ <Typography+ color="text.secondary"+ sx={{ display: "block" }}+ variant="caption"+ >+ Cleanup starts{" "}+ {formatDate(deletion.deletionStartsAt)}+ </Typography>+ <Typography+ color="text.secondary"+ sx={{ display: "block" }}+ variant="caption"+ >+ Created{" "}+ {formatDate(deletion.userCreatedAt, false)}{" "}+ ·{" "}+ {formatStorageSize(+ deletion.storageConsumed,+ )}{" "}+ stored · {deletion.authenticatorEntryCount}{" "}+ auth entries+ </Typography>+ </Box>+ <Typography+ color="success.contrastText"+ component="span"+ sx={{+ bgcolor: "success.main",+ borderRadius: 1,+ flexShrink: 0,+ fontWeight: 600,+ px: 1.25,+ py: 0.5,+ }}+ variant="button"+ >+ Recover+ </Typography>+ </MenuItem>+ ))+ )}+ {activeUserID !== undefined &&+ scheduledDeletions.length > 0 && (+ <Typography+ color="text.secondary"+ sx={{ px: 2, py: 1 }}+ variant="caption"+ >+ Recovery is unavailable while active account #+ {activeUserID} uses this email.+ </Typography>+ )}+ <Divider sx={{ mt: 0.5 }} />+ <ListSubheader>Storage warning</ListSubheader>+ <MenuItem+ disabled={activeUserID === undefined}+ disableRipple+ onClick={() => {+ closeMenu();+ setUnblocking(true);+ }}+ sx={{ gap: 1.5, py: 1.25 }}+ >+ <StorageRoundedIcon color="warning" />+ <Box sx={{ flex: 1, textAlign: "left" }}>+ <Typography sx={{ fontWeight: 600 }} variant="body2">+ Storage-warning login+ </Typography>+ <Typography color="text.secondary" variant="caption">+ Grant a temporary sign-in grace period.+ </Typography>+ </Box>+ <Typography+ color="warning.main"+ component="span"+ sx={{+ border: 1,+ borderColor: "warning.main",+ borderRadius: 1,+ flexShrink: 0,+ fontWeight: 600,+ px: 1.25,+ py: 0.375,+ }}+ variant="button"+ >+ Unblock+ </Typography>+ </MenuItem>+ </Menu>+ <ConfirmationDialog+ open={recovering !== undefined}+ onClose={() => setRecovering(undefined)}+ title="Recover deleted account?"+ actions={[+ {+ label: "Recover",+ loadingLabel: "Recovering...",+ loading,+ tone: "success",+ onClick: () => {+ recover().catch(console.error);+ },+ },+ ]}+ >+ Restore the deleted account for {email} (user #+ {recovering?.userID}). This cannot succeed while another active+ account uses this email.+ </ConfirmationDialog>+ <ConfirmationDialog+ open={unblocking}+ onClose={() => setUnblocking(false)}+ title="Unblock storage-warning login?"+ actions={[+ {+ label: "Unblock",+ loadingLabel: "Unblocking...",+ loading,+ onClick: () => {+ unblock().catch(console.error);+ },+ },+ ]}+ >+ This grants a temporary login grace; it does not restore sharing+ or family access.+ </ConfirmationDialog>+ </>+ );+};++const formatDate = (timestamp: number, includeTime = true) =>+ dateFromMicroseconds(timestamp).toLocaleString([], {+ dateStyle: "medium",+ ...(includeTime && { timeStyle: "short" }),+ });diff --git a/infra/staff/src/components/ConfirmationDialog.tsx b/infra/staff/src/components/ConfirmationDialog.tsxindex 4edfbea21d..18eaf52504 100644--- a/infra/staff/src/components/ConfirmationDialog.tsx+++ b/infra/staff/src/components/ConfirmationDialog.tsx@@ -35,51 +35,65 @@ export const ConfirmationDialog: React.FC<ConfirmationDialogProps> = ({children,onClose,actions,-}) => (- <Dialog- open={open}- onClose={onClose}- aria-labelledby="alert-dialog-title"- aria-describedby="alert-dialog-description"- PaperComponent={Paper}- sx={{- width: 499,- height: 286,- margin: "auto",- display: "flex",- flexDirection: "column",- alignItems: "center",- justifyContent: "center",- }}- slotProps={{- backdrop: {- style: { backgroundColor: "rgba(255, 255, 255, 0.9)" },- },- }}- >- <DialogTitle id="alert-dialog-title">{title}</DialogTitle>- <DialogContent>- <DialogContentText id="alert-dialog-description">- {children}- </DialogContentText>- </DialogContent>- <DialogActions sx={{ justifyContent: "center" }}>- <Button onClick={onClose} sx={cancelButtonSx}>- Cancel- </Button>- {actions.map(({ label, loadingLabel, loading, tone, onClick }) => (+}) => {+ const isLoading = actions.some(({ loading }) => loading);++ return (+ <Dialog+ open={open}+ onClose={() => {+ if (!isLoading) onClose();+ }}+ aria-labelledby="alert-dialog-title"+ aria-describedby="alert-dialog-description"+ PaperComponent={Paper}+ sx={{+ width: 499,+ height: 286,+ margin: "auto",+ display: "flex",+ flexDirection: "column",+ alignItems: "center",+ justifyContent: "center",+ }}+ slotProps={{+ backdrop: {+ style: { backgroundColor: "rgba(255, 255, 255, 0.9)" },+ },+ }}+ >+ <DialogTitle id="alert-dialog-title">{title}</DialogTitle>+ <DialogContent>+ <DialogContentText id="alert-dialog-description">+ {children}+ </DialogContentText>+ </DialogContent>+ <DialogActions sx={{ justifyContent: "center" }}><Button- key={label}- onClick={onClick}- sx={actionButtonSx[tone ?? "danger"]}- disabled={loading}+ disabled={isLoading}+ onClick={onClose}+ sx={cancelButtonSx}+ type="button">- {loading && loadingLabel ? loadingLabel : label}+ Cancel</Button>- ))}- </DialogActions>- </Dialog>-);+ {actions.map(+ ({ label, loadingLabel, loading, tone, onClick }) => (+ <Button+ key={label}+ onClick={onClick}+ sx={actionButtonSx[tone ?? "danger"]}+ disabled={isLoading}+ type="button"+ >+ {loading && loadingLabel ? loadingLabel : label}+ </Button>+ ),+ )}+ </DialogActions>+ </Dialog>+ );+};const cancelButtonSx: SxProps<Theme> = {bgcolor: "white",diff --git a/infra/staff/src/services/admin-user.ts b/infra/staff/src/services/admin-user.tsindex ccc5c1a3e3..bd0b6ece62 100644--- a/infra/staff/src/services/admin-user.ts+++ b/infra/staff/src/services/admin-user.ts@@ -108,6 +108,23 @@ const UserResponse = z.object({export type UserResponse = z.infer<typeof UserResponse>;+const ScheduledDeletionResponse = z.object({+ scheduledDeletions: z.array(+ z.object({+ userID: z.number(),+ userCreatedAt: z.number(),+ scheduledAt: z.number(),+ deletionStartsAt: z.number(),+ storageConsumed: z.number(),+ authenticatorEntryCount: z.number(),+ }),+ ),+});++export type ScheduledDeletion = z.infer<+ typeof ScheduledDeletionResponse+>["scheduledDeletions"][number];+interface AddOTTRequest {email: string;code: string;@@ -159,6 +176,47 @@ export const getUser = async (return UserResponse.parse(await response.json());};+export const getScheduledDeletions = async (+ session: Pick<StaffSession, "token">,+ email: string,+) => {+ const response = await fetch(+ apiURL("/admin/user/scheduled-deletions", { email }),+ { headers: staffJSONRequestHeaders(session) },+ );+ await ensureOk(response, "Failed to fetch scheduled deletions");+ return ScheduledDeletionResponse.parse(await response.json())+ .scheduledDeletions;+};++export const recoverScheduledDeletion = async (+ session: Pick<StaffSession, "token">,+ userID: number,+ emailID: string,+) => {+ const response = await fetch(apiURL("/admin/user/recover"), {+ method: "POST",+ headers: staffJSONRequestHeaders(session),+ body: JSON.stringify({ userID, emailID }),+ });+ await ensureOk(response, "Failed to recover account");+};++export const unblockStorageWarningLogin = async (+ session: Pick<StaffSession, "token">,+ userID: number,+) => {+ const response = await fetch(+ apiURL("/admin/user/unblock-storage-warning-login"),+ {+ method: "POST",+ headers: staffJSONRequestHeaders(session),+ body: JSON.stringify({ userID }),+ },+ );+ await ensureOk(response, "Failed to unblock storage-warning login");+};+export const getSelectedUser = async (session: StaffSession) => {const response = await fetch(apiURL("/admin/user", { email: requireEmail(session) }),