summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <ZJvandeWeg@users.noreply.github.com>2017-06-15 14:13:18 +0200
committerJoram Wilander <jwawilander@gmail.com>2017-06-15 08:13:18 -0400
commit0c04c5334fc89cf62a4bd3c1ce20469523a24026 (patch)
tree30b56cf82205ef5d739059ec1b3a24865e8d0fb3
parent98ac903fce24418538edbec77a218bcac9e20cd2 (diff)
downloadchat-0c04c5334fc89cf62a4bd3c1ce20469523a24026.tar.gz
chat-0c04c5334fc89cf62a4bd3c1ce20469523a24026.tar.bz2
chat-0c04c5334fc89cf62a4bd3c1ce20469523a24026.zip
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.
-rw-r--r--api4/params.go5
-rw-r--r--api4/team.go12
-rw-r--r--api4/team_test.go33
-rw-r--r--app/team.go9
-rw-r--r--model/client4.go11
5 files changed, 67 insertions, 3 deletions
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()
diff --git a/app/team.go b/app/team.go
index acc3966b9..317315f06 100644
--- a/app/team.go
+++ b/app/team.go
@@ -690,6 +690,15 @@ func GetTeamsUnreadForUser(excludeTeamId string, userId string) ([]*model.TeamUn
}
}
+func PermanentDeleteTeamId(teamId string) *model.AppError {
+ team, err := GetTeam(teamId)
+ if err != nil {
+ return err
+ }
+
+ return PermanentDeleteTeam(team)
+}
+
func PermanentDeleteTeam(team *model.Team) *model.AppError {
team.DeleteAt = model.GetMillis()
if result := <-Srv.Store.Team().Update(team); result.Err != nil {
diff --git a/model/client4.go b/model/client4.go
index fce4c678f..c692a8415 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -1046,6 +1046,17 @@ func (c *Client4) SoftDeleteTeam(teamId string) (bool, *Response) {
}
}
+// PermanentDeleteTeam deletes the team, should only be used when needed for
+// compliance and the like
+func (c *Client4) PermanentDeleteTeam(teamId string) (bool, *Response) {
+ if r, err := c.DoApiDelete(c.GetTeamRoute(teamId) + "?permanent=true"); 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.
func (c *Client4) GetTeamMembers(teamId string, page int, perPage int, etag string) ([]*TeamMember, *Response) {
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)