Skip to content

Commit 07461e1

Browse files
KN4CK3Rlunnytechknowlogick
authored
Fix condition for is_internal (#22095)
depends on #22094 Fixes https://codeberg.org/forgejo/forgejo/issues/77 The old logic did not consider `is_internal`. Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 4fb2006 commit 07461e1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: models/packages/package_version.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,14 @@ func SearchLatestVersions(ctx context.Context, opts *PackageSearchOptions) ([]*P
302302
cond := opts.toConds().
303303
And(builder.Expr("pv2.id IS NULL"))
304304

305+
joinCond := builder.Expr("package_version.package_id = pv2.package_id AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))")
306+
if !opts.IsInternal.IsNone() {
307+
joinCond = joinCond.And(builder.Eq{"pv2.is_internal": opts.IsInternal.IsTrue()})
308+
}
309+
305310
sess := db.GetEngine(ctx).
306311
Table("package_version").
307-
Join("LEFT", "package_version pv2", "package_version.package_id = pv2.package_id AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))").
312+
Join("LEFT", "package_version pv2", joinCond).
308313
Join("INNER", "package", "package.id = package_version.package_id").
309314
Where(cond)
310315

Diff for: routers/api/packages/npm/npm.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,9 @@ func setPackageTag(tag string, pv *packages_model.PackageVersion, deleteOnly boo
405405

406406
func PackageSearch(ctx *context.Context) {
407407
pvs, total, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
408-
OwnerID: ctx.Package.Owner.ID,
409-
Type: packages_model.TypeNpm,
408+
OwnerID: ctx.Package.Owner.ID,
409+
Type: packages_model.TypeNpm,
410+
IsInternal: util.OptionalBoolFalse,
410411
Name: packages_model.SearchValue{
411412
ExactMatch: false,
412413
Value: ctx.FormTrim("text"),

0 commit comments

Comments
 (0)