mirror of
https://github.com/ferdzo/fs.git
synced 2026-04-05 08:26:28 +00:00
add admin user delete endpoint and service support
This commit is contained in:
@@ -59,6 +59,7 @@ func (h *Handler) registerAdminRoutes() {
|
||||
r.Post("/users", h.handleAdminCreateUser)
|
||||
r.Get("/users", h.handleAdminListUsers)
|
||||
r.Get("/users/{accessKeyId}", h.handleAdminGetUser)
|
||||
r.Delete("/users/{accessKeyId}", h.handleAdminDeleteUser)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -155,6 +156,18 @@ func (h *Handler) handleAdminGetUser(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func (h *Handler) handleAdminDeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
if !h.requireBootstrapAdmin(w, r) {
|
||||
return
|
||||
}
|
||||
accessKeyID := chi.URLParam(r, "accessKeyId")
|
||||
if err := h.authSvc.DeleteUser(accessKeyID); err != nil {
|
||||
writeMappedAdminError(w, r, err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (h *Handler) requireBootstrapAdmin(w http.ResponseWriter, r *http.Request) bool {
|
||||
authCtx, ok := auth.GetRequestContext(r.Context())
|
||||
if !ok || !authCtx.Authenticated {
|
||||
|
||||
Reference in New Issue
Block a user