Add parameter to return group members in order of display name (#21775)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fae9bdf173
Коммит
33b59e0e96
23
api4/user.go
23
api4/user.go
@@ -662,13 +662,14 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if sort != "" && sort != "last_activity_at" && sort != "create_at" && sort != "status" && sort != "admin" {
|
||||
if sort != "" && sort != "last_activity_at" && sort != "create_at" && sort != "status" && sort != "admin" && sort != "display_name" {
|
||||
c.SetInvalidURLParam("sort")
|
||||
return
|
||||
}
|
||||
|
||||
// Currently only supports sorting on a team
|
||||
// or sort="status" on inChannelId
|
||||
// or sort="display_name" on inGroupId
|
||||
if (sort == "last_activity_at" || sort == "create_at") && (inTeamId == "" || notInTeamId != "" || inChannelId != "" || notInChannelId != "" || withoutTeam != "" || inGroupId != "" || notInGroupId != "") {
|
||||
c.SetInvalidURLParam("sort")
|
||||
return
|
||||
@@ -681,6 +682,10 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.SetInvalidURLParam("sort")
|
||||
return
|
||||
}
|
||||
if sort == "display_name" && (inGroupId == "" || notInGroupId != "" || inTeamId != "" || notInTeamId != "" || inChannelId != "" || notInChannelId != "" || withoutTeam != "") {
|
||||
c.SetInvalidURLParam("sort")
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
withoutTeamBool, _ = strconv.ParseBool(withoutTeam)
|
||||
@@ -869,10 +874,18 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
profiles, _, appErr = c.App.GetGroupMemberUsersPage(inGroupId, c.Params.Page, c.Params.PerPage, userGetOptions.ViewRestrictions)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
if sort == "display_name" {
|
||||
var user *model.User
|
||||
|
||||
user, appErr = c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
profiles, _, appErr = c.App.GetGroupMemberUsersSortedPage(inGroupId, c.Params.Page, c.Params.PerPage, userGetOptions.ViewRestrictions, c.App.GetNotificationNameFormat(user))
|
||||
} else {
|
||||
profiles, _, appErr = c.App.GetGroupMemberUsersPage(inGroupId, c.Params.Page, c.Params.PerPage, userGetOptions.ViewRestrictions)
|
||||
}
|
||||
} else if notInGroupId != "" {
|
||||
appErr = requireGroupAccess(c, notInGroupId)
|
||||
|
||||
@@ -2837,6 +2837,64 @@ func TestGetUsersInGroup(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestGetUsersInGroupByDisplayName(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
id := model.NewId()
|
||||
group, appErr := th.App.CreateGroup(&model.Group{
|
||||
DisplayName: "dn-foo_" + id,
|
||||
Name: model.NewString("name" + id),
|
||||
Source: model.GroupSourceLdap,
|
||||
Description: "description_" + id,
|
||||
RemoteId: model.NewString(model.NewId()),
|
||||
})
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
user1, err := th.App.CreateUser(th.Context, &model.User{Email: th.GenerateTestEmail(), Nickname: "aaa", Password: "test-password-1", Username: "zzz", Roles: model.SystemUserRoleId})
|
||||
assert.Nil(t, err)
|
||||
|
||||
user2, err := th.App.CreateUser(th.Context, &model.User{Email: th.GenerateTestEmail(), Password: "test-password-2", Username: "bbb", Roles: model.SystemUserRoleId})
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = th.App.UpsertGroupMember(group.Id, user1.Id)
|
||||
assert.Nil(t, err)
|
||||
_, err = th.App.UpsertGroupMember(group.Id, user2.Id)
|
||||
assert.Nil(t, err)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PrivacySettings.ShowFullName = true
|
||||
})
|
||||
|
||||
preference := model.Preference{
|
||||
UserId: th.SystemAdminUser.Id,
|
||||
Category: model.PreferenceCategoryDisplaySettings,
|
||||
Name: model.PreferenceNameNameFormat,
|
||||
Value: model.ShowUsername,
|
||||
}
|
||||
|
||||
err = th.App.UpdatePreferences(th.SystemAdminUser.Id, model.Preferences{preference})
|
||||
assert.Nil(t, err)
|
||||
|
||||
t.Run("Returns users in group in right order for username", func(t *testing.T) {
|
||||
users, _, err := th.SystemAdminClient.GetUsersInGroupByDisplayName(group.Id, 0, 1, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, users[0].Id, user2.Id)
|
||||
})
|
||||
|
||||
preference.Value = model.ShowNicknameFullName
|
||||
err = th.App.UpdatePreferences(th.SystemAdminUser.Id, model.Preferences{preference})
|
||||
assert.Nil(t, err)
|
||||
|
||||
t.Run("Returns users in group in right order for nickname", func(t *testing.T) {
|
||||
users, _, err := th.SystemAdminClient.GetUsersInGroupByDisplayName(group.Id, 0, 1, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, users[0].Id, user1.Id)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestUpdateUserMfa(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user