[MM-18119] Add methods for getting teams and count when query… (#12020)
* Add methods to handle include_total_count api parameter when permissions for authenticated user is not sysadmin * Add translations for app errors * Add Mocks * Add tests for new methods * When running at the TeamStore testing level, the number of returned teams is different than running tests individually. Fix for now and submit help wanted do proper teardown after each test * correct value when running test at the top level * Add helper function to delete previous teams in db * Instead of checking against numbers of teams returned, check against the actual teams returned. When creating test teams, use unique DisplaName values so the return array will be sorted consistantly. When testing private and public team counts, add teams that should not be counted. Also create odd number of public/private teams for better error protections. Don't want 1 of each type
Этот коммит содержится в:
12
api4/team.go
12
api4/team.go
@@ -740,9 +740,17 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teams, err = c.App.GetAllTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
}
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PRIVATE_TEAMS) {
|
||||
teams, err = c.App.GetAllPrivateTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
if c.Params.IncludeTotalCount {
|
||||
teamsWithCount, err = c.App.GetAllPrivateTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
} else {
|
||||
teams, err = c.App.GetAllPrivateTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
}
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
teams, err = c.App.GetAllPublicTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
if c.Params.IncludeTotalCount {
|
||||
teamsWithCount, err = c.App.GetAllPublicTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
} else {
|
||||
teams, err = c.App.GetAllPublicTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -621,6 +621,10 @@ func TestGetAllTeams(t *testing.T) {
|
||||
team3, resp = Client.CreateTeam(team3)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
team4 := &model.Team{DisplayName: "Name4", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
|
||||
team4, resp = Client.CreateTeam(team4)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
testCases := []struct {
|
||||
Name string
|
||||
Page int
|
||||
@@ -663,14 +667,14 @@ func TestGetAllTeams(t *testing.T) {
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PRIVATE_TEAMS.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team3.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team3.Id, team4.Id},
|
||||
},
|
||||
{
|
||||
Name: "Get all teams",
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PUBLIC_TEAMS.Id, model.PERMISSION_LIST_PRIVATE_TEAMS.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id, team4.Id},
|
||||
},
|
||||
{
|
||||
Name: "Get no teams because permissions",
|
||||
@@ -684,9 +688,27 @@ func TestGetAllTeams(t *testing.T) {
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PUBLIC_TEAMS.Id, model.PERMISSION_LIST_PRIVATE_TEAMS.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id, team4.Id},
|
||||
WithCount: true,
|
||||
ExpectedCount: 4,
|
||||
ExpectedCount: 5,
|
||||
},
|
||||
{
|
||||
Name: "Get all public teams with count",
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PUBLIC_TEAMS.Id},
|
||||
ExpectedTeams: []string{team1.Id, team2.Id},
|
||||
WithCount: true,
|
||||
ExpectedCount: 2,
|
||||
},
|
||||
{
|
||||
Name: "Get all private teams with count",
|
||||
Page: 0,
|
||||
PerPage: 10,
|
||||
Permissions: []string{model.PERMISSION_LIST_PRIVATE_TEAMS.Id},
|
||||
ExpectedTeams: []string{th.BasicTeam.Id, team3.Id, team4.Id},
|
||||
WithCount: true,
|
||||
ExpectedCount: 3,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2310,7 +2332,9 @@ func TestInviteGuestsToTeam(t *testing.T) {
|
||||
defer func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableEmailInvitations = &enableEmailInvitations })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.RestrictCreationToDomains = restrictCreationToDomains })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GuestAccountsSettings.RestrictCreationToDomains = guestRestrictCreationToDomains })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.GuestAccountsSettings.RestrictCreationToDomains = guestRestrictCreationToDomains
|
||||
})
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GuestAccountsSettings.Enable = &enableGuestAccounts })
|
||||
}()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user