MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / updateProjectUser

Function updateProjectUser

cmd/cql-proxy/api/project.go:355–427  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

353}
354
355func updateProjectUser(c *gin.Context) {
356 r := struct {
357 DB proto.DatabaseID `json:"db" json:"project" form:"db" form:"project" uri:"db" uri:"project" binding:"required,len=64"`
358 ID int64 `json:"id" form:"id" uri:"id" binding:"required,gt=0"`
359 Name string `json:"name" form:"name"`
360 Email string `json:"email" form:"email" binding:"omitempty,email"`
361 Provider string `json:"provider" form:"provider"`
362 State string `json:"state" form:"state"`
363 }{}
364
365 _ = c.ShouldBindUri(&r)
366
367 if err := c.ShouldBind(&r); err != nil {
368 abortWithError(c, http.StatusBadRequest, err)
369 return
370 }
371
372 _, projectDB, err := getProjectDB(c, r.DB)
373 if err != nil {
374 _ = c.Error(err)
375 abortWithError(c, http.StatusForbidden, ErrLoadProjectDatabaseFailed)
376 return
377 }
378
379 u, err := model.GetProjectUser(projectDB, r.ID)
380 if err != nil {
381 _ = c.Error(err)
382 abortWithError(c, http.StatusInternalServerError, ErrGetProjectUserFailed)
383 return
384 }
385
386 if r.Name != "" {
387 u.Name = r.Name
388 }
389 if r.Email != "" {
390 u.Email = r.Email
391 }
392 if r.Provider != "" {
393 u.Provider = r.Provider
394 }
395 if r.State != "" {
396 u.State, err = model.ParseProjectUserState(r.State)
397 if err != nil {
398 _ = c.Error(err)
399 abortWithError(c, http.StatusBadRequest, ErrGetProjectUserStateFailed)
400 return
401 }
402 }
403
404 err = model.UpdateProjectUser(projectDB, u)
405 if err != nil {
406 _ = c.Error(err)
407 if strings.Contains(err.Error(), "constraint failed") {
408 err = ErrUpdateUserConflictWithExisting
409 } else {
410 err = ErrUpdateUserFailed
411 }
412 abortWithError(c, http.StatusInternalServerError, err)

Callers

nothing calls this directly

Calls 10

GetProjectUserFunction · 0.92
ParseProjectUserStateFunction · 0.92
UpdateProjectUserFunction · 0.92
abortWithErrorFunction · 0.85
getProjectDBFunction · 0.85
responseWithDataFunction · 0.85
formatUnixTimeFunction · 0.85
ErrorMethod · 0.80
ContainsMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected