From 0c04c5334fc89cf62a4bd3c1ce20469523a24026 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Thu, 15 Jun 2017 14:13:18 +0200 Subject: Add APIv4 endpoint to permanently delete teams (#6604) Tests are added, however, it only tests the property if its soft deleted. In the background it will be hard deleted, but that is untestable through a integration test. --- api4/params.go | 5 +++++ api4/team.go | 12 +++++++++--- api4/team_test.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) (limited to 'api4') diff --git a/api4/params.go b/api4/params.go index aa865fd2a..d952eb65a 100644 --- a/api4/params.go +++ b/api4/params.go @@ -39,6 +39,7 @@ type ApiParams struct { JobType string Page int PerPage int + Permanent bool } func ApiParamsFromRequest(r *http.Request) *ApiParams { @@ -132,6 +133,10 @@ func ApiParamsFromRequest(r *http.Request) *ApiParams { params.Page = val } + if val, err := strconv.ParseBool(r.URL.Query().Get("permanent")); err != nil { + params.Permanent = val + } + if val, err := strconv.Atoi(r.URL.Query().Get("per_page")); err != nil || val < 0 { params.PerPage = PER_PAGE_DEFAULT } else if val > PER_PAGE_MAXIMUM { diff --git a/api4/team.go b/api4/team.go index b8ba47054..57a715937 100644 --- a/api4/team.go +++ b/api4/team.go @@ -30,7 +30,7 @@ func InitTeam() { BaseRoutes.Team.Handle("", ApiSessionRequired(getTeam)).Methods("GET") BaseRoutes.Team.Handle("", ApiSessionRequired(updateTeam)).Methods("PUT") - BaseRoutes.Team.Handle("", ApiSessionRequired(softDeleteTeam)).Methods("DELETE") + BaseRoutes.Team.Handle("", ApiSessionRequired(deleteTeam)).Methods("DELETE") BaseRoutes.Team.Handle("/patch", ApiSessionRequired(patchTeam)).Methods("PUT") BaseRoutes.Team.Handle("/stats", ApiSessionRequired(getTeamStats)).Methods("GET") BaseRoutes.TeamMembers.Handle("", ApiSessionRequired(getTeamMembers)).Methods("GET") @@ -172,7 +172,7 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(patchedTeam.ToJson())) } -func softDeleteTeam(c *Context, w http.ResponseWriter, r *http.Request) { +func deleteTeam(c *Context, w http.ResponseWriter, r *http.Request) { c.RequireTeamId() if c.Err != nil { return @@ -183,7 +183,13 @@ func softDeleteTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - err := app.SoftDeleteTeam(c.Params.TeamId) + var err *model.AppError + if c.Params.Permanent { + err = app.PermanentDeleteTeamId(c.Params.TeamId) + } else { + err = app.SoftDeleteTeam(c.Params.TeamId) + } + if err != nil { c.Err = err return diff --git a/api4/team_test.go b/api4/team_test.go index 61d7dc331..2aee4ba5f 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -363,6 +363,39 @@ func TestSoftDeleteTeam(t *testing.T) { CheckNoError(t, resp) } +func TestPermanentDeleteTeam(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.PermanentDeleteTeam(team.Id) + CheckNoError(t, resp) + + if !ok { + t.Fatal("should have returned true") + } + + // The team is deleted in the background, its only soft deleted at this + // time + 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.PermanentDeleteTeam("junk") + CheckBadRequestStatus(t, resp) + + if ok { + t.Fatal("should have returned false") + } +} + func TestGetAllTeams(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() defer TearDown() -- cgit v1.2.3-1-g7c22