Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve user search display name #29002

Merged
merged 11 commits into from
Feb 1, 2024
8 changes: 0 additions & 8 deletions routers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<br>")
Expand Down
6 changes: 0 additions & 6 deletions routers/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions routers/web/org/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions routers/web/repo/setting/collaboration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions web_src/js/features/comp/SearchUserBox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import $ from 'jquery';
import {htmlEscape} from 'escape-goat';

const {appSubUrl} = window.config;
const looksLikeEmailAddressCheck = /^\S+@\S+$/;
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion web_src/js/features/repo-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export function initRepoSettingSearchTeamBox() {
$.each(response.data, (_i, item) => {
const title = `${item.name} (${item.permission} access)`;
items.push({
KN4CK3R marked this conversation as resolved.
Show resolved Hide resolved
title,
title: item.name,
description: `${item.permission} access`
silverwind marked this conversation as resolved.
Show resolved Hide resolved
});
});

Expand Down
Loading