diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-05-21 23:13:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-21 23:13:47 +0800 |
commit | c59a057297c782f44a81a3e630b5094a58099edb (patch) | |
tree | 58c3020b0da9755fa769619bb3ad80e656f25cd9 /models/user/error.go | |
parent | 64f6a5d113da0d5d187752c9398d6e8d22d24b79 (diff) | |
download | gitea-c59a057297c782f44a81a3e630b5094a58099edb.tar.gz gitea-c59a057297c782f44a81a3e630b5094a58099edb.zip |
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`
Diffstat (limited to 'models/user/error.go')
-rw-r--r-- | models/user/error.go | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/models/user/error.go b/models/user/error.go index 306b9ee9d9..f512994169 100644 --- a/models/user/error.go +++ b/models/user/error.go @@ -9,13 +9,6 @@ import ( "code.gitea.io/gitea/modules/util" ) -// ____ ___ -// | | \______ ___________ -// | | / ___// __ \_ __ \ -// | | /\___ \\ ___/| | \/ -// |______//____ >\___ >__| -// \/ \/ - // ErrUserAlreadyExist represents a "user already exists" error. type ErrUserAlreadyExist struct { Name string @@ -99,3 +92,34 @@ func (err ErrUserInactive) Error() string { func (err ErrUserInactive) Unwrap() error { return util.ErrPermissionDenied } + +// ErrUserIsNotLocal represents a "ErrUserIsNotLocal" kind of error. +type ErrUserIsNotLocal struct { + UID int64 + Name string +} + +func (err ErrUserIsNotLocal) Error() string { + return fmt.Sprintf("user is not local type [uid: %d, name: %s]", err.UID, err.Name) +} + +// IsErrUserIsNotLocal +func IsErrUserIsNotLocal(err error) bool { + _, ok := err.(ErrUserIsNotLocal) + return ok +} + +type ErrUsernameNotChanged struct { + UID int64 + Name string +} + +func (err ErrUsernameNotChanged) Error() string { + return fmt.Sprintf("username hasn't been changed[uid: %d, name: %s]", err.UID, err.Name) +} + +// IsErrUsernameNotChanged +func IsErrUsernameNotChanged(err error) bool { + _, ok := err.(ErrUsernameNotChanged) + return ok +} |