Skip to content
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

feat(admin): allow deleting package versions #1011

Merged
merged 5 commits into from
Apr 2, 2025

Conversation

crowlKats
Copy link
Collaborator

this PR adds an endpoint to be able to delete package versions, but only for admins. This is not exposed in the UI for admins either, as the fact that this is for admins only is just a temporary restriction, and the idea is to come up with sensible restrictions that apply to users so they can delete versions (see #899).

Comment on lines +1000 to +1009
let count = db
.count_package_dependents(
crate::db::DependencyKind::Jsr,
&format!("@{}/{}", scope, package),
)
.await?;

if count > 0 {
return Err(ApiError::DeleteVersionHasDependents);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is not correct, as it doesnt use the version as a requirement, and as such this check applies to all versions and is stricter than should be. This is good enough for now, however ideally this would build a graph and check if there are any other versions that fit the constraints used by dependents, and only if there is no such constraint would it error.

Copy link
Contributor

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add admin UI for deleting packages

Comment on lines 1652 to 1653
#[instrument(name = "Database::yank_package_version", skip(self), err)]
pub async fn delete_package_version(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/yank_package_version/delete_package_version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you should log or instrument the package name here

Copy link
Collaborator Author

@crowlKats crowlKats Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats already done in the route handler function that calls this (same setup we have for all other db calls & endpoints)

Copy link
Contributor

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RSLGTM if you feel confident

@crowlKats crowlKats added this pull request to the merge queue Apr 2, 2025
Merged via the queue into main with commit a13e1bf Apr 2, 2025
7 checks passed
@crowlKats crowlKats deleted the package-version-deletion branch April 2, 2025 09:47
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crowlKats We had discussed that users should not be able to publish a version that was deleted anew - you didn't implement that yet. Can you do that?

@@ -254,6 +260,19 @@ function Version({
</button>
</form>
)}
{isPublished && iam.isStaff && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this only show up when sudo is on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixed in #1027

@crowlKats
Copy link
Collaborator Author

@lucacasonato this is already handled. opened #1027 for adding an additional test to showcase this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants