Skip to content

Commit 547fa1b

Browse files
KN4CK3Rlunnytechknowlogick
committed
Fix condition for is_internal (go-gitea#22095)
depends on go-gitea#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 1409b34 commit 547fa1b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

models/packages/package_version.go

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

306+
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))")
307+
if !opts.IsInternal.IsNone() {
308+
joinCond = joinCond.And(builder.Eq{"pv2.is_internal": opts.IsInternal.IsTrue()})
309+
}
310+
306311
sess := db.GetEngine(ctx).
307312
Table("package_version").
308-
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))").
313+
Join("LEFT", "package_version pv2", joinCond).
309314
Join("INNER", "package", "package.id = package_version.package_id").
310315
Where(cond)
311316

routers/api/packages/npm/npm.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,9 @@ func setPackageTag(tag string, pv *packages_model.PackageVersion, deleteOnly boo
402402

403403
func PackageSearch(ctx *context.Context) {
404404
pvs, total, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
405-
OwnerID: ctx.Package.Owner.ID,
406-
Type: packages_model.TypeNpm,
405+
OwnerID: ctx.Package.Owner.ID,
406+
Type: packages_model.TypeNpm,
407+
IsInternal: util.OptionalBoolFalse,
407408
Name: packages_model.SearchValue{
408409
ExactMatch: false,
409410
Value: ctx.FormTrim("text"),

0 commit comments

Comments
 (0)