mirror of https://github.com/go-gitea/gitea.git
Hide internal package versions (#20492)
* Hide internal versions from most searches. * Added test.
This commit is contained in:
parent
5ed082b624
commit
a3d55ac523
|
@ -20,6 +20,7 @@ import (
|
||||||
container_module "code.gitea.io/gitea/modules/packages/container"
|
container_module "code.gitea.io/gitea/modules/packages/container"
|
||||||
"code.gitea.io/gitea/modules/packages/container/oci"
|
"code.gitea.io/gitea/modules/packages/container/oci"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -487,6 +488,13 @@ func TestPackageContainer(t *testing.T) {
|
||||||
assert.Equal(t, c.ExpectedTags, tagList.Tags)
|
assert.Equal(t, c.ExpectedTags, tagList.Tags)
|
||||||
assert.Equal(t, c.ExpectedLink, resp.Header().Get("Link"))
|
assert.Equal(t, c.ExpectedLink, resp.Header().Get("Link"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/packages/%s?type=container&q=%s", user.Name, image))
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
var apiPackages []*api.Package
|
||||||
|
DecodeJSON(t, resp, &apiPackages)
|
||||||
|
assert.Len(t, apiPackages, 4) // "latest", "main", "multi", "sha256:..."
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Delete", func(t *testing.T) {
|
t.Run("Delete", func(t *testing.T) {
|
||||||
|
|
|
@ -124,6 +124,7 @@ func GetVersionsByPackageType(ctx context.Context, ownerID int64, packageType Ty
|
||||||
pvs, _, err := SearchVersions(ctx, &PackageSearchOptions{
|
pvs, _, err := SearchVersions(ctx, &PackageSearchOptions{
|
||||||
OwnerID: ownerID,
|
OwnerID: ownerID,
|
||||||
Type: packageType,
|
Type: packageType,
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
return pvs, err
|
return pvs, err
|
||||||
}
|
}
|
||||||
|
@ -137,6 +138,7 @@ func GetVersionsByPackageName(ctx context.Context, ownerID int64, packageType Ty
|
||||||
ExactMatch: true,
|
ExactMatch: true,
|
||||||
Value: name,
|
Value: name,
|
||||||
},
|
},
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
return pvs, err
|
return pvs, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
packages_module "code.gitea.io/gitea/modules/packages"
|
packages_module "code.gitea.io/gitea/modules/packages"
|
||||||
composer_module "code.gitea.io/gitea/modules/packages/composer"
|
composer_module "code.gitea.io/gitea/modules/packages/composer"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/api/packages/helper"
|
"code.gitea.io/gitea/routers/api/packages/helper"
|
||||||
packages_service "code.gitea.io/gitea/services/packages"
|
packages_service "code.gitea.io/gitea/services/packages"
|
||||||
|
|
||||||
|
@ -65,6 +66,7 @@ func SearchPackages(ctx *context.Context) {
|
||||||
OwnerID: ctx.Package.Owner.ID,
|
OwnerID: ctx.Package.Owner.ID,
|
||||||
Type: packages_model.TypeComposer,
|
Type: packages_model.TypeComposer,
|
||||||
Name: packages_model.SearchValue{Value: ctx.FormTrim("q")},
|
Name: packages_model.SearchValue{Value: ctx.FormTrim("q")},
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
Paginator: &paginator,
|
Paginator: &paginator,
|
||||||
}
|
}
|
||||||
if ctx.FormTrim("type") != "" {
|
if ctx.FormTrim("type") != "" {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
packages_module "code.gitea.io/gitea/modules/packages"
|
packages_module "code.gitea.io/gitea/modules/packages"
|
||||||
helm_module "code.gitea.io/gitea/modules/packages/helm"
|
helm_module "code.gitea.io/gitea/modules/packages/helm"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/api/packages/helper"
|
"code.gitea.io/gitea/routers/api/packages/helper"
|
||||||
packages_service "code.gitea.io/gitea/services/packages"
|
packages_service "code.gitea.io/gitea/services/packages"
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ func Index(ctx *context.Context) {
|
||||||
pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
|
pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
|
||||||
OwnerID: ctx.Package.Owner.ID,
|
OwnerID: ctx.Package.Owner.ID,
|
||||||
Type: packages_model.TypeHelm,
|
Type: packages_model.TypeHelm,
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiError(ctx, http.StatusInternalServerError, err)
|
apiError(ctx, http.StatusInternalServerError, err)
|
||||||
|
@ -108,6 +110,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||||
Value: ctx.Params("package"),
|
Value: ctx.Params("package"),
|
||||||
},
|
},
|
||||||
HasFileWithName: filename,
|
HasFileWithName: filename,
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiError(ctx, http.StatusInternalServerError, err)
|
apiError(ctx, http.StatusInternalServerError, err)
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
packages_module "code.gitea.io/gitea/modules/packages"
|
packages_module "code.gitea.io/gitea/modules/packages"
|
||||||
npm_module "code.gitea.io/gitea/modules/packages/npm"
|
npm_module "code.gitea.io/gitea/modules/packages/npm"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/api/packages/helper"
|
"code.gitea.io/gitea/routers/api/packages/helper"
|
||||||
packages_service "code.gitea.io/gitea/services/packages"
|
packages_service "code.gitea.io/gitea/services/packages"
|
||||||
|
|
||||||
|
@ -261,6 +262,7 @@ func setPackageTag(tag string, pv *packages_model.PackageVersion, deleteOnly boo
|
||||||
Properties: map[string]string{
|
Properties: map[string]string{
|
||||||
npm_module.TagProperty: tag,
|
npm_module.TagProperty: tag,
|
||||||
},
|
},
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
packages_module "code.gitea.io/gitea/modules/packages"
|
packages_module "code.gitea.io/gitea/modules/packages"
|
||||||
nuget_module "code.gitea.io/gitea/modules/packages/nuget"
|
nuget_module "code.gitea.io/gitea/modules/packages/nuget"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/api/packages/helper"
|
"code.gitea.io/gitea/routers/api/packages/helper"
|
||||||
packages_service "code.gitea.io/gitea/services/packages"
|
packages_service "code.gitea.io/gitea/services/packages"
|
||||||
)
|
)
|
||||||
|
@ -42,6 +43,7 @@ func SearchService(ctx *context.Context) {
|
||||||
OwnerID: ctx.Package.Owner.ID,
|
OwnerID: ctx.Package.Owner.ID,
|
||||||
Type: packages_model.TypeNuGet,
|
Type: packages_model.TypeNuGet,
|
||||||
Name: packages_model.SearchValue{Value: ctx.FormTrim("q")},
|
Name: packages_model.SearchValue{Value: ctx.FormTrim("q")},
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
Paginator: db.NewAbsoluteListOptions(
|
Paginator: db.NewAbsoluteListOptions(
|
||||||
ctx.FormInt("skip"),
|
ctx.FormInt("skip"),
|
||||||
ctx.FormInt("take"),
|
ctx.FormInt("take"),
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
packages_module "code.gitea.io/gitea/modules/packages"
|
packages_module "code.gitea.io/gitea/modules/packages"
|
||||||
rubygems_module "code.gitea.io/gitea/modules/packages/rubygems"
|
rubygems_module "code.gitea.io/gitea/modules/packages/rubygems"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/api/packages/helper"
|
"code.gitea.io/gitea/routers/api/packages/helper"
|
||||||
packages_service "code.gitea.io/gitea/services/packages"
|
packages_service "code.gitea.io/gitea/services/packages"
|
||||||
)
|
)
|
||||||
|
@ -42,6 +43,7 @@ func EnumeratePackagesLatest(ctx *context.Context) {
|
||||||
pvs, _, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
|
pvs, _, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
|
||||||
OwnerID: ctx.Package.Owner.ID,
|
OwnerID: ctx.Package.Owner.ID,
|
||||||
Type: packages_model.TypeRubyGems,
|
Type: packages_model.TypeRubyGems,
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiError(ctx, http.StatusInternalServerError, err)
|
apiError(ctx, http.StatusInternalServerError, err)
|
||||||
|
@ -289,6 +291,7 @@ func getVersionsByFilename(ctx *context.Context, filename string) ([]*packages_m
|
||||||
OwnerID: ctx.Package.Owner.ID,
|
OwnerID: ctx.Package.Owner.ID,
|
||||||
Type: packages_model.TypeRubyGems,
|
Type: packages_model.TypeRubyGems,
|
||||||
HasFileWithName: filename,
|
HasFileWithName: filename,
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
return pvs, err
|
return pvs, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/convert"
|
"code.gitea.io/gitea/modules/convert"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
packages_service "code.gitea.io/gitea/services/packages"
|
packages_service "code.gitea.io/gitea/services/packages"
|
||||||
)
|
)
|
||||||
|
@ -58,6 +59,7 @@ func ListPackages(ctx *context.APIContext) {
|
||||||
OwnerID: ctx.Package.Owner.ID,
|
OwnerID: ctx.Package.Owner.ID,
|
||||||
Type: packages.Type(packageType),
|
Type: packages.Type(packageType),
|
||||||
Name: packages.SearchValue{Value: query},
|
Name: packages.SearchValue{Value: query},
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
Paginator: &listOptions,
|
Paginator: &listOptions,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
packages_service "code.gitea.io/gitea/services/packages"
|
packages_service "code.gitea.io/gitea/services/packages"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ func Packages(ctx *context.Context) {
|
||||||
Type: packages_model.Type(packageType),
|
Type: packages_model.Type(packageType),
|
||||||
Name: packages_model.SearchValue{Value: query},
|
Name: packages_model.SearchValue{Value: query},
|
||||||
Sort: sort,
|
Sort: sort,
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
Paginator: &db.ListOptions{
|
Paginator: &db.ListOptions{
|
||||||
PageSize: setting.UI.PackagesPagingNum,
|
PageSize: setting.UI.PackagesPagingNum,
|
||||||
Page: page,
|
Page: page,
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -36,6 +37,7 @@ func Packages(ctx *context.Context) {
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
Type: packages.Type(packageType),
|
Type: packages.Type(packageType),
|
||||||
Name: packages.SearchValue{Value: query},
|
Name: packages.SearchValue{Value: query},
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SearchLatestVersions", err)
|
ctx.ServerError("SearchLatestVersions", err)
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
"code.gitea.io/gitea/services/forms"
|
"code.gitea.io/gitea/services/forms"
|
||||||
packages_service "code.gitea.io/gitea/services/packages"
|
packages_service "code.gitea.io/gitea/services/packages"
|
||||||
|
@ -46,6 +47,7 @@ func ListPackages(ctx *context.Context) {
|
||||||
OwnerID: ctx.ContextUser.ID,
|
OwnerID: ctx.ContextUser.ID,
|
||||||
Type: packages_model.Type(packageType),
|
Type: packages_model.Type(packageType),
|
||||||
Name: packages_model.SearchValue{Value: query},
|
Name: packages_model.SearchValue{Value: query},
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SearchLatestVersions", err)
|
ctx.ServerError("SearchLatestVersions", err)
|
||||||
|
@ -113,6 +115,7 @@ func RedirectToLastVersion(ctx *context.Context) {
|
||||||
|
|
||||||
pvs, _, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
|
pvs, _, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
|
||||||
PackageID: p.ID,
|
PackageID: p.ID,
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetPackageByName", err)
|
ctx.ServerError("GetPackageByName", err)
|
||||||
|
@ -159,6 +162,7 @@ func ViewPackageVersion(ctx *context.Context) {
|
||||||
pvs, total, err = packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
|
pvs, total, err = packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
|
||||||
Paginator: db.NewAbsoluteListOptions(0, 5),
|
Paginator: db.NewAbsoluteListOptions(0, 5),
|
||||||
PackageID: pd.Package.ID,
|
PackageID: pd.Package.ID,
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SearchVersions", err)
|
ctx.ServerError("SearchVersions", err)
|
||||||
|
@ -254,6 +258,7 @@ func ListPackageVersions(ctx *context.Context) {
|
||||||
ExactMatch: false,
|
ExactMatch: false,
|
||||||
Value: query,
|
Value: query,
|
||||||
},
|
},
|
||||||
|
IsInternal: util.OptionalBoolFalse,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SearchVersions", err)
|
ctx.ServerError("SearchVersions", err)
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
packages_module "code.gitea.io/gitea/modules/packages"
|
packages_module "code.gitea.io/gitea/modules/packages"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
container_service "code.gitea.io/gitea/services/packages/container"
|
container_service "code.gitea.io/gitea/services/packages/container"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -463,6 +464,7 @@ func RemoveAllPackages(ctx context.Context, userID int64) (int, error) {
|
||||||
Page: 1,
|
Page: 1,
|
||||||
},
|
},
|
||||||
OwnerID: userID,
|
OwnerID: userID,
|
||||||
|
IsInternal: util.OptionalBoolNone,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return count, fmt.Errorf("GetOwnedPackages[%d]: %w", userID, err)
|
return count, fmt.Errorf("GetOwnedPackages[%d]: %w", userID, err)
|
||||||
|
|
Loading…
Reference in New Issue