// title: remove team // path: /teams/{name} // method: DELETE // responses: // 200: Team removed // 401: Unauthorized // 403: Forbidden // 404: Not found func removeTeam(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) { r.ParseForm() name := r.URL.Query().Get(":name") allowed := permission.Check(t, permission.PermTeamDelete, permission.Context(permission.CtxTeam, name), ) if !allowed { return &errors.HTTP{Code: http.StatusNotFound, Message: fmt.Sprintf(`Team "%s" not found.`, name)} } evt, err := event.New(&event.Opts{ Target: teamTarget(name), Kind: permission.PermTeamDelete, Owner: t, CustomData: event.FormToCustomData(r.Form), Allowed: event.Allowed(permission.PermTeamReadEvents, permission.Context(permission.CtxTeam, name)), }) if err != nil { return err } defer func() { evt.Done(err) }() err = auth.RemoveTeam(name) if err != nil { if _, ok := err.(*auth.ErrTeamStillUsed); ok { msg := fmt.Sprintf("This team cannot be removed because there are still references to it:\n%s", err) return &errors.HTTP{Code: http.StatusForbidden, Message: msg} } if err == auth.ErrTeamNotFound { return &errors.HTTP{Code: http.StatusNotFound, Message: fmt.Sprintf(`Team "%s" not found.`, name)} } return err } return nil }
func removeTeam(w http.ResponseWriter, r *http.Request, t auth.Token) error { name := r.URL.Query().Get(":name") allowed := permission.Check(t, permission.PermTeamDelete, permission.Context(permission.CtxTeam, name), ) if !allowed { return &errors.HTTP{Code: http.StatusNotFound, Message: fmt.Sprintf(`Team "%s" not found.`, name)} } rec.Log(t.GetUserName(), "remove-team", name) err := auth.RemoveTeam(name) if err != nil { if _, ok := err.(*auth.ErrTeamStillUsed); ok { msg := fmt.Sprintf("This team cannot be removed because there are still references to it:\n%s", err) return &errors.HTTP{Code: http.StatusForbidden, Message: msg} } if err == auth.ErrTeamNotFound { return &errors.HTTP{Code: http.StatusNotFound, Message: fmt.Sprintf(`Team "%s" not found.`, name)} } return err } return nil }
func removeTeam(w http.ResponseWriter, r *http.Request, t auth.Token) error { name := r.URL.Query().Get(":name") rec.Log(t.GetUserName(), "remove-team", name) user, err := t.User() if err != nil { return err } if !user.IsAdmin() && !auth.CheckUserAccess([]string{name}, user) { return &errors.HTTP{Code: http.StatusNotFound, Message: fmt.Sprintf(`Team "%s" not found.`, name)} } err = auth.RemoveTeam(name) if err != nil { if _, ok := err.(*auth.ErrTeamStillUsed); ok { msg := fmt.Sprintf("This team cannot be removed because there are still references to it:\n%s", err) return &errors.HTTP{Code: http.StatusForbidden, Message: msg} } if err == auth.ErrTeamNotFound { return &errors.HTTP{Code: http.StatusNotFound, Message: fmt.Sprintf(`Team "%s" not found.`, name)} } return err } return nil }