-
Notifications
You must be signed in to change notification settings - Fork 273
Add admin namespace deletion feature via API (fixes #1519) #1547
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -324,6 +324,67 @@ public ResultJson createNamespace(NamespaceJson json) { | |
| return ResultJson.success("Created namespace " + namespace.getName()); | ||
| } | ||
|
|
||
| @Transactional(rollbackOn = ErrorResultException.class) | ||
| public ResultJson deleteNamespace(String namespaceName, UserData admin) { | ||
| var namespace = repositories.findNamespace(namespaceName); | ||
| if (namespace == null) { | ||
| throw new ErrorResultException("Namespace not found: " + namespaceName, HttpStatus.NOT_FOUND); | ||
| } | ||
|
|
||
| // Get all extensions in the namespace | ||
| var extensions = repositories.findExtensions(namespace); | ||
|
|
||
| // Delete all extensions and their versions | ||
| for (var extension : extensions) { | ||
| // Remove reviews (associated with extension, not version) | ||
| var reviews = repositories.findAllReviews(extension); | ||
| for (var review : reviews) { | ||
| entityManager.remove(review); | ||
| } | ||
|
|
||
| // Remove all versions and their resources | ||
| var versions = repositories.findVersions(extension); | ||
| for (var version : versions) { | ||
| // Remove file resources | ||
| var resources = repositories.findFiles(version); | ||
| for (var resource : resources) { | ||
| storageUtil.removeFile(resource); | ||
| entityManager.remove(resource); | ||
| } | ||
|
|
||
| // Remove the version | ||
| entityManager.remove(version); | ||
| } | ||
|
|
||
| // Clear cache for the extension | ||
| cache.evictExtensionJsons(extension); | ||
| cache.evictLatestExtensionVersion(extension); | ||
|
|
||
| // Remove the extension | ||
| entityManager.remove(extension); | ||
| } | ||
|
Comment on lines
+338
to
+365
|
||
|
|
||
| // Remove all namespace memberships | ||
| var memberships = repositories.findMemberships(namespace); | ||
| for (var membership : memberships) { | ||
| entityManager.remove(membership); | ||
| } | ||
|
|
||
| // Clear cache for the namespace | ||
| cache.evictNamespaceDetails(namespace); | ||
| cache.evictSitemap(); | ||
|
|
||
| // Remove the namespace | ||
| entityManager.remove(namespace); | ||
|
|
||
| // Update search index | ||
| search.updateSearchEntries(extensions.toList()); | ||
|
||
|
|
||
| var result = ResultJson.success("Deleted namespace " + namespaceName + " with " + extensions.toList().size() + " extension(s)"); | ||
| logAdminAction(admin, result); | ||
| return result; | ||
| } | ||
|
|
||
| public void changeNamespace(ChangeNamespaceJson json) { | ||
| if (StringUtils.isEmpty(json.oldNamespace())) { | ||
| throw new ErrorResultException("Old namespace must have a value"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File removal should be done asynchronously via job scheduler, similar to removeExtensionVersion() on line 243 which uses scheduler.enqueue(new RemoveFileJobRequest(resource)). This prevents blocking the transaction on potentially slow external storage operations.