PLT-2713 Added ability for admins to list users not in any team (#5844)
* PLT-2713 Added ability for admins to list users not in any team * Updated style of unit test
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
a4764a5c10
Коммит
6ac87d82e3
@@ -726,6 +726,54 @@ func (us SqlUserStore) GetProfilesNotInChannel(teamId string, channelId string,
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetProfilesWithoutTeam(offset int, limit int) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
var users []*model.User
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
Users
|
||||
WHERE
|
||||
(SELECT
|
||||
COUNT(0)
|
||||
FROM
|
||||
TeamMembers
|
||||
WHERE
|
||||
TeamMembers.UserId = Users.Id
|
||||
AND TeamMembers.DeleteAt = 0) = 0
|
||||
ORDER BY
|
||||
Username ASC
|
||||
LIMIT
|
||||
:Limit
|
||||
OFFSET
|
||||
:Offset`
|
||||
|
||||
if _, err := us.GetReplica().Select(&users, query, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
|
||||
result.Err = model.NewLocAppError("SqlUserStore.GetProfilesWithoutTeam", "store.sql_user.get_profiles.app_error", nil, err.Error())
|
||||
} else {
|
||||
|
||||
for _, u := range users {
|
||||
u.Password = ""
|
||||
u.AuthData = new(string)
|
||||
*u.AuthData = ""
|
||||
}
|
||||
|
||||
result.Data = users
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetProfilesByUsernames(usernames []string, teamId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
|
||||
@@ -373,6 +373,49 @@ func TestUserStoreGetProfilesInChannel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserStoreGetProfilesWithoutTeam(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
teamId := model.NewId()
|
||||
|
||||
// These usernames need to appear in the first 100 users for this to work
|
||||
|
||||
u1 := &model.User{}
|
||||
u1.Username = "a000000000" + model.NewId()
|
||||
u1.Email = model.NewId()
|
||||
Must(store.User().Save(u1))
|
||||
Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u1.Id}))
|
||||
defer store.User().PermanentDelete(u1.Id)
|
||||
|
||||
u2 := &model.User{}
|
||||
u2.Username = "a000000001" + model.NewId()
|
||||
u2.Email = model.NewId()
|
||||
Must(store.User().Save(u2))
|
||||
defer store.User().PermanentDelete(u2.Id)
|
||||
|
||||
if r1 := <-store.User().GetProfilesWithoutTeam(0, 100); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
users := r1.Data.([]*model.User)
|
||||
|
||||
found1 := false
|
||||
found2 := false
|
||||
for _, u := range users {
|
||||
if u.Id == u1.Id {
|
||||
found1 = true
|
||||
} else if u.Id == u2.Id {
|
||||
found2 = true
|
||||
}
|
||||
}
|
||||
|
||||
if found1 {
|
||||
t.Fatal("shouldn't have returned user on team")
|
||||
} else if !found2 {
|
||||
t.Fatal("should've returned user without any teams")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserStoreGetAllProfilesInChannel(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
|
||||
@@ -177,6 +177,7 @@ type UserStore interface {
|
||||
GetProfilesInChannel(channelId string, offset int, limit int) StoreChannel
|
||||
GetAllProfilesInChannel(channelId string, allowFromCache bool) StoreChannel
|
||||
GetProfilesNotInChannel(teamId string, channelId string, offset int, limit int) StoreChannel
|
||||
GetProfilesWithoutTeam(offset int, limit int) StoreChannel
|
||||
GetProfilesByUsernames(usernames []string, teamId string) StoreChannel
|
||||
GetAllProfiles(offset int, limit int) StoreChannel
|
||||
GetProfiles(teamId string, offset int, limit int) StoreChannel
|
||||
|
||||
Ссылка в новой задаче
Block a user