From fe657f5faafd468d0a58eb5cc962f0ce697d1bb5 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Mon, 31 Mar 2025 16:07:41 +1000 Subject: [PATCH] fix(ui): Fix disabled create repository button on create repo form (#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 repo limit, but were stll able to create a repo in an org, the button would still be disabled. - Resolves #7341 - Add Integration Tests to the create repo form Signed-off-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 94b1100aeb..fbe650003d 100644 --- a/options/locale_next/locale_en-US.json +++ b/options/locale_next/locale_en-US.json @@ -21,5 +21,6 @@ "alert.asset_load_failed": "Failed to load asset files from {path}. Please make sure the asset files can be accessed.", "alert.range_error": " must be a number between %[1]s and %[2]s.", "install.invalid_lfs_path": "Unable to create the LFS root at the specified path: %[1]s", + "repo.form.cannot_create": "The owner has already reached the repository limit. If you can create organization repositories, those organizations have also reached their limit.", "meta.last_line": "Thank you for translating Forgejo! This line isn't seen by the users but it serves other purposes in the translation management. You can place a fun fact in the translation instead of translating it." } 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"}}