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)
| 304 | // schema: |
| 305 | // $ref: "#/definitions/Error" |
| 306 | func (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 |
nothing calls this directly
no test coverage detected