Skip to content

armgit / ente

Public Imported from GitHub
0

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

Expose admin storage usage

Neeraj Gupta637bd82e1165
diff --git a/infra/staff/src/App.tsx b/infra/staff/src/App.tsx
index 91f8f418bf..4ed0350991 100644
--- a/infra/staff/src/App.tsx
+++ b/infra/staff/src/App.tsx
@@ -345,8 +345,6 @@ const readUrlCredentials = () => {
return { email: urlParams.get("email"), token: urlParams.get("token") };
};
-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.";
@@ -357,10 +355,6 @@ const buildUserDetailsData = (
userResponse: UserResponse,
userSearchInput: string,
): UserDetailsData => {
- if (!userResponse.subscription) {
- throw new Error(subscriptionDataNotFoundMessage);
- }
-
const { subscription } = userResponse;
const emailMFAEnabled =
userResponse.details?.profileData?.isEmailMFAEnabled ?? false;
@@ -373,6 +367,10 @@ const buildUserDetailsData = (
const { photosFileCount, lockerFileCount } = userResponse;
const fileCountsAvailable =
photosFileCount !== undefined && lockerFileCount !== undefined;
+ const storageConsumed =
+ userResponse.storageConsumedStatus === "unavailable"
+ ? undefined
+ : (userResponse.storageConsumed ?? userResponse.details?.usage);
return {
email: userResponse.user.email || userSearchInput,
@@ -404,14 +402,17 @@ const buildUserDetailsData = (
kind: "text",
label: "Total",
value:
- subscription.storage === 0
+ !subscription || subscription.storage === 0
? "None"
: formatStorageSize(subscription.storage),
},
{
kind: "text",
label: "Consumed",
- value: formatStorageSize(userResponse.details?.usage),
+ value:
+ storageConsumed === undefined
+ ? "Unavailable"
+ : formatStorageSize(storageConsumed),
},
{
kind: "text",
@@ -423,20 +424,21 @@ const buildUserDetailsData = (
{
kind: "text",
label: "Product ID",
- value: subscription.productID || "None",
+ value: subscription?.productID || "None",
},
{
kind: "text",
label: "Provider",
- value: subscription.paymentProvider || "None",
+ value: subscription?.paymentProvider || "None",
},
{
kind: "expiry",
label: "Expiry time",
- value:
- dateFromMicroseconds(
- subscription.expiryTime,
- ).toISOString() || "None",
+ value: subscription
+ ? dateFromMicroseconds(
+ subscription.expiryTime,
+ ).toISOString()
+ : "None",
},
],
security: [
diff --git a/infra/staff/src/services/admin-user.ts b/infra/staff/src/services/admin-user.ts
index 3145d8c7a9..34b71e8f49 100644
--- a/infra/staff/src/services/admin-user.ts
+++ b/infra/staff/src/services/admin-user.ts
@@ -105,6 +105,11 @@ const UserResponse = z.object({
photosFileCount: z.number().nullish().transform(nullToUndefined),
lockerFileCount: z.number().nullish().transform(nullToUndefined),
tokens: z.array(TokenData).nullish().transform(nullishToEmpty),
+ storageConsumed: z.number().nullish().transform(nullToUndefined),
+ storageConsumedStatus: z
+ .enum(["available", "unavailable"])
+ .nullish()
+ .transform(nullToUndefined),
details: UserDetails,
});
diff --git a/server/pkg/api/admin.go b/server/pkg/api/admin.go
index bf04309955..4c716cb9be 100644
--- a/server/pkg/api/admin.go
+++ b/server/pkg/api/admin.go
@@ -695,6 +695,14 @@ func (h *AdminHandler) alertIfAdminMissing2FA(ctx adminAlertContext) {
}
func (h *AdminHandler) attachSubscription(ctx *gin.Context, userID int64, response gin.H) {
+ storageConsumed, err := h.UsageRepo.GetUsage(userID)
+ if err != nil {
+ logrus.WithError(err).WithField("user_id", userID).Error("failed to get user storage usage")
+ response["storageConsumedStatus"] = "unavailable"
+ } else {
+ response["storageConsumed"] = storageConsumed
+ response["storageConsumedStatus"] = "available"
+ }
subscription, err := h.BillingRepo.GetUserSubscription(userID)
if err == nil {
response["subscription"] = subscription