From b3a0ec49c26455e7c8457e0df736d179ecc63f62 Mon Sep 17 00:00:00 2001 From: kerwin612 Date: Fri, 13 Jun 2025 19:13:49 +0800 Subject: [PATCH] fix --- routers/web/repo/fork.go | 2 +- templates/repo/pulls/fork.tmpl | 4 ++-- tests/integration/repo_fork_test.go | 2 +- web_src/js/index.ts | 2 -- web_src/js/modules/form.ts | 30 ----------------------------- 5 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 web_src/js/modules/form.ts diff --git a/routers/web/repo/fork.go b/routers/web/repo/fork.go index 79f033659b..6ae459c0ad 100644 --- a/routers/web/repo/fork.go +++ b/routers/web/repo/fork.go @@ -228,5 +228,5 @@ func ForkPost(ctx *context.Context) { } log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name) - ctx.Redirect(ctxUser.HomeLink() + "/" + url.PathEscape(repo.Name)) + ctx.JSONRedirect(ctxUser.HomeLink() + "/" + url.PathEscape(repo.Name)) } diff --git a/templates/repo/pulls/fork.tmpl b/templates/repo/pulls/fork.tmpl index 0a384151ae..0d775ed6a0 100644 --- a/templates/repo/pulls/fork.tmpl +++ b/templates/repo/pulls/fork.tmpl @@ -6,7 +6,7 @@
{{template "base/alert" .}} -
+ {{.CsrfTokenHtml}}
@@ -75,7 +75,7 @@
-
diff --git a/tests/integration/repo_fork_test.go b/tests/integration/repo_fork_test.go index a7010af14a..94f8e61c5b 100644 --- a/tests/integration/repo_fork_test.go +++ b/tests/integration/repo_fork_test.go @@ -51,7 +51,7 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO "repo_name": forkRepoName, "fork_single_branch": forkBranch, }) - session.MakeRequest(t, req, http.StatusSeeOther) + session.MakeRequest(t, req, http.StatusOK) // Step4: check the existence of the forked repo req = NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName) diff --git a/web_src/js/index.ts b/web_src/js/index.ts index 0c70f2f437..7e84773bc1 100644 --- a/web_src/js/index.ts +++ b/web_src/js/index.ts @@ -65,7 +65,6 @@ import {initGlobalButtonClickOnEnter, initGlobalButtons, initGlobalDeleteButton} import {initGlobalComboMarkdownEditor, initGlobalEnterQuickSubmit, initGlobalFormDirtyLeaveConfirm} from './features/common-form.ts'; import {callInitFunctions} from './modules/init.ts'; import {initRepoViewFileTree} from './features/repo-view-file-tree.ts'; -import {initFormSubmitHandlers} from './modules/form.ts'; initGiteaFomantic(); initSubmitEventPolyfill(); @@ -86,7 +85,6 @@ onDomReady(() => { initGlobalComboMarkdownEditor, initGlobalDeleteButton, initGlobalInput, - initFormSubmitHandlers, initCommonOrganization, initCommonIssueListQuickGoto, diff --git a/web_src/js/modules/form.ts b/web_src/js/modules/form.ts deleted file mode 100644 index dd48eb0039..0000000000 --- a/web_src/js/modules/form.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Form handling utilities - */ - -import {addDelegatedEventListener} from '../utils/dom.ts'; - -/** - * Prevent duplicate form submission - * @param form The form element - * @param submitter The submit button element - */ -function preventDuplicateSubmit(form: HTMLFormElement, submitter: HTMLElement) { - form.addEventListener('submit', () => { - submitter.classList.add('disabled'); - submitter.setAttribute('disabled', 'disabled'); - }); -} - -/** - * Initialize form submit handlers - */ -export function initFormSubmitHandlers() { - // Add delegated event listener for forms with data-prevent-duplicate attribute - addDelegatedEventListener(document, 'submit', 'form[data-prevent-duplicate]', (form: HTMLFormElement) => { - const submitter = form.querySelector('button[type="submit"]'); - if (submitter) { - preventDuplicateSubmit(form, submitter); - } - }); -}