MCPcopy Index your code
hub / github.com/gotify/server / DeleteUserByID

Method DeleteUserByID

api/user.go:306–330  ·  view source on GitHub ↗

DeleteUserByID deletes the user by id swagger:operation DELETE /user/{id} user deleteUser Deletes a user. --- produces: [application/json] security: [clientTokenAuthorizationHeader: [], clientTokenHeader: [], clientTokenQuery: [], basicAuth: []] parameters: - name: id in: path descripti

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

304// schema:
305// $ref: "#/definitions/Error"
306func (a *UserAPI) DeleteUserByID(ctx *gin.Context) {
307 withID(ctx, "id", func(id uint) {
308 user, err := a.DB.GetUserByID(id)
309 if success := successOrAbort(ctx, 500, err); !success {
310 return
311 }
312 if user != nil {
313 adminCount, err := a.DB.CountUser(&model.User{Admin: true})
314 if success := successOrAbort(ctx, 500, err); !success {
315 return
316 }
317 if user.Admin && adminCount == 1 {
318 ctx.AbortWithError(400, errors.New("cannot delete last admin"))
319 return
320 }
321 if err := a.UserChangeNotifier.fireUserDeleted(id); err != nil {
322 ctx.AbortWithError(500, err)
323 return
324 }
325 successOrAbort(ctx, 500, a.DB.DeleteUserByID(id))
326 } else {
327 ctx.AbortWithError(404, errors.New("user does not exist"))
328 }
329 })
330}
331
332// ChangePassword changes the password from the current user
333// swagger:operation POST /current/user/password user updateCurrentUser

Callers

nothing calls this directly

Calls 6

withIDFunction · 0.85
successOrAbortFunction · 0.85
fireUserDeletedMethod · 0.80
GetUserByIDMethod · 0.65
CountUserMethod · 0.65
DeleteUserByIDMethod · 0.65

Tested by

no test coverage detected