@@ -73,6 +73,7 @@ func CreateUser(ctx *context.APIContext) {
73
73
// "$ref": "#/responses/forbidden"
74
74
// "422":
75
75
// "$ref": "#/responses/validationError"
76
+
76
77
form := web .GetForm (ctx ).(* api.CreateUserOption )
77
78
78
79
u := & user_model.User {
@@ -163,13 +164,10 @@ func EditUser(ctx *context.APIContext) {
163
164
// "$ref": "#/responses/forbidden"
164
165
// "422":
165
166
// "$ref": "#/responses/validationError"
167
+
166
168
form := web .GetForm (ctx ).(* api.EditUserOption )
167
- u := user .GetUserByParams (ctx )
168
- if ctx .Written () {
169
- return
170
- }
171
169
172
- parseAuthSource (ctx , u , form .SourceID , form .LoginName )
170
+ parseAuthSource (ctx , ctx . ContextUser , form .SourceID , form .LoginName )
173
171
if ctx .Written () {
174
172
return
175
173
}
@@ -193,24 +191,24 @@ func EditUser(ctx *context.APIContext) {
193
191
ctx .Error (http .StatusBadRequest , "PasswordPwned" , errors .New ("PasswordPwned" ))
194
192
return
195
193
}
196
- if u .Salt , err = user_model .GetUserSalt (); err != nil {
194
+ if ctx . ContextUser .Salt , err = user_model .GetUserSalt (); err != nil {
197
195
ctx .Error (http .StatusInternalServerError , "UpdateUser" , err )
198
196
return
199
197
}
200
- if err = u .SetPassword (form .Password ); err != nil {
198
+ if err = ctx . ContextUser .SetPassword (form .Password ); err != nil {
201
199
ctx .InternalServerError (err )
202
200
return
203
201
}
204
202
}
205
203
206
204
if form .MustChangePassword != nil {
207
- u .MustChangePassword = * form .MustChangePassword
205
+ ctx . ContextUser .MustChangePassword = * form .MustChangePassword
208
206
}
209
207
210
- u .LoginName = form .LoginName
208
+ ctx . ContextUser .LoginName = form .LoginName
211
209
212
210
if form .FullName != nil {
213
- u .FullName = * form .FullName
211
+ ctx . ContextUser .FullName = * form .FullName
214
212
}
215
213
var emailChanged bool
216
214
if form .Email != nil {
@@ -225,47 +223,47 @@ func EditUser(ctx *context.APIContext) {
225
223
return
226
224
}
227
225
228
- emailChanged = ! strings .EqualFold (u .Email , email )
229
- u .Email = email
226
+ emailChanged = ! strings .EqualFold (ctx . ContextUser .Email , email )
227
+ ctx . ContextUser .Email = email
230
228
}
231
229
if form .Website != nil {
232
- u .Website = * form .Website
230
+ ctx . ContextUser .Website = * form .Website
233
231
}
234
232
if form .Location != nil {
235
- u .Location = * form .Location
233
+ ctx . ContextUser .Location = * form .Location
236
234
}
237
235
if form .Description != nil {
238
- u .Description = * form .Description
236
+ ctx . ContextUser .Description = * form .Description
239
237
}
240
238
if form .Active != nil {
241
- u .IsActive = * form .Active
239
+ ctx . ContextUser .IsActive = * form .Active
242
240
}
243
241
if len (form .Visibility ) != 0 {
244
- u .Visibility = api .VisibilityModes [form .Visibility ]
242
+ ctx . ContextUser .Visibility = api .VisibilityModes [form .Visibility ]
245
243
}
246
244
if form .Admin != nil {
247
- u .IsAdmin = * form .Admin
245
+ ctx . ContextUser .IsAdmin = * form .Admin
248
246
}
249
247
if form .AllowGitHook != nil {
250
- u .AllowGitHook = * form .AllowGitHook
248
+ ctx . ContextUser .AllowGitHook = * form .AllowGitHook
251
249
}
252
250
if form .AllowImportLocal != nil {
253
- u .AllowImportLocal = * form .AllowImportLocal
251
+ ctx . ContextUser .AllowImportLocal = * form .AllowImportLocal
254
252
}
255
253
if form .MaxRepoCreation != nil {
256
- u .MaxRepoCreation = * form .MaxRepoCreation
254
+ ctx . ContextUser .MaxRepoCreation = * form .MaxRepoCreation
257
255
}
258
256
if form .AllowCreateOrganization != nil {
259
- u .AllowCreateOrganization = * form .AllowCreateOrganization
257
+ ctx . ContextUser .AllowCreateOrganization = * form .AllowCreateOrganization
260
258
}
261
259
if form .ProhibitLogin != nil {
262
- u .ProhibitLogin = * form .ProhibitLogin
260
+ ctx . ContextUser .ProhibitLogin = * form .ProhibitLogin
263
261
}
264
262
if form .Restricted != nil {
265
- u .IsRestricted = * form .Restricted
263
+ ctx . ContextUser .IsRestricted = * form .Restricted
266
264
}
267
265
268
- if err := user_model .UpdateUser (u , emailChanged ); err != nil {
266
+ if err := user_model .UpdateUser (ctx . ContextUser , emailChanged ); err != nil {
269
267
if user_model .IsErrEmailAlreadyUsed (err ) ||
270
268
user_model .IsErrEmailCharIsNotSupported (err ) ||
271
269
user_model .IsErrEmailInvalid (err ) {
@@ -275,9 +273,9 @@ func EditUser(ctx *context.APIContext) {
275
273
}
276
274
return
277
275
}
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 )
279
277
280
- ctx .JSON (http .StatusOK , convert .ToUser (u , ctx .Doer ))
278
+ ctx .JSON (http .StatusOK , convert .ToUser (ctx . ContextUser , ctx .Doer ))
281
279
}
282
280
283
281
// DeleteUser api for deleting a user
@@ -301,17 +299,12 @@ func DeleteUser(ctx *context.APIContext) {
301
299
// "422":
302
300
// "$ref": "#/responses/validationError"
303
301
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 ))
311
304
return
312
305
}
313
306
314
- if err := user_service .DeleteUser (u ); err != nil {
307
+ if err := user_service .DeleteUser (ctx . ContextUser ); err != nil {
315
308
if models .IsErrUserOwnRepos (err ) ||
316
309
models .IsErrUserHasOrgs (err ) {
317
310
ctx .Error (http .StatusUnprocessableEntity , "" , err )
@@ -320,7 +313,7 @@ func DeleteUser(ctx *context.APIContext) {
320
313
}
321
314
return
322
315
}
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 )
324
317
325
318
ctx .Status (http .StatusNoContent )
326
319
}
@@ -351,12 +344,10 @@ func CreatePublicKey(ctx *context.APIContext) {
351
344
// "$ref": "#/responses/forbidden"
352
345
// "422":
353
346
// "$ref": "#/responses/validationError"
347
+
354
348
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 )
360
351
}
361
352
362
353
// DeleteUserPublicKey api for deleting a user's public key
@@ -386,12 +377,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
386
377
// "404":
387
378
// "$ref": "#/responses/notFound"
388
379
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 {
395
381
if asymkey_model .IsErrKeyNotExist (err ) {
396
382
ctx .NotFound ()
397
383
} else if asymkey_model .IsErrKeyAccessDenied (err ) {
@@ -401,7 +387,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
401
387
}
402
388
return
403
389
}
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 )
405
391
406
392
ctx .Status (http .StatusNoContent )
407
393
}
0 commit comments