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.
Этот коммит содержится в:
Zeger-Jan van de Weg
2017-06-15 14:13:18 +02:00
коммит произвёл Joram Wilander
родитель 98ac903fce
Коммит 0c04c5334f
5 изменённых файлов: 67 добавлений и 3 удалений

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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

Просмотреть файл

@@ -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()