From b6be9fb901ac878602241f1909c2d9ae60c5fcef Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 8 May 2024 21:14:46 +0000 Subject: [PATCH] Fix an incorrect form submission in repo-issue.js (#3675) This fixes `initRepoPullRequestAllowMaintainerEdit()` to submit the form correctly (as a web form, rather than as JSON payload). Fixes #3618, cherry picked from gitea#30854. Co-Authored-By: wxiaoguang --- Manual testing steps: - Open a PR against any repository, with the "Allow edits from maintainers" option checked. - Open the developer console (`Ctrl-Shift-I` on Firefox), and look at the Network tab. - Visit the PR, find the "Allow edits from maintainers" checkbox, and click it. - See the developer console, and check that the response says the setting is false. - Refresh the page *completely* (`Ctrl-Shift-R` on Firefox) - Observe that the setting is off. - Click the box again to enable it. - See the developer console, and check that the response says the setting is true. - Reload without cache again (`Ctrl-Shift-R` on Firefox) - Observe that the setting is now on. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3675 Reviewed-by: Earl Warren Co-authored-by: Gergely Nagy Co-committed-by: Gergely Nagy (cherry picked from commit f4dd53d79dda7481cd29634727cd8e2caae8d7fe) --- release-notes/8.0.0/fix/3675.md | 1 + web_src/js/features/repo-issue.js | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 release-notes/8.0.0/fix/3675.md diff --git a/release-notes/8.0.0/fix/3675.md b/release-notes/8.0.0/fix/3675.md new file mode 100644 index 0000000000..c6feed07ca --- /dev/null +++ b/release-notes/8.0.0/fix/3675.md @@ -0,0 +1 @@ +Fixed an issue that rendered the "Allow edits from maintainers" checkbox disfunctional, preventing people from turning it on. diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 52fe0303b3..8d057e37a9 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -284,23 +284,23 @@ export function initRepoPullRequestMergeInstruction() { export function initRepoPullRequestAllowMaintainerEdit() { const wrapper = document.getElementById('allow-edits-from-maintainers'); if (!wrapper) return; - - wrapper.querySelector('input[type="checkbox"]')?.addEventListener('change', async (e) => { - const checked = e.target.checked; + const checkbox = wrapper.querySelector('input[type="checkbox"]'); + checkbox.addEventListener('input', async () => { const url = `${wrapper.getAttribute('data-url')}/set_allow_maintainer_edit`; wrapper.classList.add('is-loading'); - e.target.disabled = true; try { - const response = await POST(url, {data: {allow_maintainer_edit: checked}}); - if (!response.ok) { + const resp = await POST(url, {data: new URLSearchParams({allow_maintainer_edit: checkbox.checked})}); + if (!resp.ok) { throw new Error('Failed to update maintainer edit permission'); } + const data = await resp.json(); + checkbox.checked = data.allow_maintainer_edit; } catch (error) { + checkbox.checked = !checkbox.checked; console.error(error); showTemporaryTooltip(wrapper, wrapper.getAttribute('data-prompt-error')); } finally { wrapper.classList.remove('is-loading'); - e.target.disabled = false; } }); }