aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/shared
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-12-08 20:44:17 +0800
committerGitHub <noreply@github.com>2024-12-08 20:44:17 +0800
commit23471e1333b8289063e97cf27b6ad7796f593b47 (patch)
treebcb5cca70300ed374517f5a47194668a17a9e0c4 /routers/web/shared
parent9d08d3fbf5ca28fe8f056b9552bb06079fbaf449 (diff)
downloadgitea-23471e1333b8289063e97cf27b6ad7796f593b47.tar.gz
gitea-23471e1333b8289063e97cf27b6ad7796f593b47.zip
Refactor issue list (#32755)
1. add backend support for filtering "poster" and "assignee" * due to the limits, there is no frontend support at the moment 2. rewrite TS code without jquery, now there are 14 jQuery files left:
Diffstat (limited to 'routers/web/shared')
-rw-r--r--routers/web/shared/user/helper.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/routers/web/shared/user/helper.go b/routers/web/shared/user/helper.go
index dfd65420c1..7268767e0a 100644
--- a/routers/web/shared/user/helper.go
+++ b/routers/web/shared/user/helper.go
@@ -4,7 +4,9 @@
package user
import (
+ "context"
"slices"
+ "strconv"
"code.gitea.io/gitea/models/user"
)
@@ -24,3 +26,22 @@ func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
}
return users
}
+
+// GetFilterUserIDByName tries to get the user ID from the given username.
+// Before, the "issue filter" passes user ID to query the list, but in many cases, it's impossible to pre-fetch the full user list.
+// So it's better to make it work like GitHub: users could input username directly.
+// Since it only converts the username to ID directly and is only used internally (to search issues), so no permission check is needed.
+// Old usage: poster=123, new usage: poster=the-username (at the moment, non-existing username is treated as poster=0, not ideal but acceptable)
+func GetFilterUserIDByName(ctx context.Context, name string) int64 {
+ if name == "" {
+ return 0
+ }
+ u, err := user.GetUserByName(ctx, name)
+ if err != nil {
+ if id, err := strconv.ParseInt(name, 10, 64); err == nil {
+ return id
+ }
+ return 0
+ }
+ return u.ID
+}