Skip to content

armgit / ente

Public Imported from GitHub
0

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

Reset created_at for collection_files on restore from is_deleted true -> false

Neeraj Guptab5feb7fcf62d
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index 71b1b8366a..b8e719411b 100644
--- a/server/cmd/museum/main.go
+++ b/server/cmd/museum/main.go
@@ -329,7 +329,7 @@ func main() {
CollectionActionsRepo: &repo.CollectionActionsRepository{DB: db},
}
- // Pending actions controller/handler
+ // Pending actions' controller/handler
collectionActionsController := &controller.CollectionActionsController{
Repo: &repo.CollectionActionsRepository{DB: db},
}
diff --git a/server/pkg/api/collection_actions.go b/server/pkg/api/collection_actions.go
index 07ea7e7b87..af9aed4725 100644
--- a/server/pkg/api/collection_actions.go
+++ b/server/pkg/api/collection_actions.go
@@ -20,7 +20,15 @@ const pendingRemoveLimit = 2000
// ListPendingRemove returns pending REMOVE actions after the provided updatedAt timestamp
func (h *CollectionActionsHandler) ListPendingRemove(c *gin.Context) {
userID := auth.GetUserID(c.Request.Header)
- updatedAfter, _ := strconv.ParseInt(c.Query("updatedAt"), 10, 64)
+ updatedAfter := int64(0)
+ if c.Query("sinceTime") != "" {
+ parseValue, err := strconv.ParseInt(c.Query("sinceTime"), 10, 64)
+ if err != nil {
+ handler.Error(c, stacktrace.Propagate(err, ""))
+ return
+ }
+ updatedAfter = parseValue
+ }
actions, err := h.Controller.ListPendingRemoveActions(c, userID, updatedAfter, pendingRemoveLimit)
if err != nil {
handler.Error(c, stacktrace.Propagate(err, ""))
@@ -28,5 +36,6 @@ func (h *CollectionActionsHandler) ListPendingRemove(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"actions": actions,
+ "hasMore": len(actions) >= pendingRemoveLimit,
})
}
diff --git a/server/pkg/repo/collection.go b/server/pkg/repo/collection.go
index 7946a6635c..e1003899c9 100644
--- a/server/pkg/repo/collection.go
+++ b/server/pkg/repo/collection.go
@@ -585,7 +585,16 @@ func (repo *CollectionRepository) AddFiles(
(collection_id, file_id, encrypted_key, key_decryption_nonce, is_deleted, updation_time, c_owner_id, f_owner_id)
VALUES($1, $2, $3, $4, $5, $6, $7, $8)
ON CONFLICT ON CONSTRAINT unique_collection_files_cid_fid
- DO UPDATE SET(is_deleted, updation_time, action_user, action) = ($5, $6, NULL, NULL)`, collectionID, file.ID, file.EncryptedKey,
+ DO UPDATE SET
+ is_deleted = EXCLUDED.is_deleted,
+ updation_time = EXCLUDED.updation_time,
+ action_user = NULL,
+ action = NULL,
+ created_at = CASE
+ WHEN collection_files.is_deleted = TRUE AND EXCLUDED.is_deleted = FALSE
+ THEN now_utc_micro_seconds()
+ ELSE collection_files.created_at
+ END`, collectionID, file.ID, file.EncryptedKey,
file.KeyDecryptionNonce, false, updationTime, collectionOwnerID, fileOwnerID)
if err != nil {
tx.Rollback()
@@ -627,7 +636,16 @@ func (repo *CollectionRepository) RestoreFiles(ctx context.Context, userID int64
(collection_id, file_id, encrypted_key, key_decryption_nonce, is_deleted, updation_time, c_owner_id, f_owner_id)
VALUES($1, $2, $3, $4, $5, $6, $7, $8)
ON CONFLICT ON CONSTRAINT unique_collection_files_cid_fid
- DO UPDATE SET(is_deleted, updation_time, action_user, action) = ($5, $6, NULL, NULL)`, collectionID, file.ID, file.EncryptedKey,
+ DO UPDATE SET
+ is_deleted = EXCLUDED.is_deleted,
+ updation_time = EXCLUDED.updation_time,
+ action_user = NULL,
+ action = NULL,
+ created_at = CASE
+ WHEN collection_files.is_deleted = TRUE AND EXCLUDED.is_deleted = FALSE
+ THEN now_utc_micro_seconds()
+ ELSE collection_files.created_at
+ END`, collectionID, file.ID, file.EncryptedKey,
file.KeyDecryptionNonce, false, updationTime, userID, userID)
if err != nil {
tx.Rollback()
@@ -735,7 +753,16 @@ func (repo *CollectionRepository) MoveFiles(ctx context.Context,
(collection_id, file_id, encrypted_key, key_decryption_nonce, is_deleted, updation_time, c_owner_id, f_owner_id)
VALUES($1, $2, $3, $4, $5, $6, $7, $8)
ON CONFLICT ON CONSTRAINT unique_collection_files_cid_fid
- DO UPDATE SET(is_deleted, updation_time, action_user, action) = ($5, $6, NULL, NULL)`, toCollectionID, file.ID, file.EncryptedKey,
+ DO UPDATE SET
+ is_deleted = EXCLUDED.is_deleted,
+ updation_time = EXCLUDED.updation_time,
+ action_user = NULL,
+ action = NULL,
+ created_at = CASE
+ WHEN collection_files.is_deleted = TRUE AND EXCLUDED.is_deleted = FALSE
+ THEN now_utc_micro_seconds()
+ ELSE collection_files.created_at
+ END`, toCollectionID, file.ID, file.EncryptedKey,
file.KeyDecryptionNonce, false, updationTime, collectionOwner, fileOwner)
if err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {