-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add per-user trash (soft delete) with scheduled cleanup #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DenizAltunkapan
merged 1 commit into
Vault-Web:main
from
GabrielBBaldez:feature/user-trash-soft-delete
Jun 13, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/cloudpage/controller/TrashController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package cloudpage.controller; | ||
|
|
||
| import cloudpage.dto.TrashEntryDto; | ||
| import cloudpage.service.TrashService; | ||
| import cloudpage.service.UserService; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| /** Endpoints for a user's trash: listing entries, restoring them, or permanently deleting them. */ | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/files/trash") | ||
| public class TrashController { | ||
|
|
||
| private final TrashService trashService; | ||
| private final UserService userService; | ||
|
|
||
| @GetMapping | ||
| public List<TrashEntryDto> listTrash() { | ||
| return trashService.listTrash(userService.getCurrentUser().getId()); | ||
| } | ||
|
|
||
| @PostMapping("/{id}/restore") | ||
| public void restore(@PathVariable String id) throws IOException { | ||
| var user = userService.getCurrentUser(); | ||
| trashService.restore(user.getRootFolderPath(), user.getId(), id); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}") | ||
| public void purge(@PathVariable String id) throws IOException { | ||
| var user = userService.getCurrentUser(); | ||
| trashService.purge(user.getRootFolderPath(), user.getId(), id); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package cloudpage.dto; | ||
|
|
||
| import java.time.Instant; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @AllArgsConstructor | ||
| public class TrashEntryDto { | ||
|
|
||
| private String id; | ||
| private String name; | ||
| private String originalPath; | ||
| private Instant deletedAt; | ||
| private long size; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package cloudpage.model; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import java.time.Instant; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| /** | ||
| * A file that has been soft-deleted into a user's trash. The {@link #id} also serves as the file | ||
| * name under the user's {@code .trash} directory. An entry is removed once its file is restored, | ||
| * permanently deleted, or purged after the retention period. | ||
| */ | ||
| @Entity | ||
| @Table(name = "trash_entries") | ||
| @Getter | ||
| @Setter | ||
| public class TrashEntry { | ||
|
|
||
| @Id private String id; | ||
|
|
||
| private String userId; | ||
|
|
||
| /** Path, relative to the user's root, the file was deleted from and should be restored to. */ | ||
| private String originalPath; | ||
|
|
||
| /** Original file name, shown in the trash listing. */ | ||
| private String displayName; | ||
|
|
||
| private Instant deletedAt; | ||
|
|
||
| private long sizeBytes; | ||
| } |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/cloudpage/repository/TrashEntryRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package cloudpage.repository; | ||
|
|
||
| import cloudpage.model.TrashEntry; | ||
| import java.time.Instant; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| public interface TrashEntryRepository extends JpaRepository<TrashEntry, String> { | ||
|
|
||
| List<TrashEntry> findByUserId(String userId); | ||
|
|
||
| Optional<TrashEntry> findByIdAndUserId(String id, String userId); | ||
|
|
||
| List<TrashEntry> findByDeletedAtBefore(Instant cutoff); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.