APIv4 DELETE /teams/{team_id} (#5937)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
43e795448f
Коммит
997eacd4b6
21
api4/team.go
21
api4/team.go
@@ -26,6 +26,7 @@ func InitTeam() {
|
|||||||
|
|
||||||
BaseRoutes.Team.Handle("", ApiSessionRequired(getTeam)).Methods("GET")
|
BaseRoutes.Team.Handle("", ApiSessionRequired(getTeam)).Methods("GET")
|
||||||
BaseRoutes.Team.Handle("", ApiSessionRequired(updateTeam)).Methods("PUT")
|
BaseRoutes.Team.Handle("", ApiSessionRequired(updateTeam)).Methods("PUT")
|
||||||
|
BaseRoutes.Team.Handle("", ApiSessionRequired(softDeleteTeam)).Methods("DELETE")
|
||||||
BaseRoutes.Team.Handle("/patch", ApiSessionRequired(patchTeam)).Methods("PUT")
|
BaseRoutes.Team.Handle("/patch", ApiSessionRequired(patchTeam)).Methods("PUT")
|
||||||
BaseRoutes.Team.Handle("/stats", ApiSessionRequired(getTeamStats)).Methods("GET")
|
BaseRoutes.Team.Handle("/stats", ApiSessionRequired(getTeamStats)).Methods("GET")
|
||||||
BaseRoutes.TeamMembers.Handle("", ApiSessionRequired(getTeamMembers)).Methods("GET")
|
BaseRoutes.TeamMembers.Handle("", ApiSessionRequired(getTeamMembers)).Methods("GET")
|
||||||
@@ -165,6 +166,26 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte(patchedTeam.ToJson()))
|
w.Write([]byte(patchedTeam.ToJson()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func softDeleteTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
c.RequireTeamId()
|
||||||
|
if c.Err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !app.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||||
|
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.SoftDeleteTeam(c.Params.TeamId)
|
||||||
|
if err != nil {
|
||||||
|
c.Err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnStatusOK(w)
|
||||||
|
}
|
||||||
|
|
||||||
func getTeamsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getTeamsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
c.RequireUserId()
|
c.RequireUserId()
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
|
|||||||
@@ -321,6 +321,48 @@ func TestPatchTeam(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSoftDeleteTeam(t *testing.T) {
|
||||||
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
|
defer TearDown()
|
||||||
|
Client := th.Client
|
||||||
|
|
||||||
|
team := &model.Team{DisplayName: "DisplayName", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN}
|
||||||
|
team, _ = Client.CreateTeam(team)
|
||||||
|
|
||||||
|
ok, resp := Client.SoftDeleteTeam(team.Id)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("should have returned true")
|
||||||
|
}
|
||||||
|
|
||||||
|
rteam, err := app.GetTeam(team.Id)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("should have returned archived team")
|
||||||
|
}
|
||||||
|
if rteam.DeleteAt == 0 {
|
||||||
|
t.Fatal("should have not set to zero")
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, resp = Client.SoftDeleteTeam("junk")
|
||||||
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
t.Fatal("should have returned false")
|
||||||
|
}
|
||||||
|
|
||||||
|
otherTeam := th.BasicTeam
|
||||||
|
_, resp = Client.SoftDeleteTeam(otherTeam.Id)
|
||||||
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
|
Client.Logout()
|
||||||
|
_, resp = Client.SoftDeleteTeam(otherTeam.Id)
|
||||||
|
CheckUnauthorizedStatus(t, resp)
|
||||||
|
|
||||||
|
_, resp = th.SystemAdminClient.SoftDeleteTeam(otherTeam.Id)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetAllTeams(t *testing.T) {
|
func TestGetAllTeams(t *testing.T) {
|
||||||
th := Setup().InitBasic().InitSystemAdmin()
|
th := Setup().InitBasic().InitSystemAdmin()
|
||||||
defer TearDown()
|
defer TearDown()
|
||||||
|
|||||||
14
app/team.go
14
app/team.go
@@ -682,6 +682,20 @@ func PermanentDeleteTeam(team *model.Team) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SoftDeleteTeam(teamId string) *model.AppError {
|
||||||
|
team, err := GetTeam(teamId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
team.DeleteAt = model.GetMillis()
|
||||||
|
if result := <-Srv.Store.Team().Update(team); result.Err != nil {
|
||||||
|
return result.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetTeamStats(teamId string) (*model.TeamStats, *model.AppError) {
|
func GetTeamStats(teamId string) (*model.TeamStats, *model.AppError) {
|
||||||
tchan := Srv.Store.Team().GetTotalMemberCount(teamId)
|
tchan := Srv.Store.Team().GetTotalMemberCount(teamId)
|
||||||
achan := Srv.Store.Team().GetActiveMemberCount(teamId)
|
achan := Srv.Store.Team().GetActiveMemberCount(teamId)
|
||||||
|
|||||||
@@ -914,6 +914,16 @@ func (c *Client4) PatchTeam(teamId string, patch *TeamPatch) (*Team, *Response)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SoftDeleteTeam deletes the team softly (archive only, not permanent delete).
|
||||||
|
func (c *Client4) SoftDeleteTeam(teamId string) (bool, *Response) {
|
||||||
|
if r, err := c.DoApiDelete(c.GetTeamRoute(teamId)); err != nil {
|
||||||
|
return false, &Response{StatusCode: r.StatusCode, Error: err}
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return CheckStatusOK(r), BuildResponse(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetTeamMembers returns team members based on the provided team id string.
|
// GetTeamMembers returns team members based on the provided team id string.
|
||||||
func (c *Client4) GetTeamMembers(teamId string, page int, perPage int, etag string) ([]*TeamMember, *Response) {
|
func (c *Client4) GetTeamMembers(teamId string, page int, perPage int, etag string) ([]*TeamMember, *Response) {
|
||||||
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
|
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user