Move package settings to package instead of being tied to version (#37026)

Unties settings page from package version and adds button to delete the
package version
Settings page now allows for deletion of entire package and it's
versions as opposed to a single version

Adds an API endpoint to delete the entire package with all versions from
registry

fixes: https://github.com/go-gitea/gitea/issues/36904

Co-Authored-By: gemini-3-flash

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
TheFox0x7
2026-04-05 21:51:51 +02:00
committed by GitHub
parent a8938115d4
commit ca51b4f875
19 changed files with 477 additions and 45 deletions
+41
View File
@@ -5,6 +5,7 @@ package packages
import (
"context"
"errors"
"code.gitea.io/gitea/models/db"
@@ -86,6 +87,46 @@ func DeleteAllProperties(ctx context.Context, refType PropertyType, refID int64)
return err
}
// DeletePropertiesByPackageID deletes properties of a typed linked to the package
// Use to avoid for loops in mass deletion of properties
func DeletePropertiesByPackageID(ctx context.Context, refType PropertyType, packageID int64) error {
var deleteStmt *builder.Builder
switch refType {
case PropertyTypeFile:
deleteStmt = builder.Delete(
// Delete all properties that are attached to a file and are in ids from a subquery
// which returns ids from the package_file table joined on package_version to link it with package id
builder.Eq{"ref_type": PropertyTypeFile}, builder.In("ref_id",
builder.Select("package_file.id").From("package_file").
LeftJoin("package_version", "package_file.version_id = package_version.id").
Where(builder.Eq{"package_version.package_id": packageID}))).From("package_property")
case PropertyTypeVersion:
// Delete all properties that are attached to a version and are in ids from subquery to the package_version filtered by package id
deleteStmt = builder.Delete(
builder.Eq{"ref_type": PropertyTypeVersion}, builder.In("ref_id",
builder.Select("package_version.id").From("package_version").
Where(builder.Eq{"package_version.package_id": packageID}))).From("package_property")
case PropertyTypePackage:
// Delete all properties that are attached to a package and their reference links to the given package ID
deleteStmt = builder.Delete(
builder.Eq{"ref_type": PropertyTypePackage}, builder.Eq{"ref_id": packageID}).
From("package_property")
default:
return errors.New("invalid ref type")
}
_, err := db.GetEngine(ctx).Exec(deleteStmt)
return err
}
// DeleteFilePropertiesByVersionID deletes all file properties linked to specific version
func DeleteFilePropertiesByVersionID(ctx context.Context, versionID int64) error {
deleteStmt := builder.Delete(builder.Eq{"ref_type": PropertyTypeFile}, builder.In("ref_id", builder.Select("id").From("package_file").Where(builder.Eq{"version_id": versionID}))).From("package_property")
_, err := db.GetEngine(ctx).Exec(deleteStmt)
return err
}
// DeletePropertyByID deletes a property
func DeletePropertyByID(ctx context.Context, propertyID int64) error {
_, err := db.GetEngine(ctx).ID(propertyID).Delete(&PackageProperty{})