From a0f902f635a7a8d5474e4d0ff9eb97c5da476496 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Tue, 20 May 2025 16:37:15 +0200 Subject: [PATCH] fix(ui): make limits clearer in create repo form (#7402) Resolves: #7341 Previously, the Create Repository button was only enabled if a user was able to create a repo in their own namespace. However, if they had reached the global repo limit, but were stlll able to create a repo in an org, the button would still be disabled. In this pull request, the create repo form now: 1. Behaves like it always did previously if the user has not reached the repo limit. 2. If the User has reached the repo limit, and they are unable to create a repo in any of their orgs (or they have no orgs), the create repo form is displayed as: ![Screenshot](/attachments/9f22f43d-0036-4c48-b794-54302c0f241c) 3. If the User has reached the repo limit, and the **limit is greater than zero**, an alert appears at the top of the form, and they are only allowed to choose from the orgs that they are allowed to create repos in: ![Screenshot](/attachments/f5508e05-74fd-4858-9e95-967bd7017abd) 4. If the User has reached the repo limit, and the **limit is equal to zero**, no alert is displayed, as no user can create repos on that instance, and they are only allowed to choose from the orgs that they are allowed to create repos in: ![localhost_3000_repo_create (4).png](/attachments/e7a87da8-c19c-47e1-845e-2afc3667ab02) Co-authored-by: 0ko <0ko@noreply.codeberg.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7402 Reviewed-by: Gusted Co-authored-by: Ryan Lerch Co-committed-by: Ryan Lerch --- models/fixtures/user.yml | 2 +- options/locale_next/locale_en-US.json | 1 + templates/repo/create.tmpl | 70 ++++++++++++++----------- templates/repo/create_basic.tmpl | 28 ++++++---- tests/integration/repo_generate_test.go | 57 ++++++++++++++++++++ 5 files changed, 116 insertions(+), 42 deletions(-) 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"}}
- {{template "base/alert" .}} - {{template "repo/create_helper" .}} + {{if or .CanCreateRepo .Orgs}} + {{template "base/alert" .}} + {{template "repo/create_helper" .}} - {{if not .CanCreateRepo}} + {{if and (not .CanCreateRepo) (ne .MaxCreationLimit 0)}} +
+

{{ctx.Locale.TrN .MaxCreationLimit "repo.form.reach_limit_of_creation_1" "repo.form.reach_limit_of_creation_n" .MaxCreationLimit}}

+
+ {{end}} +
+ {{template "repo/create_basic" .}} +
+ +
+ + {{ctx.Locale.Tr "repo.new_from_template"}} + {{ctx.Locale.Tr "repo.new_from_template_description"}} + + {{template "repo/create_from_template" .}} +
+ +
+
+ {{ctx.Locale.Tr "repo.auto_init"}} + {{template "repo/create_init" .}} +
+ +
+ {{ctx.Locale.Tr "repo.new_advanced"}} +
{{ctx.Locale.Tr "repo.new_advanced_expand"}} + {{template "repo/create_advanced" .}} +
+
+
+ + {{else}}
-

{{ctx.Locale.TrN .MaxCreationLimit "repo.form.reach_limit_of_creation_1" "repo.form.reach_limit_of_creation_n" .MaxCreationLimit}}

+ {{ctx.Locale.Tr "repo.form.cannot_create"}}
{{end}} -
- {{template "repo/create_basic" .}} -
- -
- - {{ctx.Locale.Tr "repo.new_from_template"}} - {{ctx.Locale.Tr "repo.new_from_template_description"}} - - {{template "repo/create_from_template" .}} -
- -
-
- {{ctx.Locale.Tr "repo.auto_init"}} - {{template "repo/create_init" .}} -
- -
- {{ctx.Locale.Tr "repo.new_advanced"}} -
{{ctx.Locale.Tr "repo.new_advanced_expand"}} - {{template "repo/create_advanced" .}} -
-
-
-
diff --git a/templates/repo/create_basic.tmpl b/templates/repo/create_basic.tmpl index 0396629fef..90545c2769 100644 --- a/templates/repo/create_basic.tmpl +++ b/templates/repo/create_basic.tmpl @@ -2,17 +2,27 @@ {{ctx.Locale.Tr "repo.owner"}}