π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Add delete user way
Smaug6739410ac141391b
diff --git a/backend/controllers/users.controller.go b/backend/controllers/users.controller.goindex b3738aad..18f4eb73 100644--- a/backend/controllers/users.controller.go+++ b/backend/controllers/users.controller.go@@ -20,6 +20,7 @@ type UserController interface {CreateUser(c *gin.Context) (int, any)UpdateUser(c *gin.Context) (int, any)UpdatePassword(c *gin.Context) (int, any)+ DeleteUser(c *gin.Context) (int, any)}type UserControllerImpl struct {Controller@@ -155,7 +156,7 @@ func (ctr *UserControllerImpl) CreateUser(c *gin.Context) (int, any) {func (ctr *UserControllerImpl) UpdateUser(c *gin.Context) (int, any) {id, err := utils.SelfOrPermission(c, utils.ADMINISTRATOR)if err != nil {- return http.StatusBadRequest, err+ return http.StatusUnauthorized, err}var user models.Userif err := c.ShouldBind(&user); err != nil {@@ -199,7 +200,7 @@ func (ctr *UserControllerImpl) UpdateUser(c *gin.Context) (int, any) {func (ctr *UserControllerImpl) UpdatePassword(c *gin.Context) (int, any) {id, err := utils.SelfOrPermission(c, utils.ADMINISTRATOR)if err != nil {- return http.StatusBadRequest, err+ return http.StatusUnauthorized, err}var payload struct {Password string `form:"password" json:"password"`@@ -221,3 +222,25 @@ func (ctr *UserControllerImpl) UpdatePassword(c *gin.Context) (int, any) {}return http.StatusOK, "Password updated successfully"}++// Delete User+// @Summary Delete user+// @Method DELETE+// @Router /users/{id} [delete]+// @Security Authenfification: Auth, {self, admin}+// @Param id path int true "User ID"+// @Success 200 {object} Success(string)+// @Failure 400 {object} Error+// @Failure 401 {object} Error+func (ctr *UserControllerImpl) DeleteUser(c *gin.Context) (int, any) {+ id, err := utils.SelfOrPermission(c, utils.ADMINISTRATOR)+ if err != nil {+ return http.StatusUnauthorized, err+ }++ err = ctr.user_service.DeleteUser(id)+ if err != nil {+ return http.StatusInternalServerError, err+ }+ return http.StatusOK, "User deleted successfully"+}diff --git a/backend/router/routes/users.go b/backend/router/routes/users.goindex 572afa9c..57b1da90 100644--- a/backend/router/routes/users.go+++ b/backend/router/routes/users.go@@ -21,4 +21,5 @@ func Users(app *app.App, router *gin.RouterGroup) {usr.POST("/", utils.WP(usrCtrl.CreateUser))usr.PATCH("/:id", middlewares.Auth(), utils.WP(usrCtrl.UpdateUser))usr.PATCH("/:id/password", middlewares.Auth(), utils.WP(usrCtrl.UpdatePassword))+ usr.DELETE("/:id", middlewares.Auth(), utils.WP(usrCtrl.DeleteUser))}