-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Refactor rename user and rename organization #24052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cdd32a1
refactor rename user and rename organization
lunny 7f5af9c
Add integration test for admin rename user
lunny 07445ed
Fix test
lunny 7aeb9ab
Merge branch 'main' into lunny/refactor_user
lunny 9edd592
Fix bug
lunny f024d8f
Merge branch 'main' into lunny/refactor_user
lunny 3889aee
Fix test
lunny a4465d8
Merge branch 'main' into lunny/refactor_user
lunny d9269e3
Merge branch 'main' into lunny/refactor_user
techknowlogick 4f630eb
Fix test
lunny 5f81de3
Merge branch 'main' into lunny/refactor_user
lunny a53d3eb
Merge branch 'lunny/refactor_user' of github.com:lunny/gitea into lun…
lunny 7b053b5
Merge branch 'main' into lunny/refactor_user
6543 7eeb6ca
Follow yp05327's suggestion
lunny fb439e2
Merge branch 'main' into lunny/refactor_user
lunny a72707e
Merge branch 'lunny/refactor_user' of github.com:lunny/gitea into lun…
lunny 6d9870a
Follow reviewers' suggestion
lunny 0d08560
merge main branch
lunny c6f01e3
Merge duplicated functions
lunny 67ec820
Improve trace
lunny 5a87f6e
Merge branch 'main' into lunny/refactor_user
lunny b8e748f
Merge branch 'main' into lunny/refactor_user
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package user | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
user_model "code.gitea.io/gitea/models/user" | ||
"code.gitea.io/gitea/modules/avatar" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/storage" | ||
) | ||
|
||
// UploadAvatar saves custom avatar for user. | ||
func UploadAvatar(u *user_model.User, data []byte) error { | ||
avatarData, err := avatar.ProcessAvatarImage(data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ctx, committer, err := db.TxContext(db.DefaultContext) | ||
if err != nil { | ||
return err | ||
} | ||
defer committer.Close() | ||
|
||
u.UseCustomAvatar = true | ||
u.Avatar = avatar.HashAvatar(u.ID, data) | ||
if err = user_model.UpdateUserCols(ctx, u, "use_custom_avatar", "avatar"); err != nil { | ||
return fmt.Errorf("updateUser: %w", err) | ||
} | ||
|
||
if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error { | ||
_, err := w.Write(avatarData) | ||
return err | ||
}); err != nil { | ||
return fmt.Errorf("Failed to create dir %s: %w", u.CustomAvatarRelativePath(), err) | ||
} | ||
|
||
return committer.Commit() | ||
} | ||
|
||
// DeleteAvatar deletes the user's custom avatar. | ||
func DeleteAvatar(u *user_model.User) error { | ||
aPath := u.CustomAvatarRelativePath() | ||
log.Trace("DeleteAvatar[%d]: %s", u.ID, aPath) | ||
if len(u.Avatar) > 0 { | ||
if err := storage.Avatars.Delete(aPath); err != nil { | ||
return fmt.Errorf("Failed to remove %s: %w", aPath, err) | ||
} | ||
} | ||
|
||
u.UseCustomAvatar = false | ||
u.Avatar = "" | ||
if _, err := db.GetEngine(db.DefaultContext).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil { | ||
return fmt.Errorf("UpdateUser: %w", err) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.