π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Show comment delete option only to authorized users
Anand Baburajan1c9ee41a2291
diff --git a/web/packages/gallery/components/viewer/CommentsSidebar.tsx b/web/packages/gallery/components/viewer/CommentsSidebar.tsxindex 9e62444b34..850d39ebfe 100644--- a/web/packages/gallery/components/viewer/CommentsSidebar.tsx+++ b/web/packages/gallery/components/viewer/CommentsSidebar.tsx@@ -441,6 +441,11 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({}}, [replyingTo]);+ // Reset selected collection when the file changes (gallery view only)+ useEffect(() => {+ setSelectedCollectionID(undefined);+ }, [file?.id]);+// Check if opened from a collection contextconst hasCollectionContext =activeCollectionID !== undefined && activeCollectionID !== 0;@@ -497,6 +502,35 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({sortedCollectionsInfo,]);+ // Check if the current user can delete a given comment.+ // User can delete if: they authored the comment, OR they are owner/admin of the collection.+ const canDeleteComment = useCallback(+ (comment: Comment): boolean => {+ // Comment author can always delete their own comment+ if (comment.userID === currentUserID) {+ return true;+ }++ // Check if user is owner or admin of the selected collection+ const collectionID = selectedCollectionInfo?.id;+ if (!collectionID || !collectionSummaries) {+ return false;+ }++ const summary = collectionSummaries.get(collectionID);+ if (!summary) {+ return false;+ }++ // User is owner (sharedOutgoing) or admin (sharedIncomingAdmin)+ return (+ summary.attributes.has("sharedOutgoing") ||+ summary.attributes.has("sharedIncomingAdmin")+ );+ },+ [currentUserID, selectedCollectionInfo, collectionSummaries],+ );+// Load comments and reactions from prefetched data.const loadComments = useCallback(() => {if (!file || !open || !prefetchedComments) return;@@ -1250,24 +1284,29 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({<ReplyIcon /><span>Reply</span></StyledMenuItem>- <StyledMenuItem- onClick={() => handleContextMenuAction("delete")}- sx={(theme) => ({- "&:hover": {- backgroundColor: "#F24F4F",- color: "#fff",- },- ...theme.applyStyles("dark", {- "&:hover": {- backgroundColor: "#C53030",- color: "#fff",- },- }),- })}- >- <DeleteIcon />- <span>Delete</span>- </StyledMenuItem>+ {contextMenu &&+ canDeleteComment(contextMenu.comment) && (+ <StyledMenuItem+ onClick={() =>+ handleContextMenuAction("delete")+ }+ sx={(theme) => ({+ "&:hover": {+ backgroundColor: "#F24F4F",+ color: "#fff",+ },+ ...theme.applyStyles("dark", {+ "&:hover": {+ backgroundColor: "#C53030",+ color: "#fff",+ },+ }),+ })}+ >+ <DeleteIcon />+ <span>Delete</span>+ </StyledMenuItem>+ )}</StyledMenu></CommentsContainer>diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex 435e661302..d4ebe69565 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -1473,11 +1473,15 @@ const createCollectionSummaries = (type = "sharedIncoming";attributes.add("shared");attributes.add("sharedIncoming");+ const userRole = collection.sharees.find(+ (s) => s.id == user.id,+ )?.role;attributes.add(- collection.sharees.find((s) => s.id == user.id)?.role ==- "COLLABORATOR"- ? "sharedIncomingCollaborator"- : "sharedIncomingViewer",+ userRole == "ADMIN"+ ? "sharedIncomingAdmin"+ : userRole == "COLLABORATOR"+ ? "sharedIncomingCollaborator"+ : "sharedIncomingViewer",);} else if (collectionType == "uncategorized") {type = "uncategorized";diff --git a/web/packages/new/photos/services/collection-summary.ts b/web/packages/new/photos/services/collection-summary.tsindex 2876e305e1..e46d40f78f 100644--- a/web/packages/new/photos/services/collection-summary.ts+++ b/web/packages/new/photos/services/collection-summary.ts@@ -17,6 +17,7 @@ export type CollectionSummaryAttribute =| "sharedOutgoing"| "sharedIncomingViewer"| "sharedIncomingCollaborator"+ | "sharedIncomingAdmin"| "sharedOnlyViaLink"| "system"| "archived"