MCPcopy Create free account
hub / github.com/gogs/gogs / EditUser

Function EditUser

internal/route/api/v1/admin/user.go:70–120  ·  view source on GitHub ↗
(c *context.APIContext, form api.EditUserOption)

Source from the content-addressed store, hash-verified

68}
69
70func EditUser(c *context.APIContext, form api.EditUserOption) {
71 u := user.GetUserByParams(c)
72 if c.Written() {
73 return
74 }
75
76 parseLoginSource(c, form.SourceID)
77 if c.Written() {
78 return
79 }
80
81 opts := database.UpdateUserOptions{
82 LoginSource: &form.SourceID,
83 LoginName: &form.LoginName,
84 FullName: &form.FullName,
85 Website: &form.Website,
86 Location: &form.Location,
87 MaxRepoCreation: form.MaxRepoCreation,
88 IsActivated: form.Active,
89 IsAdmin: form.Admin,
90 AllowGitHook: form.AllowGitHook,
91 AllowImportLocal: form.AllowImportLocal,
92 ProhibitLogin: nil, // TODO: Add this option to API
93 }
94
95 if form.Password != "" {
96 opts.Password = &form.Password
97 }
98
99 if u.Email != form.Email {
100 opts.Email = &form.Email
101 }
102
103 err := database.Handle.Users().Update(c.Req.Context(), u.ID, opts)
104 if err != nil {
105 if database.IsErrEmailAlreadyUsed(err) {
106 c.ErrorStatus(http.StatusUnprocessableEntity, err)
107 } else {
108 c.Error(err, "update user")
109 }
110 return
111 }
112 log.Trace("Account updated by admin %q: %s", c.User.Name, u.Name)
113
114 u, err = database.Handle.Users().GetByID(c.Req.Context(), u.ID)
115 if err != nil {
116 c.Error(err, "get user")
117 return
118 }
119 c.JSONSuccess(u.APIFormat())
120}
121
122func DeleteUser(c *context.APIContext) {
123 u := user.GetUserByParams(c)

Callers

nothing calls this directly

Calls 10

GetUserByParamsFunction · 0.92
IsErrEmailAlreadyUsedFunction · 0.92
parseLoginSourceFunction · 0.85
UsersMethod · 0.80
ErrorStatusMethod · 0.80
JSONSuccessMethod · 0.80
UpdateMethod · 0.65
GetByIDMethod · 0.65
ErrorMethod · 0.45
APIFormatMethod · 0.45

Tested by

no test coverage detected