From 0a32bd56eb71f279e41b7ccde11b51dd9df2c748 Mon Sep 17 00:00:00 2001 From: Norwin Date: Wed, 27 Jul 2022 16:06:54 +0200 Subject: [PATCH] Show hint to link package to repo when viewing empty repo package list (#20504) (#20507) --- options/locale/locale_en-US.ini | 1 + routers/web/repo/packages.go | 4 ++++ templates/package/shared/list.tmpl | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3c03dc9c44..9a8418201a 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3038,6 +3038,7 @@ title = Packages desc = Manage repository packages. empty = There are no packages yet. empty.documentation = For more information on the package registry, see the documentation. +empty.repo = Did you upload a package, but it's not shown here? Go to package settings and link it to this repo. filter.type = Type filter.type.all = All filter.no_result = Your filter produced no results. diff --git a/routers/web/repo/packages.go b/routers/web/repo/packages.go index 03ea4fc5f4..ad5b520675 100644 --- a/routers/web/repo/packages.go +++ b/routers/web/repo/packages.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/packages" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" @@ -60,6 +61,9 @@ func Packages(ctx *context.Context) { ctx.Data["Query"] = query ctx.Data["PackageType"] = packageType ctx.Data["HasPackages"] = hasPackages + if ctx.Repo != nil { + ctx.Data["CanWritePackages"] = ctx.IsUserRepoWriter([]unit.Type{unit.TypePackages}) || ctx.IsUserSiteAdmin() + } ctx.Data["PackageDescriptors"] = pds ctx.Data["Total"] = total ctx.Data["RepositoryAccessMap"] = map[int64]bool{ctx.Repo.Repository.ID: true} // There is only the current repository diff --git a/templates/package/shared/list.tmpl b/templates/package/shared/list.tmpl index ce2b57e4a0..0a1da7dc3a 100644 --- a/templates/package/shared/list.tmpl +++ b/templates/package/shared/list.tmpl @@ -47,6 +47,10 @@
{{svg "octicon-package" 32}}

{{.i18n.Tr "packages.empty"}}

+ {{if and .Repository .CanWritePackages}} + {{$packagesUrl := URLJoin .Owner.HTMLURL "-" "packages" }} +

{{.i18n.Tr "packages.empty.repo" $packagesUrl | Safe}}

+ {{end}}

{{.i18n.Tr "packages.empty.documentation" | Safe}}

{{else}}