Skip to content

Commit

Permalink
Prevent any API requests on accounts that are in deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Oct 29, 2024
1 parent 06251bb commit 0290c5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion internal/api/keppel/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ func (a *API) handlePutAccount(w http.ResponseWriter, r *http.Request) {
http.Error(w, `malformed attribute "account.name" in request body is not allowed here`, http.StatusUnprocessableEntity)
return
}
// ... transfer it here into the struct, to make the below code simpler
// ... or state ...
if req.Account.State != "" {
http.Error(w, `malformed attribute "account.state" in request body is not allowed here`, http.StatusUnprocessableEntity)
return
}
// ... and transfer the name here into the struct, to make the below code simpler
req.Account.Name = models.AccountName(mux.Vars(r)["account"])

// check permission to create account
Expand Down
4 changes: 2 additions & 2 deletions internal/api/keppel/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1951,9 +1951,9 @@ func TestDeleteAccount(t *testing.T) {
assert.HTTPRequest{
Method: "DELETE",
Path: "/keppel/v1/accounts/test1",
Header: map[string]string{"X-Test-Perms": "view:tenant1,change:tenant1"},
ExpectStatus: http.StatusConflict,
ExpectBody: assert.StringData("account is deleting\n"),
"error": "account is already set to be deleted",
},
}.Check(t, h)

// that didn't touch the DB
Expand Down
4 changes: 4 additions & 0 deletions internal/api/keppel/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ func (a *API) findAccountFromRequest(w http.ResponseWriter, r *http.Request, _ *
http.Error(w, "account not found", http.StatusNotFound)
return nil
}
if account.IsDeleting {
http.Error(w, "account is deleting", http.StatusConflict)
return nil
}
return account
}

Expand Down

0 comments on commit 0290c5a

Please sign in to comment.