From 15debbbe4eb94c1855a0178e379b7e3d19bd07ad Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 7 Jun 2024 15:37:33 +0200 Subject: [PATCH 01/46] Enable poetry non-package mode (#31282) [Poetry 1.8.0](https://github.com/python-poetry/poetry/releases/tag/1.8.0) added support for [non-package mode](https://python-poetry.org/docs/basic-usage/#operating-modes), e.g. projects that are not python packages themselves like we are. Make use of that and remove the previous workaround via `--no-root`. --- Makefile | 4 ++-- pyproject.toml | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d97360c9f4..b5a79091eb 100644 --- a/Makefile +++ b/Makefile @@ -878,7 +878,7 @@ node_modules: package-lock.json @touch node_modules .venv: poetry.lock - poetry install --no-root + poetry install @touch .venv .PHONY: update @@ -895,7 +895,7 @@ update-js: node-check | node_modules update-py: node-check | node_modules npx updates -u -f pyproject.toml rm -rf .venv poetry.lock - poetry install --no-root + poetry install @touch .venv .PHONY: fomantic diff --git a/pyproject.toml b/pyproject.toml index bb768d5cb1..0724a8e24a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,5 @@ [tool.poetry] -name = "gitea" -version = "0.0.0" -description = "" -authors = [] +package-mode = false [tool.poetry.dependencies] python = "^3.10" From 291a00dc570a143092e5ad19cdad12939d3d70dc Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 7 Jun 2024 15:42:31 +0200 Subject: [PATCH 02/46] Fix and clean up `ConfirmModal` (#31283) Bug: orange button color was removed in https://github.com/go-gitea/gitea/pull/30475, replaced with red Bug: translation text was not html-escaped Refactor: Replaced as much jQuery as possible, added useful `createElementFromHTML` Refactor: Remove colors checks that don't exist on `.link-action` image --------- Co-authored-by: wxiaoguang Co-authored-by: delvh --- web_src/js/features/common-global.js | 4 ++-- web_src/js/features/comp/ConfirmModal.js | 25 ++++++++++++------------ web_src/js/features/repo-issue-list.js | 2 +- web_src/js/utils/dom.js | 7 +++++++ web_src/js/utils/dom.test.js | 5 +++++ 5 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 web_src/js/utils/dom.test.js diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 3b021d4485..65eb237dde 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -295,8 +295,8 @@ async function linkAction(e) { return; } - const isRisky = el.classList.contains('red') || el.classList.contains('yellow') || el.classList.contains('orange') || el.classList.contains('negative'); - if (await confirmModal({content: modalConfirmContent, buttonColor: isRisky ? 'orange' : 'primary'})) { + const isRisky = el.classList.contains('red') || el.classList.contains('negative'); + if (await confirmModal(modalConfirmContent, {confirmButtonColor: isRisky ? 'red' : 'primary'})) { await doRequest(); } } diff --git a/web_src/js/features/comp/ConfirmModal.js b/web_src/js/features/comp/ConfirmModal.js index e64996a352..f9ad5c39cc 100644 --- a/web_src/js/features/comp/ConfirmModal.js +++ b/web_src/js/features/comp/ConfirmModal.js @@ -1,22 +1,23 @@ import $ from 'jquery'; import {svg} from '../../svg.js'; import {htmlEscape} from 'escape-goat'; +import {createElementFromHTML} from '../../utils/dom.js'; const {i18n} = window.config; -export async function confirmModal(opts = {content: '', buttonColor: 'primary'}) { +export function confirmModal(content, {confirmButtonColor = 'primary'} = {}) { return new Promise((resolve) => { - const $modal = $(` - -`); - - $modal.appendTo(document.body); + const modal = createElementFromHTML(` + + `); + document.body.append(modal); + const $modal = $(modal); $modal.modal({ onApprove() { resolve(true); diff --git a/web_src/js/features/repo-issue-list.js b/web_src/js/features/repo-issue-list.js index 92f058c4d2..5d18a7ff8d 100644 --- a/web_src/js/features/repo-issue-list.js +++ b/web_src/js/features/repo-issue-list.js @@ -76,7 +76,7 @@ function initRepoIssueListCheckboxes() { // for delete if (action === 'delete') { const confirmText = e.target.getAttribute('data-action-delete-confirm'); - if (!await confirmModal({content: confirmText, buttonColor: 'orange'})) { + if (!await confirmModal(confirmText, {confirmButtonColor: 'red'})) { return; } } diff --git a/web_src/js/utils/dom.js b/web_src/js/utils/dom.js index a48510b191..7289f19cbf 100644 --- a/web_src/js/utils/dom.js +++ b/web_src/js/utils/dom.js @@ -297,3 +297,10 @@ export function replaceTextareaSelection(textarea, text) { textarea.dispatchEvent(new CustomEvent('change', {bubbles: true, cancelable: true})); } } + +// Warning: Do not enter any unsanitized variables here +export function createElementFromHTML(htmlString) { + const div = document.createElement('div'); + div.innerHTML = htmlString.trim(); + return div.firstChild; +} diff --git a/web_src/js/utils/dom.test.js b/web_src/js/utils/dom.test.js new file mode 100644 index 0000000000..fd7d97cad5 --- /dev/null +++ b/web_src/js/utils/dom.test.js @@ -0,0 +1,5 @@ +import {createElementFromHTML} from './dom.js'; + +test('createElementFromHTML', () => { + expect(createElementFromHTML('foobar').outerHTML).toEqual('foobar'); +}); From 0188d82e4908eb173f7203d577f801f3168ffcb8 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 7 Jun 2024 23:15:17 +0800 Subject: [PATCH 03/46] Fix some URLs whose sub-path is missing (#31289) Fix #31285 --- templates/admin/packages/list.tmpl | 2 +- templates/devtest/fetch-action.tmpl | 2 +- templates/user/settings/applications.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/admin/packages/list.tmpl b/templates/admin/packages/list.tmpl index 863f11da25..d1d77b6220 100644 --- a/templates/admin/packages/list.tmpl +++ b/templates/admin/packages/list.tmpl @@ -5,7 +5,7 @@ {{ctx.Locale.Tr "admin.packages.total_size" (FileSize .TotalBlobSize)}}, {{ctx.Locale.Tr "admin.packages.unreferenced_size" (FileSize .TotalUnreferencedBlobSize)}})
-
+ {{.CsrfTokenHtml}}
diff --git a/templates/devtest/fetch-action.tmpl b/templates/devtest/fetch-action.tmpl index 2b25e6c9c4..66f41fc6de 100644 --- a/templates/devtest/fetch-action.tmpl +++ b/templates/devtest/fetch-action.tmpl @@ -25,7 +25,7 @@
-
+
bad action url
diff --git a/templates/user/settings/applications.tmpl b/templates/user/settings/applications.tmpl index 8c67653e58..3c1934dd8b 100644 --- a/templates/user/settings/applications.tmpl +++ b/templates/user/settings/applications.tmpl @@ -75,7 +75,7 @@ {{ctx.Locale.Tr "settings.select_permissions"}}

- {{ctx.Locale.Tr "settings.access_token_desc" (`href="/api/swagger" target="_blank"`|SafeHTML) (`href="https://docs.gitea.com/development/oauth2-provider#scopes" target="_blank"`|SafeHTML)}} + {{ctx.Locale.Tr "settings.access_token_desc" (HTMLFormat `href="%s/api/swagger" target="_blank"` AppSubUrl) (`href="https://docs.gitea.com/development/oauth2-provider#scopes" target="_blank"`|SafeHTML)}}

Date: Sun, 9 Jun 2024 16:29:29 +0800 Subject: [PATCH 04/46] Remove sub-path from container registry realm (#31293) Container registry requires that the "/v2" must be in the root, so the sub-path in AppURL should be removed --- modules/setting/packages.go | 5 ----- modules/test/utils.go | 6 ++++-- routers/api/packages/container/container.go | 6 +++--- routers/web/user/package.go | 8 +++++++- tests/integration/api_packages_container_test.go | 12 +++++++++--- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/modules/setting/packages.go b/modules/setting/packages.go index b225615a24..00fba67b39 100644 --- a/modules/setting/packages.go +++ b/modules/setting/packages.go @@ -6,7 +6,6 @@ package setting import ( "fmt" "math" - "net/url" "os" "path/filepath" @@ -19,7 +18,6 @@ var ( Storage *Storage Enabled bool ChunkedUploadPath string - RegistryHost string LimitTotalOwnerCount int64 LimitTotalOwnerSize int64 @@ -66,9 +64,6 @@ func loadPackagesFrom(rootCfg ConfigProvider) (err error) { return err } - appURL, _ := url.Parse(AppURL) - Packages.RegistryHost = appURL.Host - Packages.ChunkedUploadPath = filepath.ToSlash(sec.Key("CHUNKED_UPLOAD_PATH").MustString("tmp/package-upload")) if !filepath.IsAbs(Packages.ChunkedUploadPath) { Packages.ChunkedUploadPath = filepath.ToSlash(filepath.Join(AppDataPath, Packages.ChunkedUploadPath)) diff --git a/modules/test/utils.go b/modules/test/utils.go index 4a0c2f1b3b..8dee92fbce 100644 --- a/modules/test/utils.go +++ b/modules/test/utils.go @@ -34,8 +34,10 @@ func IsNormalPageCompleted(s string) bool { return strings.Contains(s, `