MCPcopy Create free account
hub / github.com/actiontech/dtle / UpdateUserV2

Function UpdateUserV2

api/handler/v2/user.go:169–206  ·  view source on GitHub ↗

@Id UpdateUserV2 @Description update user info. @Tags user @Accept application/json @Security ApiKeyAuth @Param user body models.UpdateUserReqV2 true "user info" @Success 200 {object} models.UpdateUserRespV2 @Router /v2/user/update [post]

(c echo.Context)

Source from the content-addressed store, hash-verified

167// @Success 200 {object} models.UpdateUserRespV2
168// @Router /v2/user/update [post]
169func UpdateUserV2(c echo.Context) error {
170 logger := handler.NewLogger().Named("UpdateUserV2")
171 reqParam := new(models.UpdateUserReqV2)
172 if err := handler.BindAndValidate(logger, c, reqParam); err != nil {
173 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(err))
174 }
175
176 storeManager, err := common.NewStoreManager([]string{handler.ConsulAddr}, logger)
177 if err != nil {
178 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(fmt.Errorf("get consul client failed: %v", err)))
179 }
180
181 if hasAccess, err := checkUserAccess(logger, c, fmt.Sprintf("%s:%s", reqParam.Tenant, reqParam.Username)); err != nil || !hasAccess {
182 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(fmt.Errorf("current user has no access to operate group %v ; err : %v", reqParam.Tenant, err)))
183 }
184
185 user, exist, err := storeManager.GetUser(reqParam.Tenant, reqParam.Username)
186 if err != nil {
187 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(err))
188 }
189 if !exist {
190 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(fmt.Errorf("user %v:%v does not exist", reqParam.Tenant, reqParam.Username)))
191 }
192
193 user.Role = reqParam.Role
194 user.Remark = reqParam.Remark
195
196 if !VerifyPassword(user.Password) {
197 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(fmt.Errorf("password does not meet the rules")))
198 }
199
200 if err := storeManager.SaveUser(user); nil != err {
201 return c.JSON(http.StatusInternalServerError,
202 models.BuildBaseResp(fmt.Errorf("delete metadata of user[userName=%v,Tenant=%v] from consul failed: %v", reqParam.Username, reqParam.Tenant, err)))
203 }
204
205 return c.JSON(http.StatusOK, models.UpdateUserRespV2{BaseResp: models.BuildBaseResp(nil)})
206}
207
208// @Id ResetPasswordV2
209// @Description reset user password.

Callers

nothing calls this directly

Calls 8

GetUserMethod · 0.95
SaveUserMethod · 0.95
NewLoggerFunction · 0.92
BindAndValidateFunction · 0.92
BuildBaseRespFunction · 0.92
NewStoreManagerFunction · 0.92
checkUserAccessFunction · 0.85
VerifyPasswordFunction · 0.85

Tested by

no test coverage detected