коммит произвёл
GitHub
родитель
f42d3c83f3
Коммит
1c498996a4
12
api4/team.go
12
api4/team.go
@@ -853,26 +853,30 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
var teamsWithCount *model.TeamsWithCount
|
var teamsWithCount *model.TeamsWithCount
|
||||||
|
|
||||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PRIVATE_TEAMS) && c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
listPrivate := c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PRIVATE_TEAMS)
|
||||||
|
listPublic := c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PUBLIC_TEAMS)
|
||||||
|
if listPrivate && listPublic {
|
||||||
if c.Params.IncludeTotalCount {
|
if c.Params.IncludeTotalCount {
|
||||||
teamsWithCount, err = c.App.GetAllTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
teamsWithCount, err = c.App.GetAllTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||||
} else {
|
} else {
|
||||||
teams, err = c.App.GetAllTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
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) {
|
} else if listPrivate {
|
||||||
if c.Params.IncludeTotalCount {
|
if c.Params.IncludeTotalCount {
|
||||||
teamsWithCount, err = c.App.GetAllPrivateTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
teamsWithCount, err = c.App.GetAllPrivateTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||||
} else {
|
} else {
|
||||||
teams, err = c.App.GetAllPrivateTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
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) {
|
} else if listPublic {
|
||||||
if c.Params.IncludeTotalCount {
|
if c.Params.IncludeTotalCount {
|
||||||
teamsWithCount, err = c.App.GetAllPublicTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
teamsWithCount, err = c.App.GetAllPublicTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||||
} else {
|
} else {
|
||||||
teams, err = c.App.GetAllPublicTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
teams, err = c.App.GetAllPublicTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// The user doesn't have permissions to list private as well as public teams.
|
||||||
|
err = model.NewAppError("getAllTeams", "api.team.get_all_teams.insufficient_permissions", nil, "", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -572,13 +572,16 @@ func TestGetAllTeams(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
Name string
|
Name string
|
||||||
Page int
|
Page int
|
||||||
PerPage int
|
PerPage int
|
||||||
Permissions []string
|
Permissions []string
|
||||||
ExpectedTeams []string
|
ExpectedTeams []string
|
||||||
WithCount bool
|
WithCount bool
|
||||||
ExpectedCount int64
|
ExpectedCount int64
|
||||||
|
ExpectedError bool
|
||||||
|
ErrorId string
|
||||||
|
ExpectedStatusCode int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Name: "Get 1 team per page",
|
Name: "Get 1 team per page",
|
||||||
@@ -623,11 +626,23 @@ func TestGetAllTeams(t *testing.T) {
|
|||||||
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id, team4.Id},
|
ExpectedTeams: []string{th.BasicTeam.Id, team1.Id, team2.Id, team3.Id, team4.Id},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Get no teams because permissions",
|
Name: "Get no teams because permissions",
|
||||||
Page: 0,
|
Page: 0,
|
||||||
PerPage: 10,
|
PerPage: 10,
|
||||||
Permissions: []string{},
|
Permissions: []string{},
|
||||||
ExpectedTeams: []string{},
|
ExpectedError: true,
|
||||||
|
ExpectedStatusCode: http.StatusForbidden,
|
||||||
|
ErrorId: "api.team.get_all_teams.insufficient_permissions",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Get no teams because permissions with count",
|
||||||
|
Page: 0,
|
||||||
|
PerPage: 10,
|
||||||
|
Permissions: []string{},
|
||||||
|
WithCount: true,
|
||||||
|
ExpectedError: true,
|
||||||
|
ExpectedStatusCode: http.StatusForbidden,
|
||||||
|
ErrorId: "api.team.get_all_teams.insufficient_permissions",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Get all teams with count",
|
Name: "Get all teams with count",
|
||||||
@@ -679,6 +694,11 @@ func TestGetAllTeams(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
teams, resp = Client.GetAllTeams("", tc.Page, tc.PerPage)
|
teams, resp = Client.GetAllTeams("", tc.Page, tc.PerPage)
|
||||||
}
|
}
|
||||||
|
if tc.ExpectedError {
|
||||||
|
CheckErrorMessage(t, resp, tc.ErrorId)
|
||||||
|
checkHTTPStatus(t, resp, tc.ExpectedStatusCode, true)
|
||||||
|
return
|
||||||
|
}
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
require.Equal(t, len(tc.ExpectedTeams), len(teams))
|
require.Equal(t, len(tc.ExpectedTeams), len(teams))
|
||||||
for idx, team := range teams {
|
for idx, team := range teams {
|
||||||
|
|||||||
@@ -1966,6 +1966,10 @@
|
|||||||
"id": "api.team.demote_user_to_guest.license.error",
|
"id": "api.team.demote_user_to_guest.license.error",
|
||||||
"translation": "Your license does not support guest accounts"
|
"translation": "Your license does not support guest accounts"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.team.get_all_teams.insufficient_permissions",
|
||||||
|
"translation": "You don't have the appropriate permissions to list all teams"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.team.get_invite_info.not_open_team",
|
"id": "api.team.get_invite_info.not_open_team",
|
||||||
"translation": "Invite is invalid because this is not an open team."
|
"translation": "Invite is invalid because this is not an open team."
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user