From 081334f78d2dfc59bc25b69d929dbbb7378e5a34 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 31 Jan 2024 22:19:04 +0000 Subject: [PATCH 01/10] Use description for extra info. --- routers/utils/utils.go | 8 -------- routers/utils/utils_test.go | 6 ------ routers/web/org/teams.go | 3 +-- routers/web/repo/setting/collaboration.go | 5 ++--- web_src/js/features/comp/SearchUserBox.js | 10 ++++------ web_src/js/features/repo-settings.js | 3 ++- 6 files changed, 9 insertions(+), 26 deletions(-) diff --git a/routers/utils/utils.go b/routers/utils/utils.go index d6856fceacd20..1f4d11fd3ccaf 100644 --- a/routers/utils/utils.go +++ b/routers/utils/utils.go @@ -11,14 +11,6 @@ import ( "code.gitea.io/gitea/modules/setting" ) -// RemoveUsernameParameterSuffix returns the username parameter without the (fullname) suffix - leaving just the username -func RemoveUsernameParameterSuffix(name string) string { - if index := strings.Index(name, " ("); index >= 0 { - name = name[:index] - } - return name -} - // SanitizeFlashErrorString will sanitize a flash error string func SanitizeFlashErrorString(x string) string { return strings.ReplaceAll(html.EscapeString(x), "\n", "
") diff --git a/routers/utils/utils_test.go b/routers/utils/utils_test.go index 6d19214c88e57..440aad87c6bea 100644 --- a/routers/utils/utils_test.go +++ b/routers/utils/utils_test.go @@ -11,12 +11,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestRemoveUsernameParameterSuffix(t *testing.T) { - assert.Equal(t, "foobar", RemoveUsernameParameterSuffix("foobar (Foo Bar)")) - assert.Equal(t, "foobar", RemoveUsernameParameterSuffix("foobar")) - assert.Equal(t, "", RemoveUsernameParameterSuffix("")) -} - func TestIsExternalURL(t *testing.T) { setting.AppURL = "https://try.gitea.io/" type test struct { diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 9e65c8ba9cd95..71fe99c97c70d 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -24,7 +24,6 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/web" - "code.gitea.io/gitea/routers/utils" shared_user "code.gitea.io/gitea/routers/web/shared/user" "code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/forms" @@ -127,7 +126,7 @@ func TeamsAction(ctx *context.Context) { ctx.Error(http.StatusNotFound) return } - uname := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("uname"))) + uname := strings.ToLower(ctx.FormString("uname")) var u *user_model.User u, err = user_model.GetUserByName(ctx, uname) if err != nil { diff --git a/routers/web/repo/setting/collaboration.go b/routers/web/repo/setting/collaboration.go index e217697cc0adc..c5c2a88c49cf3 100644 --- a/routers/web/repo/setting/collaboration.go +++ b/routers/web/repo/setting/collaboration.go @@ -17,7 +17,6 @@ import ( "code.gitea.io/gitea/modules/log" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/routers/utils" "code.gitea.io/gitea/services/mailer" org_service "code.gitea.io/gitea/services/org" repo_service "code.gitea.io/gitea/services/repository" @@ -52,7 +51,7 @@ func Collaboration(ctx *context.Context) { // CollaborationPost response for actions for a collaboration of a repository func CollaborationPost(ctx *context.Context) { - name := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("collaborator"))) + name := strings.ToLower(ctx.FormString("collaborator")) if len(name) == 0 || ctx.Repo.Owner.LowerName == name { ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath()) return @@ -144,7 +143,7 @@ func AddTeamPost(ctx *context.Context) { return } - name := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("team"))) + name := strings.ToLower(ctx.FormString("team")) if len(name) == 0 { ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration") return diff --git a/web_src/js/features/comp/SearchUserBox.js b/web_src/js/features/comp/SearchUserBox.js index 960b787fea6b6..191d6cad2513b 100644 --- a/web_src/js/features/comp/SearchUserBox.js +++ b/web_src/js/features/comp/SearchUserBox.js @@ -1,5 +1,4 @@ import $ from 'jquery'; -import {htmlEscape} from 'escape-goat'; const {appSubUrl} = window.config; const looksLikeEmailAddressCheck = /^\S+@\S+$/; @@ -17,14 +16,13 @@ export function initCompSearchUserBox() { const searchQuery = $searchUserBox.find('input').val(); const searchQueryUppercase = searchQuery.toUpperCase(); $.each(response.data, (_i, item) => { - let title = item.login; - if (item.full_name && item.full_name.length > 0) { - title += ` (${htmlEscape(item.full_name)})`; - } const resultItem = { - title, + title: item.login, image: item.avatar_url }; + if (item.full_name && item.full_name.length > 0) { + resultItem.description = item.full_name; + } if (searchQueryUppercase === item.login.toUpperCase()) { items.unshift(resultItem); } else { diff --git a/web_src/js/features/repo-settings.js b/web_src/js/features/repo-settings.js index 04974200bb996..1a9026aa722d7 100644 --- a/web_src/js/features/repo-settings.js +++ b/web_src/js/features/repo-settings.js @@ -54,7 +54,8 @@ export function initRepoSettingSearchTeamBox() { $.each(response.data, (_i, item) => { const title = `${item.name} (${item.permission} access)`; items.push({ - title, + title: item.name, + description: `${item.permission} access` }); }); From 07cf3bbd8a0fd46a60f1cfef4765b66b5fb2c004 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Thu, 1 Feb 2024 12:28:01 +0000 Subject: [PATCH 02/10] Re-Add escaping. --- web_src/js/features/comp/SearchUserBox.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web_src/js/features/comp/SearchUserBox.js b/web_src/js/features/comp/SearchUserBox.js index 191d6cad2513b..b298a2a6bee5e 100644 --- a/web_src/js/features/comp/SearchUserBox.js +++ b/web_src/js/features/comp/SearchUserBox.js @@ -1,4 +1,5 @@ import $ from 'jquery'; +import {htmlEscape} from 'escape-goat'; const {appSubUrl} = window.config; const looksLikeEmailAddressCheck = /^\S+@\S+$/; @@ -21,7 +22,7 @@ export function initCompSearchUserBox() { image: item.avatar_url }; if (item.full_name && item.full_name.length > 0) { - resultItem.description = item.full_name; + resultItem.description = htmlEscape(item.full_name); } if (searchQueryUppercase === item.login.toUpperCase()) { items.unshift(resultItem); From 3325febc221fb4fa315f916fa3a91b5771fcbb54 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Thu, 1 Feb 2024 12:39:37 +0000 Subject: [PATCH 03/10] Remove unused variable. --- web_src/js/features/repo-settings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/web_src/js/features/repo-settings.js b/web_src/js/features/repo-settings.js index 1a9026aa722d7..fd4e712bcd725 100644 --- a/web_src/js/features/repo-settings.js +++ b/web_src/js/features/repo-settings.js @@ -52,7 +52,6 @@ export function initRepoSettingSearchTeamBox() { onResponse(response) { const items = []; $.each(response.data, (_i, item) => { - const title = `${item.name} (${item.permission} access)`; items.push({ title: item.name, description: `${item.permission} access` From 9a3470d9c1317dbc021feb81ae94b8f654063b2d Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 1 Feb 2024 16:41:49 +0100 Subject: [PATCH 04/10] css fixes for search box --- web_src/css/base.css | 3 +++ web_src/css/repo.css | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/web_src/css/base.css b/web_src/css/base.css index cc1f6a8397614..2e26ab23d8aa3 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -200,6 +200,9 @@ a.label, .ui.search > .results .result { background: var(--color-body); + border-color: var(--color-secondary); + display: flex; + align-items: center; } .ui.search > .results .result .title { diff --git a/web_src/css/repo.css b/web_src/css/repo.css index dfe0d6c77f5e5..26f3fb6ba1984 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -2128,14 +2128,17 @@ } #search-user-box .results .result .image { - float: left; - margin-right: 8px; + order: 0; + margin-right: 12px; width: 2em; height: 2em; + min-width: 2em; + min-height: 2em; } #search-user-box .results .result .content { margin: 6px 0; /* this trick is used to align with the sibling avatar image */ + overflow-wrap: anywhere; } .ui.menu .item > img:not(.ui) { From bfcca7175d17dab0ae2ab82e4bab10fd32f998fb Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 1 Feb 2024 16:55:40 +0100 Subject: [PATCH 05/10] move selector --- web_src/css/base.css | 1 + web_src/css/repo.css | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/css/base.css b/web_src/css/base.css index 2e26ab23d8aa3..198e87c0e202f 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -196,6 +196,7 @@ a.label, .ui.search > .results { background: var(--color-body); border-color: var(--color-secondary); + overflow-wrap: anywhere; /* allow text to wrap as fomantic limits this to 18em width */ } .ui.search > .results .result { diff --git a/web_src/css/repo.css b/web_src/css/repo.css index 26f3fb6ba1984..02e04831968bb 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -2138,7 +2138,6 @@ #search-user-box .results .result .content { margin: 6px 0; /* this trick is used to align with the sibling avatar image */ - overflow-wrap: anywhere; } .ui.menu .item > img:not(.ui) { From 28be871aa41418c8dc0120030a56d7833dcd71ad Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 1 Feb 2024 16:57:44 +0100 Subject: [PATCH 06/10] remove outdated comment --- web_src/css/repo.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/css/repo.css b/web_src/css/repo.css index 02e04831968bb..010a5788f7b7a 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -2137,7 +2137,7 @@ } #search-user-box .results .result .content { - margin: 6px 0; /* this trick is used to align with the sibling avatar image */ + margin: 6px 0; } .ui.menu .item > img:not(.ui) { From 6da06851c76a0358c4063d58f2e0cedb283000b1 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 1 Feb 2024 17:40:41 +0100 Subject: [PATCH 07/10] fix margin and add comment --- web_src/css/repo.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/css/repo.css b/web_src/css/repo.css index 010a5788f7b7a..b28d7182d9b4b 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -2137,7 +2137,7 @@ } #search-user-box .results .result .content { - margin: 6px 0; + margin: 0; /* remove margin reserved for avatar becaue we move it to left via `order: 0` */ } .ui.menu .item > img:not(.ui) { From cd6187256afee9072cd6c6c7ba4679dcee2cd3f5 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 1 Feb 2024 17:41:26 +0100 Subject: [PATCH 08/10] Update web_src/js/features/comp/SearchUserBox.js Co-authored-by: wxiaoguang --- web_src/js/features/comp/SearchUserBox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/comp/SearchUserBox.js b/web_src/js/features/comp/SearchUserBox.js index b298a2a6bee5e..992d4ef0206db 100644 --- a/web_src/js/features/comp/SearchUserBox.js +++ b/web_src/js/features/comp/SearchUserBox.js @@ -21,7 +21,7 @@ export function initCompSearchUserBox() { title: item.login, image: item.avatar_url }; - if (item.full_name && item.full_name.length > 0) { + if (item.full_name) { resultItem.description = htmlEscape(item.full_name); } if (searchQueryUppercase === item.login.toUpperCase()) { From e7cb1244bcf80dae0bd630021607ba3ca7387f4c Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 1 Feb 2024 17:42:27 +0100 Subject: [PATCH 09/10] Add TODO --- web_src/js/features/repo-settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/repo-settings.js b/web_src/js/features/repo-settings.js index fd4e712bcd725..75e624a6a736f 100644 --- a/web_src/js/features/repo-settings.js +++ b/web_src/js/features/repo-settings.js @@ -54,7 +54,7 @@ export function initRepoSettingSearchTeamBox() { $.each(response.data, (_i, item) => { items.push({ title: item.name, - description: `${item.permission} access` + description: `${item.permission} access` // TODO: translate this string }); }); From 9eceb9a93a4ef0050e3e4810b4258a4eb1587809 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 1 Feb 2024 17:46:06 +0100 Subject: [PATCH 10/10] fix typo --- web_src/css/repo.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/css/repo.css b/web_src/css/repo.css index b28d7182d9b4b..55c6ec4817187 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -2137,7 +2137,7 @@ } #search-user-box .results .result .content { - margin: 0; /* remove margin reserved for avatar becaue we move it to left via `order: 0` */ + margin: 0; /* remove margin reserved for avatar because we move it to left via `order: 0` */ } .ui.menu .item > img:not(.ui) {