Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Show file counts in the staff dashboard

Neeraj Gupta68a3db01b52f
diff --git a/infra/staff/src/App.tsx b/infra/staff/src/App.tsx
index 986fccdb27..ae89bc4967 100644
--- a/infra/staff/src/App.tsx
+++ b/infra/staff/src/App.tsx
@@ -284,7 +284,15 @@ export const App: React.FC = () => {
}}
>
{tabValue === 0 && (
- <UserDetails userData={userData} />
+ <UserDetails
+ userData={userData}
+ onFileCountsInitialized={() =>
+ fetchData(
+ selectedUserEmail,
+ authToken,
+ )
+ }
+ />
)}
{tabValue === 1 && <FamilyTable />}
{tabValue === 2 && (
@@ -337,9 +345,15 @@ const buildUserDetailsData = (
(userResponse.details?.profileData?.passkeyCount ?? 0) > 0;
const canDisableEmailMFA =
userResponse.details?.profileData?.canDisableEmailMFA ?? false;
+ const { photosFileCount, lockerFileCount } = userResponse;
+ const fileCountsAvailable =
+ photosFileCount !== undefined && lockerFileCount !== undefined;
return {
email: userResponse.user.email || userSearchInput,
+ userID: userResponse.user.ID,
+ showFileCountInitializer:
+ photosFileCount === -1 && lockerFileCount === -1,
user: [
{
kind: "text",
@@ -408,11 +422,21 @@ const buildUserDetailsData = (
enabled: twoFactorEnabled,
},
{ kind: "passkeys", label: "Passkeys", enabled: passkeysEnabled },
- {
- kind: "text",
- label: "AuthCodes",
- value: `${userResponse.authCodes}`,
- },
+ { kind: "text", label: "Auth", value: `${userResponse.authCodes}` },
+ ...(fileCountsAvailable
+ ? [
+ {
+ kind: "text" as const,
+ label: "Photos",
+ value: fileCountLabel(photosFileCount),
+ },
+ {
+ kind: "text" as const,
+ label: "Locker",
+ value: fileCountLabel(lockerFileCount),
+ },
+ ]
+ : []),
],
securityState: {
emailMFAEnabled,
@@ -421,3 +445,6 @@ const buildUserDetailsData = (
},
};
};
+
+const fileCountLabel = (count: number) =>
+ count === -1 ? "Uninitialized" : `${count}`;
diff --git a/infra/staff/src/components/UserDetails.tsx b/infra/staff/src/components/UserDetails.tsx
index 1164e91113..3ed4853c82 100644
--- a/infra/staff/src/components/UserDetails.tsx
+++ b/infra/staff/src/components/UserDetails.tsx
@@ -15,6 +15,8 @@ import {
Typography,
} from "@mui/material";
import React, { useEffect, useState } from "react";
+import { initializeFileCounts } from "../services/admin-user";
+import { useStaffSession } from "../services/session";
import { SUCCESS_COLOR } from "../utils";
import { AddOTT } from "./AddOTT";
import { ChangeEmail } from "./ChangeEmail";
@@ -26,6 +28,8 @@ import { UpdateSubscription } from "./UpdateSubscription";
export interface UserDetailsData {
email: string;
+ userID: number;
+ showFileCountInitializer: boolean;
user: UserTableRow[];
storage: UserTableRow[];
subscription: UserTableRow[];
@@ -49,9 +53,14 @@ type UserSectionKey = "user" | "storage" | "subscription" | "security";
interface UserDetailsProps {
userData: UserDetailsData;
+ onFileCountsInitialized: () => Promise<void>;
}
-export const UserDetails: React.FC<UserDetailsProps> = ({ userData }) => {
+export const UserDetails: React.FC<UserDetailsProps> = ({
+ userData,
+ onFileCountsInitialized,
+}) => {
+ const session = useStaffSession();
const [deleteAccountOpen, setDeleteAccountOpen] = useState(false);
const [emailMFAEnabled, setEmailMFAEnabled] = useState(
userData.securityState.emailMFAEnabled,
@@ -65,6 +74,7 @@ export const UserDetails: React.FC<UserDetailsProps> = ({ userData }) => {
const [changeEmailOpen, setChangeEmailOpen] = useState(false);
const [disablePasskeysOpen, setDisablePasskeysOpen] = useState(false);
const [addOTTOpen, setAddOTTOpen] = useState(false);
+ const [fileCountInitDisabled, setFileCountInitDisabled] = useState(false);
const { canDisableEmailMFA } = userData.securityState;
useEffect(() => {
@@ -87,6 +97,21 @@ export const UserDetails: React.FC<UserDetailsProps> = ({ userData }) => {
setDisable2FAOpen(true);
}
};
+ const handleInitializeFileCounts = async () => {
+ setFileCountInitDisabled(true);
+ window.setTimeout(() => setFileCountInitDisabled(false), 30_000);
+ try {
+ const result = await initializeFileCounts(session, userData.userID);
+ if (result.reason) alert(result.reason);
+ if (result.initialized) await onFileCountsInitialized();
+ } catch (error) {
+ alert(
+ error instanceof Error
+ ? error.message
+ : "Failed to initialize file counts",
+ );
+ }
+ };
const sections: {
key: UserSectionKey;
@@ -130,6 +155,16 @@ export const UserDetails: React.FC<UserDetailsProps> = ({ userData }) => {
/>
</Grid>
))}
+ {userData.showFileCountInitializer && (
+ <Button
+ variant="contained"
+ disabled={fileCountInitDisabled}
+ onClick={() => handleInitializeFileCounts()}
+ sx={{ textTransform: "none" }}
+ >
+ Initialize file counts
+ </Button>
+ )}
<DeleteAccount
open={deleteAccountOpen}
diff --git a/infra/staff/src/services/admin-user.ts b/infra/staff/src/services/admin-user.ts
index fea34cea65..3145d8c7a9 100644
--- a/infra/staff/src/services/admin-user.ts
+++ b/infra/staff/src/services/admin-user.ts
@@ -102,12 +102,19 @@ const UserResponse = z.object({
}),
subscription: Subscription.nullish().transform(nullToUndefined),
authCodes: z.number().nullish().transform(nullishToZero),
+ photosFileCount: z.number().nullish().transform(nullToUndefined),
+ lockerFileCount: z.number().nullish().transform(nullToUndefined),
tokens: z.array(TokenData).nullish().transform(nullishToEmpty),
details: UserDetails,
});
export type UserResponse = z.infer<typeof UserResponse>;
+const InitializeFileCountsResponse = z.object({
+ initialized: z.boolean(),
+ reason: z.string().optional(),
+});
+
const ScheduledDeletionResponse = z.object({
scheduledDeletions: z.array(
z.object({
@@ -174,6 +181,19 @@ export const getUser = async (
return UserResponse.parse(await response.json());
};
+export const initializeFileCounts = async (
+ session: Pick<StaffSession, "token">,
+ userID: number,
+) => {
+ const response = await fetch(apiURL("/admin/user/init-file-counts"), {
+ method: "POST",
+ headers: staffJSONRequestHeaders(session),
+ body: JSON.stringify({ userID }),
+ });
+ await ensureOk(response, "Failed to initialize file counts");
+ return InitializeFileCountsResponse.parse(await response.json());
+};
+
export const getScheduledDeletions = async (
session: Pick<StaffSession, "token">,
email: string,