From bba837530afe2d776f4620b84473ea1d67c9b2ce Mon Sep 17 00:00:00 2001
From: Houkime <>
Date: Fri, 28 Jul 2023 10:40:40 +0000
Subject: [PATCH] feature(backups): expose forget to API

---
 .../graphql/mutations/backup_mutations.py     | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/selfprivacy_api/graphql/mutations/backup_mutations.py b/selfprivacy_api/graphql/mutations/backup_mutations.py
index b92af4a..f6dc282 100644
--- a/selfprivacy_api/graphql/mutations/backup_mutations.py
+++ b/selfprivacy_api/graphql/mutations/backup_mutations.py
@@ -157,6 +157,35 @@ class BackupMutations:
             job=job_to_api_job(job),
         )
 
+    @strawberry.mutation(permission_classes=[IsAuthenticated])
+    def forget_snapshot(self, snapshot_id: str) -> GenericMutationReturn:
+        """Forget a snapshot. 
+        Makes it inaccessible from the server. 
+        After some time, the data (encrypted) will not be recoverable
+        from the backup server too, but not immediately"""
+
+        snap = Backups.get_snapshot_by_id(snapshot_id)
+        if snap is None:
+            return GenericMutationReturn(
+                success=False,
+                code=404,
+                message=f"snapshot {snapshot_id} not found",
+            )
+            
+        try:
+            Backups.forget_snapshot(snap)
+            return GenericMutationReturn(
+                success=True,
+                code=200,
+                message="",
+            )
+        except Exception as error:
+            return GenericMutationReturn(
+                success=False,
+                code=400,
+                message=str(error),
+            )
+
     @strawberry.mutation(permission_classes=[IsAuthenticated])
     def force_snapshots_reload(self) -> GenericMutationReturn:
         """Force snapshots reload"""