Skip to content

armgit / ente

Public Imported from GitHub
0

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

Hide pending removals from shared file lookups

Neeraj Gupta32042156ff29
diff --git a/server/pkg/controller/collections/collection.go b/server/pkg/controller/collections/collection.go
index c89be4fa8f..9f888bbc87 100644
--- a/server/pkg/controller/collections/collection.go
+++ b/server/pkg/controller/collections/collection.go
@@ -119,6 +119,9 @@ func (c *CollectionController) GetFile(ctx *gin.Context, collectionID int64, fil
if !slices.Contains(cIDs, collectionID) {
return nil, stacktrace.Propagate(ente.ErrPermissionDenied, "")
}
+ if file.Action != nil && (*file.Action == ente.ActionRemove || *file.Action == ente.ActionDeleteSuggested) {
+ return nil, stacktrace.Propagate(&ente.ErrFileNotFoundInAlbum, "")
+ }
file.MagicMetadata = nil
file.Action = nil
file.ActionUserID = nil
diff --git a/server/pkg/controller/collections/collection_test.go b/server/pkg/controller/collections/collection_test.go
index 157a8e1c02..b00008d7ad 100644
--- a/server/pkg/controller/collections/collection_test.go
+++ b/server/pkg/controller/collections/collection_test.go
@@ -1,6 +1,7 @@
package collections
import (
+ "errors"
"net/http/httptest"
"testing"
@@ -96,17 +97,6 @@ func TestGetFileForViewer(t *testing.T) {
); err != nil {
t.Fatal(err)
}
- if _, err := db.Exec(
- `UPDATE collection_files SET action_user = $1, action = $2
- WHERE collection_id = $3 AND file_id = $4`,
- ownerID,
- ente.ActionRemove,
- collectionID,
- fileID,
- ); err != nil {
- t.Fatal(err)
- }
-
controller := &CollectionController{CollectionRepo: collectionRepo}
ownerFile, err := controller.GetFile(newBatchShareTestContext(ownerID), collectionID, fileID)
if err != nil {
@@ -115,10 +105,6 @@ func TestGetFileForViewer(t *testing.T) {
if ownerFile.MagicMetadata == nil || ownerFile.MagicMetadata.Data != "private-file" {
t.Fatalf("owner private magic metadata = %+v", ownerFile.MagicMetadata)
}
- if ownerFile.Action == nil || *ownerFile.Action != ente.ActionRemove || ownerFile.ActionUserID == nil || *ownerFile.ActionUserID != ownerID {
- t.Fatalf("owner action fields = (%v, %v)", ownerFile.Action, ownerFile.ActionUserID)
- }
-
viewerFile, err := controller.GetFile(newBatchShareTestContext(shareeID), collectionID, fileID)
if err != nil {
t.Fatal(err)
@@ -132,4 +118,30 @@ func TestGetFileForViewer(t *testing.T) {
if viewerFile.EncryptedKey != "collection-file-key" || viewerFile.Metadata.EncryptedData != "encrypted-metadata" {
t.Fatalf("viewer shared file fields were not preserved: %+v", viewerFile)
}
+
+ for _, action := range []string{ente.ActionRemove, ente.ActionDeleteSuggested} {
+ if _, err := db.Exec(
+ `UPDATE collection_files SET action_user = $1, action = $2
+ WHERE collection_id = $3 AND file_id = $4`,
+ ownerID,
+ action,
+ collectionID,
+ fileID,
+ ); err != nil {
+ t.Fatal(err)
+ }
+
+ ownerFile, err := controller.GetFile(newBatchShareTestContext(ownerID), collectionID, fileID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if ownerFile.Action == nil || *ownerFile.Action != action || ownerFile.ActionUserID == nil || *ownerFile.ActionUserID != ownerID {
+ t.Fatalf("owner action fields = (%v, %v)", ownerFile.Action, ownerFile.ActionUserID)
+ }
+
+ viewerFile, err := controller.GetFile(newBatchShareTestContext(shareeID), collectionID, fileID)
+ if viewerFile != nil || !errors.Is(err, &ente.ErrFileNotFoundInAlbum) {
+ t.Fatalf("viewer lookup with action %q = (%+v, %v), want file not found", action, viewerFile, err)
+ }
+ }
}