π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move
Manav Rathie267dc6bc983
diff --git a/web/apps/photos/src/components/MemberSubscriptionManage.tsx b/web/apps/photos/src/components/MemberSubscriptionManage.tsxindex 5fec26cbdf..62be7e4473 100644--- a/web/apps/photos/src/components/MemberSubscriptionManage.tsx+++ b/web/apps/photos/src/components/MemberSubscriptionManage.tsx@@ -1,4 +1,5 @@import { useIsSmallWidth } from "@/base/hooks";+import { getFamilyPlanAdmin } from "@/new/photos/services/user";import { AppContext } from "@/new/photos/types/context";import {FlexWrapper,@@ -9,7 +10,6 @@ import { Box, Button, Dialog, DialogContent, Typography } from "@mui/material";import { t } from "i18next";import { useContext } from "react";import billingService from "services/billingService";-import { getFamilyPlanAdmin } from "utils/user/family";export function MemberSubscriptionManage({ open, userDetails, onClose }) {const { setDialogMessage } = useContext(AppContext);diff --git a/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx b/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsxindex cd121608ce..090b4c949f 100644--- a/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx+++ b/web/apps/photos/src/components/Sidebar/SubscriptionCard.tsx@@ -1,5 +1,9 @@import { Overlay } from "@/base/components/mui/Container";import type { ButtonishProps } from "@/new/photos/components/mui";+import {+ hasNonAdminFamilyMembers,+ isPartOfFamily,+} from "@/new/photos/services/user";import { bytesInGB, formattedStorageByteSize } from "@/new/photos/utils/units";import { SpaceBetweenFlex } from "@ente/shared/components/Container";import ChevronRightIcon from "@mui/icons-material/ChevronRight";@@ -17,7 +21,6 @@ import { t } from "i18next";import type React from "react";import { useMemo } from "react";import type { UserDetails } from "types/user";-import { hasNonAdminFamilyMembers, isPartOfFamily } from "utils/user/family";interface SubscriptionCardProps {userDetails: UserDetails;diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsxindex 6150c4f750..3ad8b186e8 100644--- a/web/apps/photos/src/components/Sidebar/index.tsx+++ b/web/apps/photos/src/components/Sidebar/index.tsx@@ -77,7 +77,7 @@ import {isSubscriptionCancelled,isSubscriptionPastDue,} from "utils/billing";-import { isFamilyAdmin, isPartOfFamily } from "utils/user/family";+import { isFamilyAdmin, isPartOfFamily } from "@/new/photos/services/user";import { testUpload } from "../../../tests/upload.test";import { MemberSubscriptionManage } from "../MemberSubscriptionManage";import { Preferences } from "./Preferences";diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsxindex 7aee04f44d..a64a302e46 100644--- a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx@@ -1,5 +1,9 @@import { genericRetriableErrorDialogAttributes } from "@/base/components/utils/dialog";import log from "@/base/log";+import {+ getTotalFamilyUsage,+ isPartOfFamily,+} from "@/new/photos/services/user";import { AppContext } from "@/new/photos/types/context";import { bytesInGB, formattedStorageByteSize } from "@/new/photos/utils/units";import { openURL } from "@/new/photos/utils/web";@@ -53,7 +57,6 @@ import {updatePaymentMethod,updateSubscription,} from "utils/billing";-import { getTotalFamilyUsage, isPartOfFamily } from "utils/user/family";interface PlanSelectorProps {modalView: boolean;diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 082cac72c3..ff039f7a67 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -45,6 +45,7 @@ import {} from "@/new/photos/services/search";import type { SearchOption } from "@/new/photos/services/search/types";import { initSettings } from "@/new/photos/services/settings";+import { getLocalFamilyData } from "@/new/photos/services/user";import { useAppContext } from "@/new/photos/types/context";import { splitByPredicate } from "@/utils/array";import { ensure } from "@/utils/ensure";@@ -130,7 +131,6 @@ import {handleCollectionOps,} from "utils/collection";import { FILE_OPS_TYPE, getSelectedFiles, handleFileOps } from "utils/file";-import { getLocalFamilyData } from "utils/user/family";const defaultGalleryContext: GalleryContextType = {showPlanSelectorModal: () => null,diff --git a/web/apps/photos/src/services/userService.ts b/web/apps/photos/src/services/userService.tsindex f6fb67ea3a..171ebf7d2e 100644--- a/web/apps/photos/src/services/userService.ts+++ b/web/apps/photos/src/services/userService.ts@@ -1,13 +1,13 @@import { putAttributes } from "@/accounts/api/user";import log from "@/base/log";import { apiURL, familyAppOrigin } from "@/base/origins";+import { getLocalFamilyData, isPartOfFamily } from "@/new/photos/services/user";import { ApiError } from "@ente/shared/error";import HTTPService from "@ente/shared/network/HTTPService";import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";import { getToken } from "@ente/shared/storage/localStorage/helpers";import { HttpStatusCode } from "axios";import { DeleteChallengeResponse, UserDetails } from "types/user";-import { getLocalFamilyData, isPartOfFamily } from "utils/user/family";const HAS_SET_KEYS = "hasSetKeys";diff --git a/web/apps/photos/src/utils/billing/index.ts b/web/apps/photos/src/utils/billing/index.tsindex a1ff2c7b56..84d6b0c457 100644--- a/web/apps/photos/src/utils/billing/index.ts+++ b/web/apps/photos/src/utils/billing/index.ts@@ -1,4 +1,8 @@import log from "@/base/log";+import {+ getTotalFamilyUsage,+ isPartOfFamily,+} from "@/new/photos/services/user";import { SetDialogBoxAttributes } from "@ente/shared/components/DialogBox/types";import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";import { t } from "i18next";@@ -8,7 +12,6 @@ import { Plan, Subscription } from "types/billing";import { SetLoading } from "types/gallery";import { BonusData, UserDetails } from "types/user";import { getSubscriptionPurchaseSuccessMessage } from "utils/ui";-import { getTotalFamilyUsage, isPartOfFamily } from "utils/user/family";const PAYMENT_PROVIDER_STRIPE = "stripe";const FREE_PLAN = "free";diff --git a/web/apps/photos/src/utils/user/family.ts b/web/apps/photos/src/utils/user/family.tsdeleted file mode 100644index 0456976cc2..0000000000--- a/web/apps/photos/src/utils/user/family.ts+++ /dev/null@@ -1,43 +0,0 @@-import log from "@/base/log";-import type { FamilyData, FamilyMember } from "@/new/photos/services/user";-import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";-import type { User } from "@ente/shared/user/types";--export function getLocalFamilyData(): FamilyData {- return getData(LS_KEYS.FAMILY_DATA);-}--// isPartOfFamily return true if the current user is part of some family plan-export function isPartOfFamily(familyData: FamilyData): boolean {- return Boolean(- familyData && familyData.members && familyData.members.length > 0,- );-}--// hasNonAdminFamilyMembers return true if the admin user has members in his family-export function hasNonAdminFamilyMembers(familyData: FamilyData): boolean {- return Boolean(isPartOfFamily(familyData) && familyData.members.length > 1);-}--export function isFamilyAdmin(familyData: FamilyData): boolean {- const familyAdmin: FamilyMember = getFamilyPlanAdmin(familyData);- const user: User = getData(LS_KEYS.USER);- return familyAdmin.email === user.email;-}--export function getFamilyPlanAdmin(familyData: FamilyData): FamilyMember {- if (isPartOfFamily(familyData)) {- return familyData.members.find((x) => x.isAdmin);- } else {- log.error(- "invalid getFamilyPlanAdmin call - verify user is part of family plan before calling this method",- );- }-}--export function getTotalFamilyUsage(familyData: FamilyData): number {- return familyData.members.reduce(- (sum, currentMember) => sum + currentMember.usage,- 0,- );-}diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.tsindex 58bd087e74..5c20573cab 100644--- a/web/packages/new/photos/services/user.ts+++ b/web/packages/new/photos/services/user.ts@@ -1,5 +1,8 @@import { authenticatedRequestHeaders, ensureOk } from "@/base/http";+import log from "@/base/log";import { apiURL } from "@/base/origins";+import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";+import type { User } from "@ente/shared/user/types";import { z } from "zod";export interface FamilyMember {@@ -15,6 +18,52 @@ export interface FamilyData {members: FamilyMember[];}+export function getLocalFamilyData(): FamilyData {+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return+ return getData(LS_KEYS.FAMILY_DATA);+}++// isPartOfFamily return true if the current user is part of some family plan+export function isPartOfFamily(familyData: FamilyData): boolean {+ return Boolean(+ // eslint-disable-next-line @typescript-eslint/prefer-optional-chain, @typescript-eslint/no-unnecessary-condition+ familyData && familyData.members && familyData.members.length > 0,+ );+}++// hasNonAdminFamilyMembers return true if the admin user has members in his family+export function hasNonAdminFamilyMembers(familyData: FamilyData): boolean {+ return Boolean(isPartOfFamily(familyData) && familyData.members.length > 1);+}++export function isFamilyAdmin(familyData: FamilyData): boolean {+ const familyAdmin: FamilyMember = getFamilyPlanAdmin(familyData);+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment+ const user: User = getData(LS_KEYS.USER);+ return familyAdmin.email === user.email;+}++export function getFamilyPlanAdmin(familyData: FamilyData): FamilyMember {+ if (isPartOfFamily(familyData)) {+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion+ return familyData.members.find((x) => x.isAdmin)!;+ } else {+ log.error(+ "invalid getFamilyPlanAdmin call - verify user is part of family plan before calling this method",+ );+ throw new Error(+ "invalid getFamilyPlanAdmin call - verify user is part of family plan before calling this method",+ );+ }+}++export function getTotalFamilyUsage(familyData: FamilyData): number {+ return familyData.members.reduce(+ (sum, currentMember) => sum + currentMember.usage,+ 0,+ );+}+/*** Fetch the two-factor status (whether or not it is enabled) from remote.*/