Skip to content

armgit / ente

Public Imported from GitHub
0

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

Preserve unshare timestamp bump

Neeraj Guptae6dee8b48619
diff --git a/server/pkg/controller/collections/share_test.go b/server/pkg/controller/collections/share_test.go
index 4661f4b2cb..bc086b35be 100644
--- a/server/pkg/controller/collections/share_test.go
+++ b/server/pkg/controller/collections/share_test.go
@@ -97,6 +97,19 @@ func requireCollectionShareStatus(
}
}
+func collectionUpdationTime(t *testing.T, db *sql.DB, collectionID int64) int64 {
+ t.Helper()
+ var updationTime int64
+ err := db.QueryRow(
+ `SELECT updation_time FROM collections WHERE collection_id = $1`,
+ collectionID,
+ ).Scan(&updationTime)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return updationTime
+}
+
func addShareTestShare(
t *testing.T,
collectionRepo *repo.CollectionRepository,
@@ -369,6 +382,37 @@ func TestAutomaticShareLifecycle(t *testing.T) {
requireCollectionShareStatus(t, status, ente.CollectionShared, err)
}
+func TestUnShareContextBumpsCollectionForDeletedShareRow(t *testing.T) {
+ db, collectionRepo, ownerID, shareeID := setupCollectionShareTest(t)
+ ctx := context.Background()
+ collectionID := createShareTestCollection(t, collectionRepo, ownerID)
+ if err := collectionRepo.Share(
+ collectionID,
+ ownerID,
+ shareeID,
+ "share-key",
+ ente.VIEWER,
+ 1,
+ ); err != nil {
+ t.Fatal(err)
+ }
+
+ status, err := collectionRepo.UnShareContext(ctx, collectionID, shareeID)
+ requireCollectionShareStatus(t, status, ente.CollectionUnshared, err)
+ if _, err := db.Exec(
+ `UPDATE collections SET updation_time = 1 WHERE collection_id = $1`,
+ collectionID,
+ ); err != nil {
+ t.Fatal(err)
+ }
+
+ status, err = collectionRepo.UnShareContext(ctx, collectionID, shareeID)
+ requireCollectionShareStatus(t, status, ente.CollectionAlreadyUnshared, err)
+ if got := collectionUpdationTime(t, db, collectionID); got == 1 {
+ t.Fatal("collection updation_time was not bumped for deleted share row")
+ }
+}
+
func TestUncategorizedCollectionsOnlyAllowViewerShares(t *testing.T) {
_, collectionRepo, ownerID, shareeID := setupCollectionShareTest(t)
collectionID := createShareTestCollectionOfType(
diff --git a/server/pkg/repo/collection.go b/server/pkg/repo/collection.go
index 6c2a435e97..b4b826aa17 100644
--- a/server/pkg/repo/collection.go
+++ b/server/pkg/repo/collection.go
@@ -676,23 +676,17 @@ func (repo *CollectionRepository) UnShareContext(
return "", stacktrace.Propagate(err, "")
}
- result, err := tx.ExecContext(ctx, `UPDATE collection_files
+ _, err = tx.ExecContext(ctx, `UPDATE collection_files
SET is_deleted = TRUE, updation_time = $1
WHERE collection_id = $2 AND f_owner_id = $3 AND is_deleted = FALSE`,
updationTime, collectionID, toUserID)
if err != nil {
return "", stacktrace.Propagate(err, "")
}
- fileRows, err := result.RowsAffected()
- if err != nil {
+ if _, err = tx.ExecContext(ctx, `UPDATE collections SET updation_time = $1
+ WHERE collection_id = $2`, updationTime, collectionID); err != nil {
return "", stacktrace.Propagate(err, "")
}
- if status == ente.CollectionUnshared || fileRows > 0 {
- if _, err = tx.ExecContext(ctx, `UPDATE collections SET updation_time = $1
- WHERE collection_id = $2`, updationTime, collectionID); err != nil {
- return "", stacktrace.Propagate(err, "")
- }
- }
if err := tx.Commit(); err != nil {
return "", stacktrace.Propagate(err, "")
}