summaryrefslogtreecommitdiffstats
path: root/routers/web/web.go
diff options
context:
space:
mode:
authorGergely Nagy <forgejo@gergo.csillger.hu>2024-02-25 11:58:23 +0100
committerGergely Nagy <forgejo@gergo.csillger.hu>2024-02-25 12:00:17 +0100
commit0ea021c8c94a11372c0edf6ed5f9705da8750e01 (patch)
treec8b12a9a9c020888224d9c5661b6fd639d590bb3 /routers/web/web.go
parentMerge pull request 'Fixes #2452 - Skipping SHA256 tests if unsupported' (#245... (diff)
downloadforgejo-0ea021c8c94a11372c0edf6ed5f9705da8750e01.tar.xz
forgejo-0ea021c8c94a11372c0edf6ed5f9705da8750e01.zip
Allow instance-wide disabling of forking
For small, personal self-hosted instances with no user signups, the fork button is just a noise. This patch allows disabling them like stars can be disabled too. Disabling forks does not only remove the buttons from the web UI, it also disables the routes that could be used to create forks. Fixes #2441. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
Diffstat (limited to 'routers/web/web.go')
-rw-r--r--routers/web/web.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/routers/web/web.go b/routers/web/web.go
index 0684b2ac82..06ad3490aa 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -968,7 +968,9 @@ func registerRoutes(m *web.Route) {
m.Post("/create", web.Bind(forms.CreateRepoForm{}), repo.CreatePost)
m.Get("/migrate", repo.Migrate)
m.Post("/migrate", web.Bind(forms.MigrateRepoForm{}), repo.MigratePost)
- m.Get("/fork/{repoid}", context.RepoIDAssignment(), context.UnitTypes(), reqRepoCodeReader, repo.ForkByID)
+ if !setting.Repository.DisableForks {
+ m.Get("/fork/{repoid}", context.RepoIDAssignment(), context.UnitTypes(), reqRepoCodeReader, repo.ForkByID)
+ }
m.Get("/search", repo.SearchRepo)
}, reqSignIn)
@@ -1148,8 +1150,10 @@ func registerRoutes(m *web.Route) {
// Grouping for those endpoints that do require authentication
m.Group("/{username}/{reponame}", func() {
- m.Combo("/fork", reqRepoCodeReader).Get(repo.Fork).
- Post(web.Bind(forms.CreateRepoForm{}), repo.ForkPost)
+ if !setting.Repository.DisableForks {
+ m.Combo("/fork", reqRepoCodeReader).Get(repo.Fork).
+ Post(web.Bind(forms.CreateRepoForm{}), repo.ForkPost)
+ }
m.Group("/issues", func() {
m.Group("/new", func() {
m.Combo("").Get(context.RepoRef(), repo.NewIssue).
@@ -1560,9 +1564,11 @@ func registerRoutes(m *web.Route) {
m.Get("/*", context.RepoRefByType(context.RepoRefLegacy), repo.Home)
}, repo.SetEditorconfigIfExists)
- m.Group("", func() {
- m.Get("/forks", repo.Forks)
- }, context.RepoRef(), reqRepoCodeReader)
+ if !setting.Repository.DisableForks {
+ m.Group("", func() {
+ m.Get("/forks", repo.Forks)
+ }, context.RepoRef(), reqRepoCodeReader)
+ }
m.Get("/commit/{sha:([a-f0-9]{4,64})}.{ext:patch|diff}", repo.MustBeNotEmpty, reqRepoCodeReader, repo.RawDiff)
}, ignSignIn, context.RepoAssignment, context.UnitTypes())