Consolidate checks

This commit is contained in:
Manav Rathi
2024-06-02 17:36:17 +05:30
parent 0e9a4911b5
commit 62f3e6d47b
5 changed files with 30 additions and 22 deletions

View File

@@ -83,7 +83,6 @@ import {
} from "utils/billing";
import { openLink } from "utils/common";
import { getDownloadAppMessage } from "utils/ui";
import { isInternalUser } from "utils/user";
import { isFamilyAdmin, isPartOfFamily } from "utils/user/family";
import { testUpload } from "../../../tests/upload.test";
import { MemberSubscriptionManage } from "../MemberSubscriptionManage";
@@ -553,7 +552,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
onClick={openRecoveryKeyModal}
label={t("RECOVERY_KEY")}
/>
{isInternalUser() && (
{isInternalUserViaEmailCheck() && (
<EnteMenuItem
onClick={toggleTheme}
variant="secondary"
@@ -572,7 +571,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
label={t("TWO_FACTOR")}
/>
{isInternalUser() && (
{isInternalUserViaEmailCheck() && (
<EnteMenuItem
variant="secondary"
onClick={redirectToAccountsPage}
@@ -768,7 +767,7 @@ const DebugSection: React.FC = () => {
{appVersion}
</Typography>
)}
{isInternalUser() && (
{isInternalUserViaEmailCheck() && (
<EnteMenuItem
variant="secondary"
onClick={testUpload}
@@ -778,3 +777,11 @@ const DebugSection: React.FC = () => {
</>
);
};
// TODO: Legacy synchronous check, use the one for feature-flags.ts instead.
const isInternalUserViaEmailCheck = () => {
const userEmail = getData(LS_KEYS.USER)?.email;
if (!userEmail) return false;
return userEmail.endsWith("@ente.io");
};

View File

@@ -1,3 +1,4 @@
import { fetchAndSaveFeatureFlagsIfNeeded } from "@/new/photos/services/feature-flags";
import log from "@/next/log";
import { APPS } from "@ente/shared/apps/constants";
import { CenteredFlex } from "@ente/shared/components/Container";
@@ -87,7 +88,6 @@ import {
import downloadManager from "services/download";
import { syncCLIPEmbeddings } from "services/embeddingService";
import { syncEntities } from "services/entityService";
import { fetchAndSaveFeatureFlagsIfNeeded } from "@/new/photos/services/feature-flags";
import { getLocalFiles, syncFiles } from "services/fileService";
import locationSearchService from "services/locationSearchService";
import { getLocalTrashedFiles, syncTrash } from "services/trashService";
@@ -720,7 +720,7 @@ export default function Gallery() {
await syncCLIPEmbeddings();
// TODO-ML(MR): Disable fetch until we start storing it in the
// same place as the local ones.
// if (isInternalUserForML()) await syncFaceEmbeddings();
// if (isFaceIndexingEnabled()) await syncFaceEmbeddings();
}
if (clipService.isPlatformSupported()) {
void clipService.scheduleImageEmbeddingExtraction();

View File

@@ -7,7 +7,6 @@ import { ensure } from "@/utils/ensure";
import type { Remote } from "comlink";
import { getAllLocalFiles } from "services/fileService";
import type { EnteFile } from "types/file";
import { isInternalUserForML } from "utils/user";
import {
faceIndex,
indexableFileIDs,
@@ -202,7 +201,7 @@ export const unidentifiedFaceIDs = async (
* face search in the UI.
*/
export const canEnableFaceIndexing = async () =>
isInternalUserForML() || (await isInternalUser()) || (await isBetaUser());
(await isInternalUser()) || (await isBetaUser());
/**
* Return true if the user has enabled face indexing in the app's settings.

View File

@@ -1,21 +1,7 @@
import { getData, LS_KEYS } from "@ente/shared/storage/localStorage";
import type { User } from "@ente/shared/user/types";
import { UserDetails } from "types/user";
export function getLocalUserDetails(): UserDetails {
return getData(LS_KEYS.USER_DETAILS)?.value;
}
export const isInternalUser = () => {
const userEmail = getData(LS_KEYS.USER)?.email;
if (!userEmail) return false;
return userEmail.endsWith("@ente.io");
};
export const isInternalUserForML = () => {
const userID = (getData(LS_KEYS.USER) as User)?.id;
if (userID == 1 || userID == 2) return true;
return isInternalUser();
};

View File

@@ -1,3 +1,5 @@
import { isDevBuild } from "@/next/env";
import { localUser } from "@/next/local-user";
import log from "@/next/log";
import { ensure } from "@/utils/ensure";
import { nullToUndefined } from "@/utils/transform";
@@ -105,14 +107,28 @@ const remoteFeatureFlagsFetchingIfNeeded = async () => {
/**
* Return `true` if the current user is marked as an "internal" user.
*
* 1. Everyone is considered as an internal user in dev builds.
* 2. Emails that end in `@ente.io` are always considered as internal users.
* 3. If the "internalUser" remote feature flag is set, the user is internal.
* 4. Otherwise false.
*
* See also: [Note: Feature Flags].
*/
export const isInternalUser = async () => {
if (isDevBuild) return true;
const user = localUser();
if (user?.email.endsWith("@ente.io")) return true;
const flags = await remoteFeatureFlagsFetchingIfNeeded();
return flags?.internalUser ?? false;
};
/**
* Return `true` if the current user is marked as a "beta" user.
*
* See also: [Note: Feature Flags].
*/
export const isBetaUser = async () => {
const flags = await remoteFeatureFlagsFetchingIfNeeded();