diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-24 17:49:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 17:49:20 +0800 |
commit | a666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch) | |
tree | 9ab1434b759a8a2cb275a83149903a823851e309 /routers/private | |
parent | 4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff) | |
download | gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip |
Move user related model into models/user (#17781)
* Move user related model into models/user
* Fix lint for windows
* Fix windows lint
* Fix windows lint
* Move some tests in models
* Merge
Diffstat (limited to 'routers/private')
-rw-r--r-- | routers/private/hook_pre_receive.go | 9 | ||||
-rw-r--r-- | routers/private/mail.go | 6 | ||||
-rw-r--r-- | routers/private/serv.go | 15 |
3 files changed, 16 insertions, 14 deletions
diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go index 04c334b38f..5ab21d525b 100644 --- a/routers/private/hook_pre_receive.go +++ b/routers/private/hook_pre_receive.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -23,7 +24,7 @@ import ( type preReceiveContext struct { *gitea_context.PrivateContext - user *models.User + user *user_model.User perm models.Permission canCreatePullRequest bool @@ -41,7 +42,7 @@ type preReceiveContext struct { } // User gets or loads User -func (ctx *preReceiveContext) User() *models.User { +func (ctx *preReceiveContext) User() *user_model.User { if ctx.user == nil { ctx.user, ctx.perm = loadUserAndPermission(ctx.PrivateContext, ctx.opts.UserID) } @@ -449,8 +450,8 @@ func generateGitEnv(opts *private.HookOptions) (env []string) { return env } -func loadUserAndPermission(ctx *gitea_context.PrivateContext, id int64) (user *models.User, perm models.Permission) { - user, err := models.GetUserByID(id) +func loadUserAndPermission(ctx *gitea_context.PrivateContext, id int64) (user *user_model.User, perm models.Permission) { + user, err := user_model.GetUserByID(id) if err != nil { log.Error("Unable to get User id %d Error: %v", id, err) ctx.JSON(http.StatusInternalServerError, private.Response{ diff --git a/routers/private/mail.go b/routers/private/mail.go index 6b9100159a..5218cd34a1 100644 --- a/routers/private/mail.go +++ b/routers/private/mail.go @@ -9,7 +9,7 @@ import ( "net/http" "strconv" - "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" @@ -44,7 +44,7 @@ func SendEmail(ctx *context.PrivateContext) { var emails []string if len(mail.To) > 0 { for _, uname := range mail.To { - user, err := models.GetUserByName(uname) + user, err := user_model.GetUserByName(uname) if err != nil { err := fmt.Sprintf("Failed to get user information: %v", err) log.Error(err) @@ -59,7 +59,7 @@ func SendEmail(ctx *context.PrivateContext) { } } } else { - err := models.IterateUser(func(user *models.User) error { + err := user_model.IterateUser(func(user *user_model.User) error { if len(user.Email) > 0 { emails = append(emails, user.Email) } diff --git a/routers/private/serv.go b/routers/private/serv.go index 329d80476a..18057ededb 100644 --- a/routers/private/serv.go +++ b/routers/private/serv.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -48,9 +49,9 @@ func ServNoCommand(ctx *context.PrivateContext) { results.Key = key if key.Type == models.KeyTypeUser || key.Type == models.KeyTypePrincipal { - user, err := models.GetUserByID(key.OwnerID) + user, err := user_model.GetUserByID(key.OwnerID) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.JSON(http.StatusUnauthorized, private.Response{ Err: fmt.Sprintf("Cannot find owner with id: %d for key: %d", key.OwnerID, keyID), }) @@ -105,7 +106,7 @@ func ServCommand(ctx *context.PrivateContext) { results.RepoName = repoName[:len(repoName)-5] } - owner, err := models.GetUserByName(results.OwnerName) + owner, err := user_model.GetUserByName(results.OwnerName) if err != nil { log.Error("Unable to get repository owner: %s/%s Error: %v", results.OwnerName, results.RepoName, err) ctx.JSON(http.StatusInternalServerError, private.ErrServCommand{ @@ -214,7 +215,7 @@ func ServCommand(ctx *context.PrivateContext) { // So now we need to check if the key is a deploy key // We'll keep hold of the deploy key here for permissions checking var deployKey *models.DeployKey - var user *models.User + var user *user_model.User if key.Type == models.KeyTypeDeploy { results.IsDeployKey = true @@ -248,9 +249,9 @@ func ServCommand(ctx *context.PrivateContext) { } else { // Get the user represented by the Key var err error - user, err = models.GetUserByID(key.OwnerID) + user, err = user_model.GetUserByID(key.OwnerID) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.JSON(http.StatusUnauthorized, private.ErrServCommand{ Results: results, Err: fmt.Sprintf("Public Key: %d:%s owner %d does not exist.", key.ID, key.Name, key.OwnerID), @@ -333,7 +334,7 @@ func ServCommand(ctx *context.PrivateContext) { // We already know we aren't using a deploy key if !repoExist { - owner, err := models.GetUserByName(ownerName) + owner, err := user_model.GetUserByName(ownerName) if err != nil { ctx.JSON(http.StatusInternalServerError, private.ErrServCommand{ Results: results, |