Пример #1
0
// Test the ability to delete a Team.
func TestDeleteTeam(t *testing.T) {
	Setup()
	defer Teardown()

	// get the team we plan to update
	if err := database.DeleteTeam(1); err != nil {
		t.Error(err)
	}

	// now try to get the team from the database
	_, err := database.GetTeam(1)
	if err == nil {
		t.Fail()
	}
}
Пример #2
0
// Delete a specific Team.
func TeamDelete(w http.ResponseWriter, r *http.Request, u *User) error {
	// get the team from the database
	teamParam := r.FormValue(":team")
	team, err := database.GetTeamSlug(teamParam)
	if err != nil {
		return RenderNotFound(w)
	}
	if member, _ := database.IsMemberAdmin(u.ID, team.ID); !member {
		return fmt.Errorf("Forbidden")
	}
	// the user must confirm their password before deleting
	password := r.FormValue("password")
	if err := u.ComparePassword(password); err != nil {
		return RenderError(w, err, http.StatusBadRequest)
	}

	database.DeleteTeam(team.ID)
	http.Redirect(w, r, "/account/user/teams", http.StatusSeeOther)
	return nil
}