From 931c02d1521b7b990f70a590c691b066dbc27d4d Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 15 Jul 2022 00:00:10 +0800 Subject: [PATCH] Add order by for assignee no sort issue (#20053) Co-authored-by: wxiaoguang --- models/issues/issue_list.go | 2 +- models/organization/team_repo.go | 1 + models/repo/user_repo.go | 4 ++-- models/user/user.go | 7 +++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index 20e9949b66..e311e80b1d 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -242,7 +242,7 @@ func (issues IssueList) loadAssignees(ctx context.Context) error { } rows, err := db.GetEngine(ctx).Table("issue_assignees"). Join("INNER", "`user`", "`user`.id = `issue_assignees`.assignee_id"). - In("`issue_assignees`.issue_id", issueIDs[:limit]). + In("`issue_assignees`.issue_id", issueIDs[:limit]).OrderBy(user_model.GetOrderByName()). Rows(new(AssigneeIssue)) if err != nil { return err diff --git a/models/organization/team_repo.go b/models/organization/team_repo.go index fb3f267f81..3ac4fa926b 100644 --- a/models/organization/team_repo.go +++ b/models/organization/team_repo.go @@ -81,5 +81,6 @@ func GetTeamsWithAccessToRepo(ctx context.Context, orgID, repoID int64, mode per Join("INNER", "team_repo", "team_repo.team_id = team.id"). And("team_repo.org_id = ?", orgID). And("team_repo.repo_id = ?", repoID). + OrderBy("name"). Find(&teams) } diff --git a/models/repo/user_repo.go b/models/repo/user_repo.go index e697505b81..71e0c57550 100644 --- a/models/repo/user_repo.go +++ b/models/repo/user_repo.go @@ -109,7 +109,7 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us // and just waste 1 unit is cheaper than re-allocate memory once. users := make([]*user_model.User, 0, len(userIDs)+1) if len(userIDs) > 0 { - if err = e.In("id", userIDs).Find(&users); err != nil { + if err = e.In("id", userIDs).OrderBy(user_model.GetOrderByName()).Find(&users); err != nil { return nil, err } } @@ -168,5 +168,5 @@ func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64) } users := make([]*user_model.User, 0, 8) - return users, db.GetEngine(ctx).Where(cond).OrderBy("name").Find(&users) + return users, db.GetEngine(ctx).Where(cond).OrderBy(user_model.GetOrderByName()).Find(&users) } diff --git a/models/user/user.go b/models/user/user.go index 125c643f3e..fbd8df9472 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -1314,3 +1314,10 @@ func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool { } return false } + +func GetOrderByName() string { + if setting.UI.DefaultShowFullName { + return "full_name, name" + } + return "name" +}