diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml
index 630505b8b4..52080b092f 100644
--- a/models/fixtures/user.yml
+++ b/models/fixtures/user.yml
@@ -93,7 +93,7 @@
login_name: org3
type: 1
salt: ZogKvWdyEx
- max_repo_creation: -1
+ max_repo_creation: 1000
is_active: false
is_admin: false
is_restricted: false
diff --git a/options/locale_next/locale_en-US.json b/options/locale_next/locale_en-US.json
index ec5c313a90..195f58af80 100644
--- a/options/locale_next/locale_en-US.json
+++ b/options/locale_next/locale_en-US.json
@@ -46,6 +46,7 @@
"one": "wants to merge %[1]d commit from %[2]s into %[3]s",
"other": "wants to merge %[1]d commits from %[2]s into %[3]s"
},
+ "repo.form.cannot_create": "All spaces in which you can create repositories have reached the limit of repositories.",
"search.milestone_kind": "Search milestones…",
"incorrect_root_url": "This Forgejo instance is configured to be served on \"%s\". You are currently viewing Forgejo through a different URL, which may cause parts of the application to break. The canonical URL is controlled by Forgejo admins via the ROOT_URL setting in the app.ini.",
"themes.names.forgejo-auto": "Forgejo (follow system theme)",
diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl
index 7ee8587435..7c07f80c86 100644
--- a/templates/repo/create.tmpl
+++ b/templates/repo/create.tmpl
@@ -8,42 +8,48 @@
{{ctx.Locale.Tr "new_repo.title"}}
{{ctx.AvatarUtils.Avatar . 28 "mini"}}
diff --git a/tests/integration/repo_generate_test.go b/tests/integration/repo_generate_test.go
index f039b08f06..d22e6ecc74 100644
--- a/tests/integration/repo_generate_test.go
+++ b/tests/integration/repo_generate_test.go
@@ -126,6 +126,63 @@ func TestRepoCreateForm(t *testing.T) {
assertRepoCreateForm(t, htmlDoc, user, "")
}
+func TestRepoCreateFormRepoLimit(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+ org := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "org3"})
+ userName := "user2"
+ session := loginUser(t, userName)
+ locale := translation.NewLocale("en-US")
+ cannotCreateTr := locale.Tr("repo.form.cannot_create")
+
+ // Test the case where a user has hit the global max creation limit, but can still create
+ // a repo in an organization. Because the limit is greater than 0 we also show an alert
+ // to tell the user they have hit the limit.
+ t.Run("Limit above zero", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+ maxCreationLimit := 1
+ creationLimitTr := locale.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
+ defer test.MockVariableValue(&setting.Repository.MaxCreationLimit, maxCreationLimit)()
+
+ resp := session.MakeRequest(t, NewRequest(t, "GET", "/repo/create"), http.StatusOK)
+ htmlDoc := NewHTMLParser(t, resp.Body)
+ assertRepoCreateForm(t, htmlDoc, org, "")
+
+ alert := htmlDoc.doc.Find("div.ui.negative.message").Text()
+ assert.Contains(t, alert, creationLimitTr)
+ })
+
+ // Test the case where a user has hit the global max creation limit, but can still create
+ // a repo in an organization. Because the limit is 0 we DO NOT show the alert.
+ t.Run("Limit is zero", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+ maxCreationLimit := 0
+ defer test.MockVariableValue(&setting.Repository.MaxCreationLimit, maxCreationLimit)()
+
+ resp := session.MakeRequest(t, NewRequest(t, "GET", "/repo/create"), http.StatusOK)
+ htmlDoc := NewHTMLParser(t, resp.Body)
+ assertRepoCreateForm(t, htmlDoc, org, "")
+
+ htmlDoc.AssertElement(t, "div.ui.negative.message", false)
+ })
+
+ // Test the case where a user has hit the global max creation limit, and also cannot create
+ // a repo in any of their orgs. The form isnt shown, and we deisplay an alert telling the user
+ // they can't create a repo.
+ t.Run("Global limit", func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+ maxCreationLimit := 0
+ defer test.MockVariableValue(&setting.Repository.MaxCreationLimit, maxCreationLimit)()
+
+ session := loginUser(t, "user8")
+
+ resp := session.MakeRequest(t, NewRequest(t, "GET", "/repo/create"), http.StatusOK)
+ htmlDoc := NewHTMLParser(t, resp.Body)
+
+ alert := htmlDoc.doc.Find("div.ui.negative.message").Text()
+ assert.Contains(t, alert, cannotCreateTr)
+ })
+}
+
func TestRepoGenerate(t *testing.T) {
defer tests.PrepareTestEnv(t)()
userName := "user1"