@@ -73,6 +73,7 @@ func CreateUser(ctx *context.APIContext) {
7373 // "$ref": "#/responses/forbidden"
7474 // "422":
7575 // "$ref": "#/responses/validationError"
76+
7677 form := web .GetForm (ctx ).(* api.CreateUserOption )
7778
7879 u := & user_model.User {
@@ -163,13 +164,10 @@ func EditUser(ctx *context.APIContext) {
163164 // "$ref": "#/responses/forbidden"
164165 // "422":
165166 // "$ref": "#/responses/validationError"
167+
166168 form := web .GetForm (ctx ).(* api.EditUserOption )
167- u := user .GetUserByParams (ctx )
168- if ctx .Written () {
169- return
170- }
171169
172- parseAuthSource (ctx , u , form .SourceID , form .LoginName )
170+ parseAuthSource (ctx , ctx . ContextUser , form .SourceID , form .LoginName )
173171 if ctx .Written () {
174172 return
175173 }
@@ -193,24 +191,24 @@ func EditUser(ctx *context.APIContext) {
193191 ctx .Error (http .StatusBadRequest , "PasswordPwned" , errors .New ("PasswordPwned" ))
194192 return
195193 }
196- if u .Salt , err = user_model .GetUserSalt (); err != nil {
194+ if ctx . ContextUser .Salt , err = user_model .GetUserSalt (); err != nil {
197195 ctx .Error (http .StatusInternalServerError , "UpdateUser" , err )
198196 return
199197 }
200- if err = u .SetPassword (form .Password ); err != nil {
198+ if err = ctx . ContextUser .SetPassword (form .Password ); err != nil {
201199 ctx .InternalServerError (err )
202200 return
203201 }
204202 }
205203
206204 if form .MustChangePassword != nil {
207- u .MustChangePassword = * form .MustChangePassword
205+ ctx . ContextUser .MustChangePassword = * form .MustChangePassword
208206 }
209207
210- u .LoginName = form .LoginName
208+ ctx . ContextUser .LoginName = form .LoginName
211209
212210 if form .FullName != nil {
213- u .FullName = * form .FullName
211+ ctx . ContextUser .FullName = * form .FullName
214212 }
215213 var emailChanged bool
216214 if form .Email != nil {
@@ -225,47 +223,47 @@ func EditUser(ctx *context.APIContext) {
225223 return
226224 }
227225
228- emailChanged = ! strings .EqualFold (u .Email , email )
229- u .Email = email
226+ emailChanged = ! strings .EqualFold (ctx . ContextUser .Email , email )
227+ ctx . ContextUser .Email = email
230228 }
231229 if form .Website != nil {
232- u .Website = * form .Website
230+ ctx . ContextUser .Website = * form .Website
233231 }
234232 if form .Location != nil {
235- u .Location = * form .Location
233+ ctx . ContextUser .Location = * form .Location
236234 }
237235 if form .Description != nil {
238- u .Description = * form .Description
236+ ctx . ContextUser .Description = * form .Description
239237 }
240238 if form .Active != nil {
241- u .IsActive = * form .Active
239+ ctx . ContextUser .IsActive = * form .Active
242240 }
243241 if len (form .Visibility ) != 0 {
244- u .Visibility = api .VisibilityModes [form .Visibility ]
242+ ctx . ContextUser .Visibility = api .VisibilityModes [form .Visibility ]
245243 }
246244 if form .Admin != nil {
247- u .IsAdmin = * form .Admin
245+ ctx . ContextUser .IsAdmin = * form .Admin
248246 }
249247 if form .AllowGitHook != nil {
250- u .AllowGitHook = * form .AllowGitHook
248+ ctx . ContextUser .AllowGitHook = * form .AllowGitHook
251249 }
252250 if form .AllowImportLocal != nil {
253- u .AllowImportLocal = * form .AllowImportLocal
251+ ctx . ContextUser .AllowImportLocal = * form .AllowImportLocal
254252 }
255253 if form .MaxRepoCreation != nil {
256- u .MaxRepoCreation = * form .MaxRepoCreation
254+ ctx . ContextUser .MaxRepoCreation = * form .MaxRepoCreation
257255 }
258256 if form .AllowCreateOrganization != nil {
259- u .AllowCreateOrganization = * form .AllowCreateOrganization
257+ ctx . ContextUser .AllowCreateOrganization = * form .AllowCreateOrganization
260258 }
261259 if form .ProhibitLogin != nil {
262- u .ProhibitLogin = * form .ProhibitLogin
260+ ctx . ContextUser .ProhibitLogin = * form .ProhibitLogin
263261 }
264262 if form .Restricted != nil {
265- u .IsRestricted = * form .Restricted
263+ ctx . ContextUser .IsRestricted = * form .Restricted
266264 }
267265
268- if err := user_model .UpdateUser (u , emailChanged ); err != nil {
266+ if err := user_model .UpdateUser (ctx . ContextUser , emailChanged ); err != nil {
269267 if user_model .IsErrEmailAlreadyUsed (err ) ||
270268 user_model .IsErrEmailCharIsNotSupported (err ) ||
271269 user_model .IsErrEmailInvalid (err ) {
@@ -275,9 +273,9 @@ func EditUser(ctx *context.APIContext) {
275273 }
276274 return
277275 }
278- log .Trace ("Account profile updated by admin (%s): %s" , ctx .Doer .Name , u .Name )
276+ log .Trace ("Account profile updated by admin (%s): %s" , ctx .Doer .Name , ctx . ContextUser .Name )
279277
280- ctx .JSON (http .StatusOK , convert .ToUser (u , ctx .Doer ))
278+ ctx .JSON (http .StatusOK , convert .ToUser (ctx . ContextUser , ctx .Doer ))
281279}
282280
283281// DeleteUser api for deleting a user
@@ -301,17 +299,12 @@ func DeleteUser(ctx *context.APIContext) {
301299 // "422":
302300 // "$ref": "#/responses/validationError"
303301
304- u := user .GetUserByParams (ctx )
305- if ctx .Written () {
306- return
307- }
308-
309- if u .IsOrganization () {
310- ctx .Error (http .StatusUnprocessableEntity , "" , fmt .Errorf ("%s is an organization not a user" , u .Name ))
302+ if ctx .ContextUser .IsOrganization () {
303+ ctx .Error (http .StatusUnprocessableEntity , "" , fmt .Errorf ("%s is an organization not a user" , ctx .ContextUser .Name ))
311304 return
312305 }
313306
314- if err := user_service .DeleteUser (u ); err != nil {
307+ if err := user_service .DeleteUser (ctx . ContextUser ); err != nil {
315308 if models .IsErrUserOwnRepos (err ) ||
316309 models .IsErrUserHasOrgs (err ) {
317310 ctx .Error (http .StatusUnprocessableEntity , "" , err )
@@ -320,7 +313,7 @@ func DeleteUser(ctx *context.APIContext) {
320313 }
321314 return
322315 }
323- log .Trace ("Account deleted by admin(%s): %s" , ctx .Doer .Name , u .Name )
316+ log .Trace ("Account deleted by admin(%s): %s" , ctx .Doer .Name , ctx . ContextUser .Name )
324317
325318 ctx .Status (http .StatusNoContent )
326319}
@@ -351,12 +344,10 @@ func CreatePublicKey(ctx *context.APIContext) {
351344 // "$ref": "#/responses/forbidden"
352345 // "422":
353346 // "$ref": "#/responses/validationError"
347+
354348 form := web .GetForm (ctx ).(* api.CreateKeyOption )
355- u := user .GetUserByParams (ctx )
356- if ctx .Written () {
357- return
358- }
359- user .CreateUserPublicKey (ctx , * form , u .ID )
349+
350+ user .CreateUserPublicKey (ctx , * form , ctx .ContextUser .ID )
360351}
361352
362353// DeleteUserPublicKey api for deleting a user's public key
@@ -386,12 +377,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
386377 // "404":
387378 // "$ref": "#/responses/notFound"
388379
389- u := user .GetUserByParams (ctx )
390- if ctx .Written () {
391- return
392- }
393-
394- if err := asymkey_service .DeletePublicKey (u , ctx .ParamsInt64 (":id" )); err != nil {
380+ if err := asymkey_service .DeletePublicKey (ctx .ContextUser , ctx .ParamsInt64 (":id" )); err != nil {
395381 if asymkey_model .IsErrKeyNotExist (err ) {
396382 ctx .NotFound ()
397383 } else if asymkey_model .IsErrKeyAccessDenied (err ) {
@@ -401,7 +387,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
401387 }
402388 return
403389 }
404- log .Trace ("Key deleted by admin(%s): %s" , ctx .Doer .Name , u .Name )
390+ log .Trace ("Key deleted by admin(%s): %s" , ctx .Doer .Name , ctx . ContextUser .Name )
405391
406392 ctx .Status (http .StatusNoContent )
407393}
0 commit comments