summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-04-01 01:31:53 +0800
committerGitHub <noreply@github.com>2022-03-31 19:31:53 +0200
commit420851ca1ff5c97cc31930f022daaff6f484793b (patch)
tree8fbf05e426c30db2ad2ea706d53cf2c60d4989c3
parentc88547ce71a554091930e129c20776daf6da35ac (diff)
downloadgitea-420851ca1ff5c97cc31930f022daaff6f484793b.tar.gz
gitea-420851ca1ff5c97cc31930f022daaff6f484793b.zip
Fix global packages enabled avaiable (#19276)
Fix #19275
-rw-r--r--modules/context/org.go2
-rw-r--r--routers/web/user/profile.go1
-rw-r--r--routers/web/web.go44
-rw-r--r--templates/org/menu.tmpl2
-rw-r--r--templates/user/profile.tmpl2
5 files changed, 32 insertions, 19 deletions
diff --git a/modules/context/org.go b/modules/context/org.go
index f8607bd29f..427e4910c0 100644
--- a/modules/context/org.go
+++ b/modules/context/org.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/setting"
)
// Organization contains organization context
@@ -119,6 +120,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
}
ctx.Data["IsOrganizationOwner"] = ctx.Org.IsOwner
ctx.Data["IsOrganizationMember"] = ctx.Org.IsMember
+ ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled
ctx.Data["IsPublicMember"] = func(uid int64) bool {
is, _ := organization.IsPublicMembership(ctx.Org.Organization.ID, uid)
return is
diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go
index f628840375..85870eddf5 100644
--- a/routers/web/user/profile.go
+++ b/routers/web/user/profile.go
@@ -280,6 +280,7 @@ func Profile(ctx *context.Context) {
pager.AddParam(ctx, "language", "Language")
}
ctx.Data["Page"] = pager
+ ctx.Data["IsPackageEnabled"] = setting.Packages.Enabled
ctx.Data["ShowUserEmail"] = len(ctx.ContextUser.Email) > 0 && ctx.IsSigned && (!ctx.ContextUser.KeepEmailPrivate || ctx.ContextUser.ID == ctx.Doer.ID)
diff --git a/routers/web/web.go b/routers/web/web.go
index 5ff8174be4..3bdedab854 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -473,10 +473,12 @@ func RegisterRoutes(m *web.Route) {
m.Post("/delete", admin.DeleteRepo)
})
- m.Group("/packages", func() {
- m.Get("", admin.Packages)
- m.Post("/delete", admin.DeletePackageVersion)
- })
+ if setting.Packages.Enabled {
+ m.Group("/packages", func() {
+ m.Get("", admin.Packages)
+ m.Post("/delete", admin.DeletePackageVersion)
+ })
+ }
m.Group("/hooks", func() {
m.Get("", admin.DefaultOrSystemWebhooks)
@@ -670,21 +672,23 @@ func RegisterRoutes(m *web.Route) {
}, reqSignIn)
m.Group("/{username}/-", func() {
- m.Group("/packages", func() {
- m.Get("", user.ListPackages)
- m.Group("/{type}/{name}", func() {
- m.Get("", user.RedirectToLastVersion)
- m.Get("/versions", user.ListPackageVersions)
- m.Group("/{version}", func() {
- m.Get("", user.ViewPackageVersion)
- m.Get("/files/{fileid}", user.DownloadPackageFile)
- m.Group("/settings", func() {
- m.Get("", user.PackageSettings)
- m.Post("", bindIgnErr(forms.PackageSettingForm{}), user.PackageSettingsPost)
- }, reqPackageAccess(perm.AccessModeWrite))
+ if setting.Packages.Enabled {
+ m.Group("/packages", func() {
+ m.Get("", user.ListPackages)
+ m.Group("/{type}/{name}", func() {
+ m.Get("", user.RedirectToLastVersion)
+ m.Get("/versions", user.ListPackageVersions)
+ m.Group("/{version}", func() {
+ m.Get("", user.ViewPackageVersion)
+ m.Get("/files/{fileid}", user.DownloadPackageFile)
+ m.Group("/settings", func() {
+ m.Get("", user.PackageSettings)
+ m.Post("", bindIgnErr(forms.PackageSettingForm{}), user.PackageSettingsPost)
+ }, reqPackageAccess(perm.AccessModeWrite))
+ })
})
- })
- }, context.PackageAssignment(), reqPackageAccess(perm.AccessModeRead))
+ }, context.PackageAssignment(), reqPackageAccess(perm.AccessModeRead))
+ }
}, context_service.UserAssignmentWeb())
// ***** Release Attachment Download without Signin
@@ -973,7 +977,9 @@ func RegisterRoutes(m *web.Route) {
m.Get("/milestones", reqRepoIssuesOrPullsReader, repo.Milestones)
}, context.RepoRef())
- m.Get("/packages", repo.Packages)
+ if setting.Packages.Enabled {
+ m.Get("/packages", repo.Packages)
+ }
m.Group("/projects", func() {
m.Get("", repo.Projects)
diff --git a/templates/org/menu.tmpl b/templates/org/menu.tmpl
index 1f7b1216a6..ff1b8cadc5 100644
--- a/templates/org/menu.tmpl
+++ b/templates/org/menu.tmpl
@@ -3,9 +3,11 @@
<a class="{{if .PageIsViewRepositories}}active{{end}} item" href="{{$.Org.HomeLink}}">
{{svg "octicon-repo"}} {{.i18n.Tr "user.repositories"}}
</a>
+ {{if .IsPackageEnabled}}
<a class="item" href="{{$.Org.HomeLink}}/-/packages">
{{svg "octicon-package"}} {{.i18n.Tr "packages.title"}}
</a>
+ {{end}}
{{if .IsOrganizationMember}}
<a class="{{if $.PageIsOrgMembers}}active{{end}} item" href="{{$.OrgLink}}/members">
{{svg "octicon-organization"}}&nbsp;{{$.i18n.Tr "org.people"}}
diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl
index d761b84d6d..34ecf1afe2 100644
--- a/templates/user/profile.tmpl
+++ b/templates/user/profile.tmpl
@@ -87,9 +87,11 @@
<a class='{{if and (ne .TabName "activity") (ne .TabName "following") (ne .TabName "followers") (ne .TabName "stars") (ne .TabName "watching") (ne .TabName "projects")}}active{{end}} item' href="{{.Owner.HomeLink}}">
{{svg "octicon-repo"}} {{.i18n.Tr "user.repositories"}}
</a>
+ {{if .IsPackageEnabled}}
<a class='{{if eq .TabName "packages"}}active{{end}} item' href="{{.Owner.HomeLink}}/-/packages">
{{svg "octicon-package"}} {{.i18n.Tr "packages.title"}}
</a>
+ {{end}}
<a class='{{if eq .TabName "activity"}}active{{end}} item' href="{{.Owner.HomeLink}}?tab=activity">
{{svg "octicon-rss"}} {{.i18n.Tr "user.activity"}}
</a>