Skip to content

armgit / ente

Public Imported from GitHub
0

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

gate(Upload):add-feature-flag-for-upload-to-shared-album

Aswin Asok467c1f566500
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsx
index 9d3c48267d..0862b2c5a2 100644
--- a/web/apps/photos/src/components/Upload.tsx
+++ b/web/apps/photos/src/components/Upload.tsx
@@ -56,6 +56,7 @@ import { CollectionMappingChoice } from "ente-new/photos/components/CollectionMa
import type { CollectionSelectorAttributes } from "ente-new/photos/components/CollectionSelector";
import type { RemotePullOpts } from "ente-new/photos/components/gallery";
import { downloadAppDialogAttributes } from "ente-new/photos/components/utils/download";
+import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
import { suppressAutoLockOnBlurForTrustedPrompt } from "ente-new/photos/services/app-lock";
import {
addOrCopyToCollection,
@@ -69,6 +70,7 @@ import {
savedNormalCollections,
savedOrCreateUserUncategorizedCollection,
} from "ente-new/photos/services/collection";
+import { isDevBuildAndUser } from "ente-new/photos/services/settings";
import { redirectToCustomerPortal } from "ente-new/photos/services/user-details";
import { usePhotosAppContext } from "ente-new/photos/types/context";
import { firstNonEmpty } from "ente-utils/array";
@@ -178,6 +180,8 @@ export const Upload: React.FC<UploadProps> = ({
}) => {
const { showMiniDialog, onGenericError } = useBaseContext();
const { showNotification, watchFolderView } = usePhotosAppContext();
+ const { isInternalUser } = useSettingsSnapshot();
+ const canUseSharedAlbumUpload = isInternalUser || isDevBuildAndUser();
const [uploadProgressView, setUploadProgressView] = useState(false);
const [
@@ -565,10 +569,12 @@ export const Upload: React.FC<UploadProps> = ({
if (isDragAndDrop.current) {
isDragAndDrop.current = false;
- if (
+ const canUploadToActiveCollection =
props.activeCollection &&
- canAddFilesToCollection(props.activeCollection)
- ) {
+ (props.activeCollection.owner.id == user?.id ||
+ (canUseSharedAlbumUpload &&
+ canAddFilesToCollection(props.activeCollection)));
+ if (props.activeCollection && canUploadToActiveCollection) {
uploadFilesToExistingCollection(props.activeCollection);
return;
}
@@ -650,7 +656,7 @@ export const Upload: React.FC<UploadProps> = ({
try {
const uploadCollection = canDirectlyUploadToCollection(collection)
? collection
- : canAddFilesToCollection(collection)
+ : canUseSharedAlbumUpload && canAddFilesToCollection(collection)
? await savedOrCreateUserUncategorizedCollection()
: undefined;
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 395145e86c..9ebbff61e5 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -143,7 +143,10 @@ import {
type SearchOption,
type SidebarActionID,
} from "ente-new/photos/services/search/types";
-import { initSettings } from "ente-new/photos/services/settings";
+import {
+ initSettings,
+ isDevBuildAndUser,
+} from "ente-new/photos/services/settings";
import {
redirectToCustomerPortal,
savedUserDetailsOrTriggerPull,
@@ -252,7 +255,8 @@ const Page: React.FC = () => {
const [collectionSelectorAttributes, setCollectionSelectorAttributes] =
useState<CollectionSelectorAttributes | undefined>();
- const { customDomain } = useSettingsSnapshot();
+ const { customDomain, isInternalUser } = useSettingsSnapshot();
+ const canUseSharedAlbumAdd = isInternalUser || isDevBuildAndUser();
const userDetails = useUserDetailsSnapshot();
const peopleState = usePeopleStateSnapshot();
@@ -972,13 +976,14 @@ const Page: React.FC = () => {
(f) => f.ownerID == user!.id,
);
/**
- * Basically earlier we used userFiles to performCollectionOp earlier
- * irrespective of the op, and userFiles only have files of which the current
- * user is the owner. Now as we support upload from shared albums also, in case
- * it's an upload(add) using selectedFiles instead of userFiles
+ * The shared-album add/copy path can process non-owned
+ * files, but keep the old owner-only behavior for users who
+ * do not pass the shared-album add gate.
*/
const filesToProcess =
- op == "add" ? selectedFiles : userFiles;
+ canUseSharedAlbumAdd && op == "add"
+ ? selectedFiles
+ : userFiles;
const sourceCollectionID = selected.collectionID;
if (filesToProcess.length > 0) {
await performCollectionOp(
@@ -989,7 +994,7 @@ const Page: React.FC = () => {
);
}
if (
- op != "add" &&
+ !(canUseSharedAlbumAdd && op == "add") &&
userFiles.length != selectedFiles.length
) {
showMiniDialog(notifyOthersFilesDialogAttributes());
diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsx
index 737cd2332b..63f63a3843 100644
--- a/web/packages/new/photos/components/CollectionSelector.tsx
+++ b/web/packages/new/photos/components/CollectionSelector.tsx
@@ -38,6 +38,8 @@ import {
import { includes } from "ente-utils/type-guards";
import { t } from "i18next";
import React, { useEffect, useMemo, useRef, useState } from "react";
+import { isDevBuildAndUser } from "../services/settings";
+import { useSettingsSnapshot } from "./utils/use-snapshot";
export type CollectionSelectorAction =
| "upload"
@@ -140,6 +142,8 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
}) => {
// Make the dialog fullscreen if the screen is <= the dialog's max width.
const isFullScreen = useMediaQuery("(max-width: 490px)");
+ const { isInternalUser } = useSettingsSnapshot();
+ const canUseSharedAlbumUpload = isInternalUser || isDevBuildAndUser();
const [searchTerm, setSearchTerm] = useState("");
const [sortBy, setSortBy] =
@@ -166,12 +170,11 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
} else if (attributes.action == "add") {
return canAddToCollection(cs) && cs.type != "userFavorites";
} else if (attributes.action == "upload") {
- // Using add eligibility (not move eligibility) so shared incoming
- // albums are available as upload targets. Viewer-only shared incoming
- // albums are still excluded by `canAddToCollection`.
+ const canUploadToCollection = canUseSharedAlbumUpload
+ ? canAddToCollection(cs)
+ : canMoveToCollection(cs);
return (
- (canAddToCollection(cs) ||
- cs.type == "uncategorized") &&
+ (canUploadToCollection || cs.type == "uncategorized") &&
cs.type != "userFavorites"
);
} else if (attributes.action == "restore") {
@@ -204,7 +207,14 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
}
setFilteredCollections(collections);
- }, [collectionSummaries, attributes, open, onClose, sortBy]);
+ }, [
+ collectionSummaries,
+ attributes,
+ open,
+ onClose,
+ sortBy,
+ canUseSharedAlbumUpload,
+ ]);
const searchFilteredCollections = useMemo(() => {
if (!searchTerm.trim()) {