mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-25 21:00:01 +02:00
Refactor rename user and rename organization (#24052)
This PR is a refactor at the beginning. And now it did 4 things. - [x] Move renaming organizaiton and user logics into services layer and merged as one function - [x] Support rename a user capitalization only. For example, rename the user from `Lunny` to `lunny`. We just need to change one table `user` and others should not be touched. - [x] Before this PR, some renaming were missed like `agit` - [x] Fix bug the API reutrned from `http.StatusNoContent` to `http.StatusOK`
This commit is contained in:
parent
64f6a5d113
commit
c59a057297
12 changed files with 267 additions and 188 deletions
|
@ -502,17 +502,15 @@ func RenameUser(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
oldName := ctx.ContextUser.Name
|
||||
newName := web.GetForm(ctx).(*api.RenameUserOption).NewName
|
||||
|
||||
if strings.EqualFold(newName, ctx.ContextUser.Name) {
|
||||
// Noop as username is not changed
|
||||
ctx.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if user name has been changed
|
||||
if err := user_service.RenameUser(ctx, ctx.ContextUser, newName); err != nil {
|
||||
switch {
|
||||
case user_model.IsErrUsernameNotChanged(err):
|
||||
// Noop as username is not changed
|
||||
ctx.Status(http.StatusNoContent)
|
||||
case user_model.IsErrUserAlreadyExist(err):
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", ctx.Tr("form.username_been_taken"))
|
||||
case db.IsErrNameReserved(err):
|
||||
|
@ -526,5 +524,7 @@ func RenameUser(ctx *context.APIContext) {
|
|||
}
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
|
||||
log.Trace("User name changed: %s -> %s", oldName, newName)
|
||||
ctx.Status(http.StatusOK)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue