summaryrefslogtreecommitdiff
path: root/internal/api/handlers_admin.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-10 09:59:21 +0300
committerPaul Buetow <paul@buetow.org>2026-05-10 09:59:21 +0300
commit1eefc6fc815e5fbd781e8818c61aa024821ce0d3 (patch)
treebfab82e9e7e2d48dd1a3d23dc9eae017ab867975 /internal/api/handlers_admin.go
parent0af2b2bc97275b5b6168cb91dabfe30d89bd5d07 (diff)
Move self-deletion guard from handler into AdminService (DeleteUser) to fix SoC violation
- Add ErrCannotDeleteSelf sentinel error in service layer. - Change DeleteUser signature to (ctx, callerID, id) across all layers. - Move self-deletion guard from handleDeleteUser handler into userAdminService.DeleteUser. - Update handleError to map ErrCannotDeleteSelf to 400 BadRequest. - Adjust all affected tests to use the new signature.
Diffstat (limited to 'internal/api/handlers_admin.go')
-rw-r--r--internal/api/handlers_admin.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/internal/api/handlers_admin.go b/internal/api/handlers_admin.go
index 6d10c67..d68b07c 100644
--- a/internal/api/handlers_admin.go
+++ b/internal/api/handlers_admin.go
@@ -83,11 +83,11 @@ func (s *Server) handleDeleteUser(w http.ResponseWriter, r *http.Request) {
return
}
adminUser, _ := r.Context().Value(userCtxKey).(*model.User)
- if adminUser != nil && adminUser.ID == id {
- badRequest(w, "cannot delete self")
- return
+ var callerID int64
+ if adminUser != nil {
+ callerID = adminUser.ID
}
- if err := s.adminSvc.DeleteUser(r.Context(), id); err != nil {
+ if err := s.adminSvc.DeleteUser(r.Context(), callerID, id); err != nil {
handleError(w, err)
return
}