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/web | |
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/web')
38 files changed, 339 insertions, 312 deletions
diff --git a/routers/web/admin/orgs.go b/routers/web/admin/orgs.go index df3118b60f..3d440d83cb 100644 --- a/routers/web/admin/orgs.go +++ b/routers/web/admin/orgs.go @@ -6,8 +6,8 @@ package admin import ( - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" @@ -25,9 +25,9 @@ func Organizations(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminOrganizations"] = true - explore.RenderUserSearch(ctx, &models.SearchUserOptions{ + explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{ Actor: ctx.User, - Type: models.UserTypeOrganization, + Type: user_model.UserTypeOrganization, ListOptions: db.ListOptions{ PageSize: setting.UI.Admin.OrgPagingNum, }, diff --git a/routers/web/admin/repos.go b/routers/web/admin/repos.go index 432dd2f6ae..69e522ef7e 100644 --- a/routers/web/admin/repos.go +++ b/routers/web/admin/repos.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -119,9 +120,9 @@ func AdoptOrDeleteRepository(ctx *context.Context) { return } - ctxUser, err := models.GetUserByName(dirSplit[0]) + ctxUser, err := user_model.GetUserByName(dirSplit[0]) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { log.Debug("User does not exist: %s", dirSplit[0]) ctx.Redirect(setting.AppSubURL + "/admin/repos") return diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index 077cf02f15..b92c5cf01a 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -56,9 +56,9 @@ func Users(ctx *context.Context) { "SortType": sortType, } - explore.RenderUserSearch(ctx, &models.SearchUserOptions{ + explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{ Actor: ctx.User, - Type: models.UserTypeIndividual, + Type: user_model.UserTypeIndividual, ListOptions: db.ListOptions{ PageSize: setting.UI.Admin.UserPagingNum, }, @@ -114,7 +114,7 @@ func NewUserPost(ctx *context.Context) { return } - u := &models.User{ + u := &user_model.User{ Name: form.UserName, Email: form.Email, Passwd: form.Password, @@ -156,9 +156,9 @@ func NewUserPost(ctx *context.Context) { u.MustChangePassword = form.MustChangePassword } - if err := models.CreateUser(u, &models.CreateUserOverwriteOptions{Visibility: form.Visibility}); err != nil { + if err := user_model.CreateUser(u, &user_model.CreateUserOverwriteOptions{Visibility: form.Visibility}); err != nil { switch { - case models.IsErrUserAlreadyExist(err): + case user_model.IsErrUserAlreadyExist(err): ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplUserNew, &form) case user_model.IsErrEmailAlreadyUsed(err): @@ -167,15 +167,15 @@ func NewUserPost(ctx *context.Context) { case user_model.IsErrEmailInvalid(err): ctx.Data["Err_Email"] = true ctx.RenderWithErr(ctx.Tr("form.email_invalid"), tplUserNew, &form) - case models.IsErrNameReserved(err): + case db.IsErrNameReserved(err): ctx.Data["Err_UserName"] = true - ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplUserNew, &form) - case models.IsErrNamePatternNotAllowed(err): + ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(db.ErrNameReserved).Name), tplUserNew, &form) + case db.IsErrNamePatternNotAllowed(err): ctx.Data["Err_UserName"] = true - ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form) - case models.IsErrNameCharsNotAllowed(err): + ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form) + case db.IsErrNameCharsNotAllowed(err): ctx.Data["Err_UserName"] = true - ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(models.ErrNameCharsNotAllowed).Name), tplUserNew, &form) + ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(db.ErrNameCharsNotAllowed).Name), tplUserNew, &form) default: ctx.ServerError("CreateUser", err) } @@ -192,8 +192,8 @@ func NewUserPost(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/admin/users/" + strconv.FormatInt(u.ID, 10)) } -func prepareUserInfo(ctx *context.Context) *models.User { - u, err := models.GetUserByID(ctx.ParamsInt64(":userid")) +func prepareUserInfo(ctx *context.Context) *user_model.User { + u, err := user_model.GetUserByID(ctx.ParamsInt64(":userid")) if err != nil { ctx.ServerError("GetUserByID", err) return nil @@ -298,7 +298,7 @@ func EditUserPost(ctx *context.Context) { ctx.RenderWithErr(errMsg, tplUserNew, &form) return } - if u.Salt, err = models.GetUserSalt(); err != nil { + if u.Salt, err = user_model.GetUserSalt(); err != nil { ctx.ServerError("UpdateUser", err) return } @@ -352,7 +352,7 @@ func EditUserPost(ctx *context.Context) { u.ProhibitLogin = form.ProhibitLogin } - if err := models.UpdateUser(u); err != nil { + if err := user_model.UpdateUser(u); err != nil { if user_model.IsErrEmailAlreadyUsed(err) { ctx.Data["Err_Email"] = true ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form) @@ -372,7 +372,7 @@ func EditUserPost(ctx *context.Context) { // DeleteUser response for deleting a user func DeleteUser(ctx *context.Context) { - u, err := models.GetUserByID(ctx.ParamsInt64(":userid")) + u, err := user_model.GetUserByID(ctx.ParamsInt64(":userid")) if err != nil { ctx.ServerError("GetUserByID", err) return diff --git a/routers/web/admin/users_test.go b/routers/web/admin/users_test.go index 607ef2ea66..1849781bc4 100644 --- a/routers/web/admin/users_test.go +++ b/routers/web/admin/users_test.go @@ -7,8 +7,8 @@ package admin import ( "testing" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/test" @@ -23,10 +23,10 @@ func TestNewUserPost_MustChangePassword(t *testing.T) { unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "admin/users/new") - u := unittest.AssertExistsAndLoadBean(t, &models.User{ + u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, ID: 2, - }).(*models.User) + }).(*user_model.User) ctx.User = u @@ -48,7 +48,7 @@ func TestNewUserPost_MustChangePassword(t *testing.T) { assert.NotEmpty(t, ctx.Flash.SuccessMsg) - u, err := models.GetUserByName(username) + u, err := user_model.GetUserByName(username) assert.NoError(t, err) assert.Equal(t, username, u.Name) @@ -60,10 +60,10 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) { unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "admin/users/new") - u := unittest.AssertExistsAndLoadBean(t, &models.User{ + u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, ID: 2, - }).(*models.User) + }).(*user_model.User) ctx.User = u @@ -85,7 +85,7 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) { assert.NotEmpty(t, ctx.Flash.SuccessMsg) - u, err := models.GetUserByName(username) + u, err := user_model.GetUserByName(username) assert.NoError(t, err) assert.Equal(t, username, u.Name) @@ -97,10 +97,10 @@ func TestNewUserPost_InvalidEmail(t *testing.T) { unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "admin/users/new") - u := unittest.AssertExistsAndLoadBean(t, &models.User{ + u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, ID: 2, - }).(*models.User) + }).(*user_model.User) ctx.User = u @@ -127,10 +127,10 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) { unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "admin/users/new") - u := unittest.AssertExistsAndLoadBean(t, &models.User{ + u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, ID: 2, - }).(*models.User) + }).(*user_model.User) ctx.User = u @@ -152,7 +152,7 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) { assert.NotEmpty(t, ctx.Flash.SuccessMsg) - u, err := models.GetUserByName(username) + u, err := user_model.GetUserByName(username) assert.NoError(t, err) assert.Equal(t, username, u.Name) @@ -165,10 +165,10 @@ func TestNewUserPost_VisibilityPrivate(t *testing.T) { unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "admin/users/new") - u := unittest.AssertExistsAndLoadBean(t, &models.User{ + u := unittest.AssertExistsAndLoadBean(t, &user_model.User{ IsAdmin: true, ID: 2, - }).(*models.User) + }).(*user_model.User) ctx.User = u @@ -191,7 +191,7 @@ func TestNewUserPost_VisibilityPrivate(t *testing.T) { assert.NotEmpty(t, ctx.Flash.SuccessMsg) - u, err := models.GetUserByName(username) + u, err := user_model.GetUserByName(username) assert.NoError(t, err) assert.Equal(t, username, u.Name) diff --git a/routers/web/dev/template.go b/routers/web/dev/template.go index de334c4f8b..29d6033a7a 100644 --- a/routers/web/dev/template.go +++ b/routers/web/dev/template.go @@ -7,7 +7,7 @@ package dev import ( "net/http" - "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" @@ -16,7 +16,7 @@ import ( // TemplatePreview render for previewing the indicated template func TemplatePreview(ctx *context.Context) { - ctx.Data["User"] = models.User{Name: "Unknown"} + ctx.Data["User"] = user_model.User{Name: "Unknown"} ctx.Data["AppName"] = setting.AppName ctx.Data["AppVer"] = setting.AppVer ctx.Data["AppUrl"] = setting.AppURL diff --git a/routers/web/explore/org.go b/routers/web/explore/org.go index d005cfa503..41c0a0c83c 100644 --- a/routers/web/explore/org.go +++ b/routers/web/explore/org.go @@ -5,8 +5,8 @@ package explore import ( - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" @@ -31,9 +31,9 @@ func Organizations(ctx *context.Context) { visibleTypes = append(visibleTypes, structs.VisibleTypeLimited, structs.VisibleTypePrivate) } - RenderUserSearch(ctx, &models.SearchUserOptions{ + RenderUserSearch(ctx, &user_model.SearchUserOptions{ Actor: ctx.User, - Type: models.UserTypeOrganization, + Type: user_model.UserTypeOrganization, ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, Visible: visibleTypes, }, tplExploreOrganizations) diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index 78035037e5..a81386b5fd 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -39,38 +39,38 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { repos []*models.Repository count int64 err error - orderBy models.SearchOrderBy + orderBy db.SearchOrderBy ) ctx.Data["SortType"] = ctx.FormString("sort") switch ctx.FormString("sort") { case "newest": - orderBy = models.SearchOrderByNewest + orderBy = db.SearchOrderByNewest case "oldest": - orderBy = models.SearchOrderByOldest + orderBy = db.SearchOrderByOldest case "recentupdate": - orderBy = models.SearchOrderByRecentUpdated + orderBy = db.SearchOrderByRecentUpdated case "leastupdate": - orderBy = models.SearchOrderByLeastUpdated + orderBy = db.SearchOrderByLeastUpdated case "reversealphabetically": - orderBy = models.SearchOrderByAlphabeticallyReverse + orderBy = db.SearchOrderByAlphabeticallyReverse case "alphabetically": - orderBy = models.SearchOrderByAlphabetically + orderBy = db.SearchOrderByAlphabetically case "reversesize": - orderBy = models.SearchOrderBySizeReverse + orderBy = db.SearchOrderBySizeReverse case "size": - orderBy = models.SearchOrderBySize + orderBy = db.SearchOrderBySize case "moststars": - orderBy = models.SearchOrderByStarsReverse + orderBy = db.SearchOrderByStarsReverse case "feweststars": - orderBy = models.SearchOrderByStars + orderBy = db.SearchOrderByStars case "mostforks": - orderBy = models.SearchOrderByForksReverse + orderBy = db.SearchOrderByForksReverse case "fewestforks": - orderBy = models.SearchOrderByForks + orderBy = db.SearchOrderByForks default: ctx.Data["SortType"] = "recentupdate" - orderBy = models.SearchOrderByRecentUpdated + orderBy = db.SearchOrderByRecentUpdated } keyword := ctx.FormTrim("q") diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index 1fe45ed585..8560378447 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" @@ -34,17 +35,17 @@ func isKeywordValid(keyword string) bool { } // RenderUserSearch render user search page -func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplName base.TplName) { +func RenderUserSearch(ctx *context.Context, opts *user_model.SearchUserOptions, tplName base.TplName) { opts.Page = ctx.FormInt("page") if opts.Page <= 1 { opts.Page = 1 } var ( - users []*models.User + users []*user_model.User count int64 err error - orderBy models.SearchOrderBy + orderBy db.SearchOrderBy ) // we can not set orderBy to `models.SearchOrderByXxx`, because there may be a JOIN in the statement, different tables may have the same name columns @@ -69,7 +70,7 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN opts.Keyword = ctx.FormTrim("q") opts.OrderBy = orderBy if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) { - users, count, err = models.SearchUsers(opts) + users, count, err = user_model.SearchUsers(opts) if err != nil { ctx.ServerError("SearchUsers", err) return @@ -100,9 +101,9 @@ func Users(ctx *context.Context) { ctx.Data["PageIsExploreUsers"] = true ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled - RenderUserSearch(ctx, &models.SearchUserOptions{ + RenderUserSearch(ctx, &user_model.SearchUserOptions{ Actor: ctx.User, - Type: models.UserTypeIndividual, + Type: user_model.UserTypeIndividual, ListOptions: db.ListOptions{PageSize: setting.UI.ExplorePagingNum}, IsActive: util.OptionalBoolTrue, Visible: []structs.VisibleType{structs.VisibleTypePublic, structs.VisibleTypeLimited, structs.VisibleTypePrivate}, diff --git a/routers/web/feed/profile.go b/routers/web/feed/profile.go index 8bd0cb7c29..1a7f4ad24b 100644 --- a/routers/web/feed/profile.go +++ b/routers/web/feed/profile.go @@ -9,6 +9,7 @@ import ( "time" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "github.com/gorilla/feeds" @@ -22,7 +23,7 @@ func RetrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) []*mode return nil } - userCache := map[int64]*models.User{options.RequestedUser.ID: options.RequestedUser} + userCache := map[int64]*user_model.User{options.RequestedUser.ID: options.RequestedUser} if ctx.User != nil { userCache[ctx.User.ID] = ctx.User } @@ -35,9 +36,9 @@ func RetrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) []*mode for _, act := range actions { repoOwner, ok := userCache[act.Repo.OwnerID] if !ok { - repoOwner, err = models.GetUserByID(act.Repo.OwnerID) + repoOwner, err = user_model.GetUserByID(act.Repo.OwnerID) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { continue } ctx.ServerError("GetUserByID", err) @@ -51,7 +52,7 @@ func RetrieveFeeds(ctx *context.Context, options models.GetFeedsOptions) []*mode } // ShowUserFeed show user activity as RSS / Atom feed -func ShowUserFeed(ctx *context.Context, ctxUser *models.User, formatType string) { +func ShowUserFeed(ctx *context.Context, ctxUser *user_model.User, formatType string) { actions := RetrieveFeeds(ctx, models.GetFeedsOptions{ RequestedUser: ctxUser, Actor: ctx.User, diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 6e81257135..0dc441fe84 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -50,32 +50,32 @@ func Home(ctx *context.Context) { ctx.Data["RenderedDescription"] = desc } - var orderBy models.SearchOrderBy + var orderBy db.SearchOrderBy ctx.Data["SortType"] = ctx.FormString("sort") switch ctx.FormString("sort") { case "newest": - orderBy = models.SearchOrderByNewest + orderBy = db.SearchOrderByNewest case "oldest": - orderBy = models.SearchOrderByOldest + orderBy = db.SearchOrderByOldest case "recentupdate": - orderBy = models.SearchOrderByRecentUpdated + orderBy = db.SearchOrderByRecentUpdated case "leastupdate": - orderBy = models.SearchOrderByLeastUpdated + orderBy = db.SearchOrderByLeastUpdated case "reversealphabetically": - orderBy = models.SearchOrderByAlphabeticallyReverse + orderBy = db.SearchOrderByAlphabeticallyReverse case "alphabetically": - orderBy = models.SearchOrderByAlphabetically + orderBy = db.SearchOrderByAlphabetically case "moststars": - orderBy = models.SearchOrderByStarsReverse + orderBy = db.SearchOrderByStarsReverse case "feweststars": - orderBy = models.SearchOrderByStars + orderBy = db.SearchOrderByStars case "mostforks": - orderBy = models.SearchOrderByForksReverse + orderBy = db.SearchOrderByForksReverse case "fewestforks": - orderBy = models.SearchOrderByForks + orderBy = db.SearchOrderByForks default: ctx.Data["SortType"] = "recentupdate" - orderBy = models.SearchOrderByRecentUpdated + orderBy = db.SearchOrderByRecentUpdated } keyword := ctx.FormTrim("q") diff --git a/routers/web/org/org.go b/routers/web/org/org.go index 6722f8d104..c66a0cd4c8 100644 --- a/routers/web/org/org.go +++ b/routers/web/org/org.go @@ -10,6 +10,8 @@ import ( "net/http" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -52,7 +54,7 @@ func CreatePost(ctx *context.Context) { org := &models.Organization{ Name: form.OrgName, IsActive: true, - Type: models.UserTypeOrganization, + Type: user_model.UserTypeOrganization, Visibility: form.Visibility, RepoAdminChangeTeamAccess: form.RepoAdminChangeTeamAccess, } @@ -60,12 +62,12 @@ func CreatePost(ctx *context.Context) { if err := models.CreateOrganization(org, ctx.User); err != nil { ctx.Data["Err_OrgName"] = true switch { - case models.IsErrUserAlreadyExist(err): + case user_model.IsErrUserAlreadyExist(err): ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), tplCreateOrg, &form) - case models.IsErrNameReserved(err): - ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), tplCreateOrg, &form) - case models.IsErrNamePatternNotAllowed(err): - ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form) + case db.IsErrNameReserved(err): + ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(db.ErrNameReserved).Name), tplCreateOrg, &form) + case db.IsErrNamePatternNotAllowed(err): + ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form) case models.IsErrUserNotAllowedCreateOrg(err): ctx.RenderWithErr(ctx.Tr("org.form.create_org_not_allowed"), tplCreateOrg, &form) default: diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index 7a6f4fec60..f0e1db14d0 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -61,7 +62,7 @@ func SettingsPost(ctx *context.Context) { // Check if organization name has been changed. if org.LowerName != strings.ToLower(form.Name) { - isExist, err := models.IsUserExist(org.ID, form.Name) + isExist, err := user_model.IsUserExist(org.ID, form.Name) if err != nil { ctx.ServerError("IsUserExist", err) return @@ -69,8 +70,8 @@ func SettingsPost(ctx *context.Context) { ctx.Data["OrgName"] = true ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSettingsOptions, &form) return - } else if err = models.ChangeUserName(org.AsUser(), form.Name); err != nil { - if err == models.ErrUserNameIllegal { + } else if err = user_model.ChangeUserName(org.AsUser(), form.Name); err != nil { + if err == user_model.ErrUserNameIllegal { ctx.Data["OrgName"] = true ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form) } else { @@ -101,7 +102,7 @@ func SettingsPost(ctx *context.Context) { visibilityChanged := form.Visibility != org.Visibility org.Visibility = form.Visibility - if err := models.UpdateUser(org.AsUser()); err != nil { + if err := user_model.UpdateUser(org.AsUser()); err != nil { ctx.ServerError("UpdateUser", err) return } diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index ac6a42904a..da0830aad9 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" unit_model "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -114,10 +115,10 @@ func TeamsAction(ctx *context.Context) { return } uname := utils.RemoveUsernameParameterSuffix(strings.ToLower(ctx.FormString("uname"))) - var u *models.User - u, err = models.GetUserByName(uname) + var u *user_model.User + u, err = user_model.GetUserByName(uname) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.Flash.Error(ctx.Tr("form.user_not_exist")) ctx.Redirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName)) } else { diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go index 2fd72d81ab..5786aa1eb2 100644 --- a/routers/web/repo/blame.go +++ b/routers/web/repo/blame.go @@ -12,6 +12,7 @@ import ( "strings" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -139,9 +140,9 @@ func RefBlame(ctx *context.Context) { ctx.HTML(http.StatusOK, tplBlame) } -func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]*models.UserCommit, map[string]string) { +func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[string]*user_model.UserCommit, map[string]string) { // store commit data by SHA to look up avatar info etc - commitNames := make(map[string]*models.UserCommit) + commitNames := make(map[string]*user_model.UserCommit) // previousCommits contains links from SHA to parent SHA, // if parent also contains the current TreePath. previousCommits := make(map[string]string) @@ -195,14 +196,14 @@ func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) (map[st } // populate commit email addresses to later look up avatars. - for _, c := range models.ValidateCommitsWithEmails(commits) { + for _, c := range user_model.ValidateCommitsWithEmails(commits) { commitNames[c.ID.String()] = c } return commitNames, previousCommits } -func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]*models.UserCommit, previousCommits map[string]string) { +func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]*user_model.UserCommit, previousCommits map[string]string) { repoLink := ctx.Repo.RepoLink language := "" diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index ecb5107a3d..48386f7935 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/charset" "code.gitea.io/gitea/modules/context" @@ -344,7 +345,7 @@ func Diff(ctx *context.Context) { verification := models.ParseCommitWithSignature(commit) ctx.Data["Verification"] = verification - ctx.Data["Author"] = models.ValidateCommitWithEmail(commit) + ctx.Data["Author"] = user_model.ValidateCommitWithEmail(commit) ctx.Data["Parents"] = parents ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0 @@ -358,7 +359,7 @@ func Diff(ctx *context.Context) { if err == nil { ctx.Data["Note"] = string(charset.ToUTF8WithFallback(note.Message)) ctx.Data["NoteCommit"] = note.Commit - ctx.Data["NoteAuthor"] = models.ValidateCommitWithEmail(note.Commit) + ctx.Data["NoteAuthor"] = user_model.ValidateCommitWithEmail(note.Commit) } ctx.Data["BranchName"], err = commit.GetBranchName() diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 706009820a..865a734caf 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -18,6 +18,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/base" "code.gitea.io/gitea/modules/charset" "code.gitea.io/gitea/modules/context" @@ -163,7 +164,7 @@ func setCsvCompareContext(ctx *context.Context) { // CompareInfo represents the collected results from ParseCompareInfo type CompareInfo struct { - HeadUser *models.User + HeadUser *user_model.User HeadRepo *models.Repository HeadGitRepo *git.Repository CompareInfo *git.CompareInfo @@ -237,9 +238,9 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { } else if len(headInfos) == 2 { headInfosSplit := strings.Split(headInfos[0], "/") if len(headInfosSplit) == 1 { - ci.HeadUser, err = models.GetUserByName(headInfos[0]) + ci.HeadUser, err = user_model.GetUserByName(headInfos[0]) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.NotFound("GetUserByName", nil) } else { ctx.ServerError("GetUserByName", err) @@ -262,7 +263,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { return nil } if err := ci.HeadRepo.GetOwner(); err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.NotFound("GetUserByName", nil) } else { ctx.ServerError("GetUserByName", err) diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index 0626d08a7c..ce2d977518 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -110,9 +110,9 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { reponame = reponame[:len(reponame)-5] } - owner, err := models.GetUserByName(username) + owner, err := user_model.GetUserByName(username) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { if redirectUserID, err := user_model.LookupUserRedirect(username); err == nil { context.RedirectToUser(ctx, username, redirectUserID) } else { diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index ac6240e282..1ff126c7d1 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -20,6 +20,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" @@ -470,7 +471,7 @@ func retrieveProjects(ctx *context.Context, repo *models.Repository) { type repoReviewerSelection struct { IsTeam bool Team *models.Team - User *models.User + User *user_model.User Review *models.Review CanChange bool Checked bool @@ -503,7 +504,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue reviewersResult []*repoReviewerSelection teamReviewersResult []*repoReviewerSelection teamReviewers []*models.Team - reviewers []*models.User + reviewers []*user_model.User ) if canChooseReviewer { @@ -575,7 +576,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue for _, item := range pullReviews { if item.Review.ReviewerID > 0 { if err = item.Review.LoadReviewer(); err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { continue } ctx.ServerError("LoadReviewer", err) @@ -919,7 +920,7 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull // Check if the passed assignees actually exists and is assignable for _, aID := range assigneeIDs { - assignee, err := models.GetUserByID(aID) + assignee, err := user_model.GetUserByID(aID) if err != nil { ctx.ServerError("GetUserByID", err) return nil, nil, 0, 0 @@ -1019,7 +1020,7 @@ func NewIssuePost(ctx *context.Context) { } // roleDescriptor returns the Role Decriptor for a comment in/with the given repo, poster and issue -func roleDescriptor(repo *models.Repository, poster *models.User, issue *models.Issue) (models.RoleDescriptor, error) { +func roleDescriptor(repo *models.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) { perm, err := models.GetUserRepoPermission(repo, poster) if err != nil { return models.RoleDescriptorNone, err @@ -1267,7 +1268,7 @@ func ViewIssue(ctx *context.Context) { ok bool marked = make(map[int64]models.RoleDescriptor) comment *models.Comment - participants = make([]*models.User, 1, 10) + participants = make([]*user_model.User, 1, 10) ) if ctx.Repo.Repository.IsTimetrackerEnabled() { if ctx.IsSigned { @@ -1430,11 +1431,11 @@ func ViewIssue(ctx *context.Context) { continue } if err = comment.Review.LoadAttributes(); err != nil { - if !models.IsErrUserNotExist(err) { + if !user_model.IsErrUserNotExist(err) { ctx.ServerError("Review.LoadAttributes", err) return } - comment.Review.Reviewer = models.NewGhostUser() + comment.Review.Reviewer = user_model.NewGhostUser() } if err = comment.Review.LoadCodeComments(); err != nil { ctx.ServerError("Review.LoadCodeComments", err) @@ -1833,12 +1834,12 @@ func UpdateIssueAssignee(ctx *context.Context) { for _, issue := range issues { switch action { case "clear": - if err := issue_service.DeleteNotPassedAssignee(issue, ctx.User, []*models.User{}); err != nil { + if err := issue_service.DeleteNotPassedAssignee(issue, ctx.User, []*user_model.User{}); err != nil { ctx.ServerError("ClearAssignees", err) return } default: - assignee, err := models.GetUserByID(assigneeID) + assignee, err := user_model.GetUserByID(assigneeID) if err != nil { ctx.ServerError("GetUserByID", err) return @@ -1949,9 +1950,9 @@ func UpdatePullReviewRequest(ctx *context.Context) { continue } - reviewer, err := models.GetUserByID(reviewID) + reviewer, err := user_model.GetUserByID(reviewID) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { log.Warn( "UpdatePullReviewRequest: requested reviewer [%d] for %-v to %-v#%d is not exist: Error: %v", reviewID, issue.Repo, issue.Index, @@ -2452,7 +2453,7 @@ func ChangeCommentReaction(ctx *context.Context) { }) } -func addParticipant(poster *models.User, participants []*models.User) []*models.User { +func addParticipant(poster *user_model.User, participants []*user_model.User) []*user_model.User { for _, part := range participants { if poster.ID == part.ID { return participants diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go index b15c7628db..b1bc06f08b 100644 --- a/routers/web/repo/lfs.go +++ b/routers/web/repo/lfs.go @@ -216,9 +216,9 @@ func LFSLockFile(ctx *context.Context) { } _, err := models.CreateLFSLock(&models.LFSLock{ - Repo: ctx.Repo.Repository, - Path: lockPath, - Owner: ctx.User, + Repo: ctx.Repo.Repository, + Path: lockPath, + OwnerID: ctx.User.ID, }) if err != nil { if models.IsErrLFSLockAlreadyExist(err) { diff --git a/routers/web/repo/middlewares.go b/routers/web/repo/middlewares.go index 0dc6e1cb72..3ee9d1a3e9 100644 --- a/routers/web/repo/middlewares.go +++ b/routers/web/repo/middlewares.go @@ -7,8 +7,8 @@ package repo import ( "fmt" - "code.gitea.io/gitea/models" admin_model "code.gitea.io/gitea/models/admin" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" ) @@ -56,7 +56,7 @@ func SetDiffViewStyle(ctx *context.Context) { } ctx.Data["IsSplitStyle"] = style == "split" - if err := models.UpdateUserDiffViewStyle(ctx.User, style); err != nil { + if err := user_model.UpdateUserDiffViewStyle(ctx.User, style); err != nil { ctx.ServerError("ErrUpdateDiffViewStyle", err) } } diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go index 1940d89628..5eba4690d0 100644 --- a/routers/web/repo/migrate.go +++ b/routers/web/repo/migrate.go @@ -11,6 +11,8 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/lfs" @@ -66,7 +68,7 @@ func Migrate(ctx *context.Context) { ctx.HTML(http.StatusOK, base.TplName("repo/migrate/"+serviceType.Name())) } -func handleMigrateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form *forms.MigrateRepoForm) { +func handleMigrateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl base.TplName, form *forms.MigrateRepoForm) { if setting.Repository.DisableMigrations { ctx.Error(http.StatusForbidden, "MigrateError: the site administrator has disabled migrations") return @@ -94,12 +96,12 @@ func handleMigrateError(ctx *context.Context, owner *models.User, err error, nam default: ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tpl, form) } - case models.IsErrNameReserved(err): + case db.IsErrNameReserved(err): ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form) - case models.IsErrNamePatternNotAllowed(err): + ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form) + case db.IsErrNamePatternNotAllowed(err): ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form) + ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form) default: remoteAddr, _ := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword) err = util.NewStringURLSanitizedError(err, remoteAddr, true) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 83e353833f..06aa86206d 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -20,6 +20,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -237,10 +238,10 @@ func ForkPost(ctx *context.Context) { switch { case models.IsErrRepoAlreadyExist(err): ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form) - case models.IsErrNameReserved(err): - ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplFork, &form) - case models.IsErrNamePatternNotAllowed(err): - ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplFork, &form) + case db.IsErrNameReserved(err): + ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplFork, &form) + case db.IsErrNamePatternNotAllowed(err): + ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplFork, &form) default: ctx.ServerError("ForkPost", err) } @@ -1024,7 +1025,7 @@ func MergePullRequest(ctx *context.Context) { ctx.Redirect(issue.Link()) } -func stopTimerIfAvailable(user *models.User, issue *models.Issue) error { +func stopTimerIfAvailable(user *user_model.User, issue *models.Issue) error { if models.StopwatchExists(user.ID, issue.ID) { if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil { @@ -1185,9 +1186,9 @@ func TriggerTask(ctx *context.Context) { return } - pusher, err := models.GetUserByID(pusherID) + pusher, err := user_model.GetUserByID(pusherID) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.Error(http.StatusNotFound) } else { ctx.ServerError("GetUserByID", err) diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 3f12ee72bc..9bca4e6897 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -132,7 +133,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) { // Temporary cache commits count of used branches to speed up. countCache := make(map[string]int64) - cacheUsers := make(map[int64]*models.User) + cacheUsers := make(map[int64]*user_model.User) if ctx.User != nil { cacheUsers[ctx.User.ID] = ctx.User } @@ -140,10 +141,10 @@ func releasesOrTags(ctx *context.Context, isTagList bool) { for _, r := range releases { if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok { - r.Publisher, err = models.GetUserByID(r.PublisherID) + r.Publisher, err = user_model.GetUserByID(r.PublisherID) if err != nil { - if models.IsErrUserNotExist(err) { - r.Publisher = models.NewGhostUser() + if user_model.IsErrUserNotExist(err) { + r.Publisher = user_model.NewGhostUser() } else { ctx.ServerError("GetUserByID", err) return @@ -207,10 +208,10 @@ func SingleRelease(ctx *context.Context) { return } - release.Publisher, err = models.GetUserByID(release.PublisherID) + release.Publisher, err = user_model.GetUserByID(release.PublisherID) if err != nil { - if models.IsErrUserNotExist(err) { - release.Publisher = models.NewGhostUser() + if user_model.IsErrUserNotExist(err) { + release.Publisher = user_model.NewGhostUser() } else { ctx.ServerError("GetUserByID", err) return diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 9463fc4c5f..bacfa549b5 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/graceful" @@ -55,7 +56,7 @@ func MustBeAbleToUpload(ctx *context.Context) { } } -func checkContextUser(ctx *context.Context, uid int64) *models.User { +func checkContextUser(ctx *context.Context, uid int64) *user_model.User { orgs, err := models.GetOrgsCanCreateRepoByUserID(ctx.User.ID) if err != nil { ctx.ServerError("GetOrgsCanCreateRepoByUserID", err) @@ -79,8 +80,8 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User { return ctx.User } - org, err := models.GetUserByID(uid) - if models.IsErrUserNotExist(err) { + org, err := user_model.GetUserByID(uid) + if user_model.IsErrUserNotExist(err) { return ctx.User } @@ -158,7 +159,7 @@ func Create(ctx *context.Context) { ctx.HTML(http.StatusOK, tplCreate) } -func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) { +func handleCreateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl base.TplName, form interface{}) { switch { case models.IsErrReachLimitOfRepo(err): ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.MaxCreationLimit()), tpl, form) @@ -177,12 +178,12 @@ func handleCreateError(ctx *context.Context, owner *models.User, err error, name default: ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tpl, form) } - case models.IsErrNameReserved(err): + case db.IsErrNameReserved(err): ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form) - case models.IsErrNamePatternNotAllowed(err): + ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form) + case db.IsErrNamePatternNotAllowed(err): ctx.Data["Err_RepoName"] = true - ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form) + ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form) default: ctx.ServerError(name, err) } diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 6753ce1172..20fa9ea785 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" unit_model "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -94,8 +95,8 @@ func SettingsPost(ctx *context.Context) { switch { case models.IsErrRepoAlreadyExist(err): ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tplSettingsOptions, &form) - case models.IsErrNameReserved(err): - ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tplSettingsOptions, &form) + case db.IsErrNameReserved(err): + ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplSettingsOptions, &form) case models.IsErrRepoFilesAlreadyExist(err): ctx.Data["Err_RepoName"] = true switch { @@ -108,8 +109,8 @@ func SettingsPost(ctx *context.Context) { default: ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tplSettingsOptions, form) } - case models.IsErrNamePatternNotAllowed(err): - ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form) + case db.IsErrNamePatternNotAllowed(err): + ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tplSettingsOptions, &form) default: ctx.ServerError("ChangeRepositoryName", err) } @@ -577,9 +578,9 @@ func SettingsPost(ctx *context.Context) { return } - newOwner, err := models.GetUserByName(ctx.FormString("new_owner_name")) + newOwner, err := user_model.GetUserByName(ctx.FormString("new_owner_name")) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil) return } @@ -587,7 +588,7 @@ func SettingsPost(ctx *context.Context) { return } - if newOwner.Type == models.UserTypeOrganization { + if newOwner.Type == user_model.UserTypeOrganization { if !ctx.User.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !models.OrgFromUser(newOwner).HasMemberWithUserID(ctx.User.ID) { // The user shouldn't know about this organization ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil) @@ -798,9 +799,9 @@ func CollaborationPost(ctx *context.Context) { return } - u, err := models.GetUserByName(name) + u, err := user_model.GetUserByName(name) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.Flash.Error(ctx.Tr("form.user_not_exist")) ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath()) } else { @@ -935,10 +936,10 @@ func DeleteTeam(ctx *context.Context) { } // parseOwnerAndRepo get repos by owner -func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) { - owner, err := models.GetUserByName(ctx.Params(":username")) +func parseOwnerAndRepo(ctx *context.Context) (*user_model.User, *models.Repository) { + owner, err := user_model.GetUserByName(ctx.Params(":username")) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.NotFound("GetUserByName", err) } else { ctx.ServerError("GetUserByName", err) diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go index 3e8ae2b07e..8e53babe7c 100644 --- a/routers/web/repo/settings_test.go +++ b/routers/web/repo/settings_test.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/test" @@ -105,9 +106,9 @@ func TestCollaborationPost(t *testing.T) { ctx.Req.Form.Set("collaborator", "user4") - u := &models.User{ + u := &user_model.User{ LowerName: "user2", - Type: models.UserTypeIndividual, + Type: user_model.UserTypeIndividual, } re := &models.Repository{ @@ -142,7 +143,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) { ctx.Req.Form.Set("collaborator", "user9") repo := &context.Repository{ - Owner: &models.User{ + Owner: &user_model.User{ LowerName: "user2", }, } @@ -165,9 +166,9 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { ctx.Req.Form.Set("collaborator", "user4") - u := &models.User{ + u := &user_model.User{ LowerName: "user2", - Type: models.UserTypeIndividual, + Type: user_model.UserTypeIndividual, } re := &models.Repository{ @@ -207,7 +208,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) { ctx.Req.Form.Set("collaborator", "user34") repo := &context.Repository{ - Owner: &models.User{ + Owner: &user_model.User{ LowerName: "user2", }, } @@ -226,9 +227,9 @@ func TestAddTeamPost(t *testing.T) { ctx.Req.Form.Set("team", "team11") - org := &models.User{ + org := &user_model.User{ LowerName: "org26", - Type: models.UserTypeOrganization, + Type: user_model.UserTypeOrganization, } team := &models.Team{ @@ -243,7 +244,7 @@ func TestAddTeamPost(t *testing.T) { } repo := &context.Repository{ - Owner: &models.User{ + Owner: &user_model.User{ ID: 26, LowerName: "org26", RepoAdminChangeTeamAccess: true, @@ -266,9 +267,9 @@ func TestAddTeamPost_NotAllowed(t *testing.T) { ctx.Req.Form.Set("team", "team11") - org := &models.User{ + org := &user_model.User{ LowerName: "org26", - Type: models.UserTypeOrganization, + Type: user_model.UserTypeOrganization, } team := &models.Team{ @@ -283,7 +284,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) { } repo := &context.Repository{ - Owner: &models.User{ + Owner: &user_model.User{ ID: 26, LowerName: "org26", RepoAdminChangeTeamAccess: false, @@ -307,9 +308,9 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) { ctx.Req.Form.Set("team", "team11") - org := &models.User{ + org := &user_model.User{ LowerName: "org26", - Type: models.UserTypeOrganization, + Type: user_model.UserTypeOrganization, } team := &models.Team{ @@ -324,7 +325,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) { } repo := &context.Repository{ - Owner: &models.User{ + Owner: &user_model.User{ ID: 26, LowerName: "org26", RepoAdminChangeTeamAccess: true, @@ -348,9 +349,9 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) { ctx.Req.Form.Set("team", "team-non-existent") - org := &models.User{ + org := &user_model.User{ LowerName: "org26", - Type: models.UserTypeOrganization, + Type: user_model.UserTypeOrganization, } re := &models.Repository{ @@ -360,7 +361,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) { } repo := &context.Repository{ - Owner: &models.User{ + Owner: &user_model.User{ ID: 26, LowerName: "org26", RepoAdminChangeTeamAccess: true, @@ -381,9 +382,9 @@ func TestDeleteTeam(t *testing.T) { ctx.Req.Form.Set("id", "2") - org := &models.User{ + org := &user_model.User{ LowerName: "org3", - Type: models.UserTypeOrganization, + Type: user_model.UserTypeOrganization, } team := &models.Team{ @@ -398,7 +399,7 @@ func TestDeleteTeam(t *testing.T) { } repo := &context.Repository{ - Owner: &models.User{ + Owner: &user_model.User{ ID: 3, LowerName: "org3", RepoAdminChangeTeamAccess: true, diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 1293882cc5..33420aab3b 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -22,6 +22,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" unit_model "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/charset" @@ -449,7 +450,12 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st return } if lfsLock != nil { - ctx.Data["LFSLockOwner"] = lfsLock.Owner.DisplayName() + u, err := user_model.GetUserByID(lfsLock.OwnerID) + if err != nil { + ctx.ServerError("GetTreePathLock", err) + return + } + ctx.Data["LFSLockOwner"] = u.DisplayName() ctx.Data["LFSLockHint"] = ctx.Tr("repo.editor.this_file_locked") } @@ -777,7 +783,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri return nil } ctx.Data["LatestCommitVerification"] = verification - ctx.Data["LatestCommitUser"] = models.ValidateCommitWithEmail(latestCommit) + ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(latestCommit) } statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{}) @@ -893,7 +899,7 @@ func renderCode(ctx *context.Context) { } // RenderUserCards render a page show users according the input template -func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*models.User, error), tpl base.TplName) { +func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) { page := ctx.FormInt("page") if page <= 0 { page = 1 @@ -928,7 +934,7 @@ func Stars(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.stargazers") ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers") ctx.Data["PageIsStargazers"] = true - RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*models.User, error) { + RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*user_model.User, error) { return models.GetStargazers(ctx.Repo.Repository, opts) }, tplWatchers) } diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go index 4f6660926e..28ca3e0de5 100644 --- a/routers/web/repo/webhook.go +++ b/routers/web/repo/webhook.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -1149,7 +1150,7 @@ func TestWebhook(ctx *context.Context) { // Grab latest commit or fake one if it's empty repository. commit := ctx.Repo.Commit if commit == nil { - ghost := models.NewGhostUser() + ghost := user_model.NewGhostUser() commit = &git.Commit{ ID: git.MustIDFromString(git.EmptySHA), Author: ghost.NewGitSig(), diff --git a/routers/web/user/auth.go b/routers/web/user/auth.go index c5164c4956..02f5afd8ba 100644 --- a/routers/web/user/auth.go +++ b/routers/web/user/auth.go @@ -76,9 +76,9 @@ func AutoSignIn(ctx *context.Context) (bool, error) { } }() - u, err := models.GetUserByName(uname) + u, err := user_model.GetUserByName(uname) if err != nil { - if !models.IsErrUserNotExist(err) { + if !user_model.IsErrUserNotExist(err) { return false, fmt.Errorf("GetUserByName: %v", err) } return false, nil @@ -180,17 +180,17 @@ func SignInPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.SignInForm) u, source, err := auth.UserSignIn(form.UserName, form.Password) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form) log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err) } else if user_model.IsErrEmailAlreadyUsed(err) { ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form) log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err) - } else if models.IsErrUserProhibitLogin(err) { + } else if user_model.IsErrUserProhibitLogin(err) { log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err) ctx.Data["Title"] = ctx.Tr("auth.prohibit_login") ctx.HTML(http.StatusOK, "user/auth/prohibit_login") - } else if models.IsErrUserInactive(err) { + } else if user_model.IsErrUserInactive(err) { if setting.Service.RegisterEmailConfirm { ctx.Data["Title"] = ctx.Tr("auth.active_your_account") ctx.HTML(http.StatusOK, TplActivate) @@ -314,7 +314,7 @@ func TwoFactorPost(ctx *context.Context) { if ok && twofa.LastUsedPasscode != form.Passcode { remember := ctx.Session.Get("twofaRemember").(bool) - u, err := models.GetUserByID(id) + u, err := user_model.GetUserByID(id) if err != nil { ctx.ServerError("UserSignIn", err) return @@ -398,7 +398,7 @@ func TwoFactorScratchPost(ctx *context.Context) { } remember := ctx.Session.Get("twofaRemember").(bool) - u, err := models.GetUserByID(id) + u, err := user_model.GetUserByID(id) if err != nil { ctx.ServerError("UserSignIn", err) return @@ -495,7 +495,7 @@ func U2FSign(ctx *context.Context) { newCounter, authErr := r.Authenticate(*signResp, *challenge, reg.Counter) if authErr == nil { reg.Counter = newCounter - user, err := models.GetUserByID(id) + user, err := user_model.GetUserByID(id) if err != nil { ctx.ServerError("UserSignIn", err) return @@ -531,11 +531,11 @@ func U2FSign(ctx *context.Context) { } // This handles the final part of the sign-in process of the user. -func handleSignIn(ctx *context.Context, u *models.User, remember bool) { +func handleSignIn(ctx *context.Context, u *user_model.User, remember bool) { handleSignInFull(ctx, u, remember, true) } -func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyRedirect bool) string { +func handleSignInFull(ctx *context.Context, u *user_model.User, remember bool, obeyRedirect bool) string { if remember { days := 86400 * setting.LogInRememberDays ctx.SetCookie(setting.CookieUserName, u.Name, days) @@ -565,7 +565,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR // If the user does not have a locale set, we save the current one. if len(u.Language) == 0 { u.Language = ctx.Locale.Language() - if err := models.UpdateUserCols(db.DefaultContext, u, "language"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil { log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language)) return setting.AppSubURL + "/" } @@ -582,7 +582,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR // Register last login u.SetLastLogin() - if err := models.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil { ctx.ServerError("UpdateUserCols", err) return setting.AppSubURL + "/" } @@ -680,7 +680,7 @@ func SignInOAuthCallback(ctx *context.Context) { ctx.ServerError("CreateUser", err) return } - u = &models.User{ + u = &user_model.User{ Name: getUserName(&gothUser), FullName: gothUser.Name, Email: gothUser.Email, @@ -725,7 +725,7 @@ func showLinkingLogin(ctx *context.Context, gothUser goth.User) { ctx.Redirect(setting.AppSubURL + "/user/link_account") } -func updateAvatarIfNeed(url string, u *models.User) { +func updateAvatarIfNeed(url string, u *user_model.User) { if setting.OAuth2Client.UpdateAvatar && len(url) > 0 { resp, err := http.Get(url) if err == nil { @@ -743,7 +743,7 @@ func updateAvatarIfNeed(url string, u *models.User) { } } -func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.User, gothUser goth.User) { +func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *user_model.User, gothUser goth.User) { updateAvatarIfNeed(gothUser.AvatarURL, u) needs2FA := false @@ -774,7 +774,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.Us // Register last login u.SetLastLogin() - if err := models.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil { ctx.ServerError("UpdateUserCols", err) return } @@ -817,7 +817,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.Us // OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful // login the user -func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) { +func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, response http.ResponseWriter) (*user_model.User, goth.User, error) { gothUser, err := loginSource.Cfg.(*oauth2.Source).Callback(request, response) if err != nil { if err.Error() == "securecookie: the value is too long" || strings.Contains(err.Error(), "Data too long") { @@ -827,13 +827,13 @@ func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, r return nil, goth.User{}, err } - user := &models.User{ + user := &user_model.User{ LoginName: gothUser.UserID, LoginType: login.OAuth2, LoginSource: loginSource.ID, } - hasUser, err := models.GetUser(user) + hasUser, err := user_model.GetUser(user) if err != nil { return nil, goth.User{}, err } @@ -852,7 +852,7 @@ func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, r return nil, goth.User{}, err } if hasUser { - user, err = models.GetUserByID(externalLoginUser.UserID) + user, err = user_model.GetUserByID(externalLoginUser.UserID) return user, gothUser, err } @@ -893,8 +893,8 @@ func LinkAccount(ctx *context.Context) { ctx.Data["email"] = email if len(email) != 0 { - u, err := models.GetUserByEmail(email) - if err != nil && !models.IsErrUserNotExist(err) { + u, err := user_model.GetUserByEmail(email) + if err != nil && !user_model.IsErrUserNotExist(err) { ctx.ServerError("UserSignIn", err) return } @@ -902,8 +902,8 @@ func LinkAccount(ctx *context.Context) { ctx.Data["user_exists"] = true } } else if len(uname) != 0 { - u, err := models.GetUserByName(uname) - if err != nil && !models.IsErrUserNotExist(err) { + u, err := user_model.GetUserByName(uname) + if err != nil && !user_model.IsErrUserNotExist(err) { ctx.ServerError("UserSignIn", err) return } @@ -948,7 +948,7 @@ func LinkAccountPostSignIn(ctx *context.Context) { u, _, err := auth.UserSignIn(signInForm.UserName, signInForm.Password) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.Data["user_exists"] = true ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm) } else { @@ -960,7 +960,7 @@ func LinkAccountPostSignIn(ctx *context.Context) { linkAccount(ctx, u, gothUser.(goth.User), signInForm.Remember) } -func linkAccount(ctx *context.Context, u *models.User, gothUser goth.User, remember bool) { +func linkAccount(ctx *context.Context, u *user_model.User, gothUser goth.User, remember bool) { updateAvatarIfNeed(gothUser.AvatarURL, u) // If this user is enrolled in 2FA, we can't sign the user in just yet. @@ -1081,7 +1081,7 @@ func LinkAccountPostRegister(ctx *context.Context) { } if setting.Service.AllowOnlyExternalRegistration || !setting.Service.RequireExternalRegistrationPassword { - // In models.User an empty password is classed as not set, so we set form.Password to empty. + // In user_model.User an empty password is classed as not set, so we set form.Password to empty. // Eventually the database should be changed to indicate "Second Factor"-enabled accounts // (accounts that do not introduce the security vulnerabilities of a password). // If a user decides to circumvent second-factor security, and purposefully create a password, @@ -1105,7 +1105,7 @@ func LinkAccountPostRegister(ctx *context.Context) { ctx.ServerError("CreateUser", err) } - u := &models.User{ + u := &user_model.User{ Name: form.UserName, Email: form.Email, Passwd: form.Password, @@ -1249,7 +1249,7 @@ func SignUpPost(ctx *context.Context) { return } - u := &models.User{ + u := &user_model.User{ Name: form.UserName, Email: form.Email, Passwd: form.Password, @@ -1268,7 +1268,7 @@ func SignUpPost(ctx *context.Context) { // createAndHandleCreatedUser calls createUserInContext and // then handleUserCreated. -func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *models.User, gothUser *goth.User, allowLink bool) bool { +func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) bool { if !createUserInContext(ctx, tpl, form, u, gothUser, allowLink) { return false } @@ -1277,16 +1277,16 @@ func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form int // createUserInContext creates a user and handles errors within a given context. // Optionally a template can be specified. -func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *models.User, gothUser *goth.User, allowLink bool) (ok bool) { - if err := models.CreateUser(u); err != nil { - if allowLink && (models.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) { +func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) (ok bool) { + if err := user_model.CreateUser(u); err != nil { + if allowLink && (user_model.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) { if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingAuto { - var user *models.User - user = &models.User{Name: u.Name} - hasUser, err := models.GetUser(user) + var user *user_model.User + user = &user_model.User{Name: u.Name} + hasUser, err := user_model.GetUser(user) if !hasUser || err != nil { - user = &models.User{Email: u.Email} - hasUser, err = models.GetUser(user) + user = &user_model.User{Email: u.Email} + hasUser, err = user_model.GetUser(user) if !hasUser || err != nil { ctx.ServerError("UserLinkAccount", err) return @@ -1310,7 +1310,7 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{ // handle error with template switch { - case models.IsErrUserAlreadyExist(err): + case user_model.IsErrUserAlreadyExist(err): ctx.Data["Err_UserName"] = true ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tpl, form) case user_model.IsErrEmailAlreadyUsed(err): @@ -1319,15 +1319,15 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{ case user_model.IsErrEmailInvalid(err): ctx.Data["Err_Email"] = true ctx.RenderWithErr(ctx.Tr("form.email_invalid"), tpl, form) - case models.IsErrNameReserved(err): + case db.IsErrNameReserved(err): ctx.Data["Err_UserName"] = true - ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form) - case models.IsErrNamePatternNotAllowed(err): + ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form) + case db.IsErrNamePatternNotAllowed(err): ctx.Data["Err_UserName"] = true - ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form) - case models.IsErrNameCharsNotAllowed(err): + ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form) + case db.IsErrNameCharsNotAllowed(err): ctx.Data["Err_UserName"] = true - ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(models.ErrNameCharsNotAllowed).Name), tpl, form) + ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(db.ErrNameCharsNotAllowed).Name), tpl, form) default: ctx.ServerError("CreateUser", err) } @@ -1340,13 +1340,13 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{ // handleUserCreated does additional steps after a new user is created. // It auto-sets admin for the only user, updates the optional external user and // sends a confirmation email if required. -func handleUserCreated(ctx *context.Context, u *models.User, gothUser *goth.User) (ok bool) { +func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.User) (ok bool) { // Auto-set admin for the only user. - if models.CountUsers() == 1 { + if user_model.CountUsers() == 1 { u.IsAdmin = true u.IsActive = true u.SetLastLogin() - if err := models.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_active", "last_login_unix"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_active", "last_login_unix"); err != nil { ctx.ServerError("UpdateUser", err) return } @@ -1406,7 +1406,7 @@ func Activate(ctx *context.Context) { return } - user := models.VerifyUserActiveCode(code) + user := user_model.VerifyUserActiveCode(code) // if code is wrong if user == nil { ctx.Data["IsActivateFailed"] = true @@ -1433,7 +1433,7 @@ func ActivatePost(ctx *context.Context) { return } - user := models.VerifyUserActiveCode(code) + user := user_model.VerifyUserActiveCode(code) // if code is wrong if user == nil { ctx.Data["IsActivateFailed"] = true @@ -1460,15 +1460,15 @@ func ActivatePost(ctx *context.Context) { handleAccountActivation(ctx, user) } -func handleAccountActivation(ctx *context.Context, user *models.User) { +func handleAccountActivation(ctx *context.Context, user *user_model.User) { user.IsActive = true var err error - if user.Rands, err = models.GetUserSalt(); err != nil { + if user.Rands, err = user_model.GetUserSalt(); err != nil { ctx.ServerError("UpdateUser", err) return } - if err := models.UpdateUserCols(db.DefaultContext, user, "is_active", "rands"); err != nil { - if models.IsErrUserNotExist(err) { + if err := user_model.UpdateUserCols(db.DefaultContext, user, "is_active", "rands"); err != nil { + if user_model.IsErrUserNotExist(err) { ctx.NotFound("UpdateUserCols", err) } else { ctx.ServerError("UpdateUser", err) @@ -1512,7 +1512,7 @@ func ActivateEmail(ctx *context.Context) { log.Trace("Email activated: %s", email.Email) ctx.Flash.Success(ctx.Tr("settings.add_email_success")) - if u, err := models.GetUserByID(email.UID); err != nil { + if u, err := user_model.GetUserByID(email.UID); err != nil { log.Warn("GetUserByID: %d", email.UID) } else { // Allow user to validate more emails @@ -1556,9 +1556,9 @@ func ForgotPasswdPost(ctx *context.Context) { email := ctx.FormString("email") ctx.Data["Email"] = email - u, err := models.GetUserByEmail(email) + u, err := user_model.GetUserByEmail(email) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language()) ctx.Data["IsResetSent"] = true ctx.HTML(http.StatusOK, tplForgotPassword) @@ -1592,7 +1592,7 @@ func ForgotPasswdPost(ctx *context.Context) { ctx.HTML(http.StatusOK, tplForgotPassword) } -func commonResetPassword(ctx *context.Context) (*models.User, *login.TwoFactor) { +func commonResetPassword(ctx *context.Context) (*user_model.User, *login.TwoFactor) { code := ctx.FormString("code") ctx.Data["Title"] = ctx.Tr("auth.reset_password") @@ -1608,7 +1608,7 @@ func commonResetPassword(ctx *context.Context) (*models.User, *login.TwoFactor) } // Fail early, don't frustrate the user - u := models.VerifyUserActiveCode(code) + u := user_model.VerifyUserActiveCode(code) if u == nil { ctx.Flash.Error(ctx.Tr("auth.invalid_code")) return nil, nil @@ -1718,7 +1718,7 @@ func ResetPasswdPost(ctx *context.Context) { } } var err error - if u.Rands, err = models.GetUserSalt(); err != nil { + if u.Rands, err = user_model.GetUserSalt(); err != nil { ctx.ServerError("UpdateUser", err) return } @@ -1727,7 +1727,7 @@ func ResetPasswdPost(ctx *context.Context) { return } u.MustChangePassword = false - if err := models.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil { ctx.ServerError("UpdateUser", err) return } @@ -1803,7 +1803,7 @@ func MustChangePasswordPost(ctx *context.Context) { u.MustChangePassword = false - if err := models.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil { ctx.ServerError("UpdateUser", err) return } diff --git a/routers/web/user/auth_openid.go b/routers/web/user/auth_openid.go index 4724a7b431..68e166d12c 100644 --- a/routers/web/user/auth_openid.go +++ b/routers/web/user/auth_openid.go @@ -9,7 +9,6 @@ import ( "net/http" "net/url" - "code.gitea.io/gitea/models" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/auth/openid" "code.gitea.io/gitea/modules/base" @@ -163,9 +162,9 @@ func signInOpenIDVerify(ctx *context.Context) { /* Now we should seek for the user and log him in, or prompt * to register if not found */ - u, err := models.GetUserByOpenID(id) + u, err := user_model.GetUserByOpenID(id) if err != nil { - if !models.IsErrUserNotExist(err) { + if !user_model.IsErrUserNotExist(err) { ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{ Openid: id, }) @@ -203,9 +202,9 @@ func signInOpenIDVerify(ctx *context.Context) { log.Trace("User has email=" + email + " and nickname=" + nickname) if email != "" { - u, err = models.GetUserByEmail(email) + u, err = user_model.GetUserByEmail(email) if err != nil { - if !models.IsErrUserNotExist(err) { + if !user_model.IsErrUserNotExist(err) { ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{ Openid: id, }) @@ -219,9 +218,9 @@ func signInOpenIDVerify(ctx *context.Context) { } if u == nil && nickname != "" { - u, _ = models.GetUserByName(nickname) + u, _ = user_model.GetUserByName(nickname) if err != nil { - if !models.IsErrUserNotExist(err) { + if !user_model.IsErrUserNotExist(err) { ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{ Openid: id, }) @@ -294,7 +293,7 @@ func ConnectOpenIDPost(ctx *context.Context) { u, _, err := auth.UserSignIn(form.UserName, form.Password) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplConnectOID, &form) } else { ctx.ServerError("ConnectOpenIDPost", err) @@ -419,7 +418,7 @@ func RegisterOpenIDPost(ctx *context.Context) { return } - u := &models.User{ + u := &user_model.User{ Name: form.UserName, Email: form.Email, Passwd: password, diff --git a/routers/web/user/avatar.go b/routers/web/user/avatar.go index f39bcc36d3..c8bca9dc2c 100644 --- a/routers/web/user/avatar.go +++ b/routers/web/user/avatar.go @@ -8,8 +8,8 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/avatars" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/httpcache" ) @@ -27,15 +27,15 @@ func AvatarByUserName(ctx *context.Context) { userName := ctx.Params(":username") size := int(ctx.ParamsInt64(":size")) - var user *models.User + var user *user_model.User if strings.ToLower(userName) != "ghost" { var err error - if user, err = models.GetUserByName(userName); err != nil { + if user, err = user_model.GetUserByName(userName); err != nil { ctx.ServerError("Invalid user: "+userName, err) return } } else { - user = models.NewGhostUser() + user = user_model.NewGhostUser() } cacheableRedirect(ctx, user.AvatarLinkWithSize(size)) diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 9efbe755d9..ca2705a42f 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" @@ -43,7 +44,7 @@ const ( ) // getDashboardContextUser finds out which context user dashboard is being viewed as . -func getDashboardContextUser(ctx *context.Context) *models.User { +func getDashboardContextUser(ctx *context.Context) *user_model.User { ctxUser := ctx.User orgName := ctx.Params(":org") if len(orgName) > 0 { @@ -727,7 +728,7 @@ func getRepoIDs(reposQuery string) []int64 { return repoIDs } -func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit.Type) ([]int64, error) { +func getActiveUserRepoIDs(ctxUser *user_model.User, team *models.Team, unitType unit.Type) ([]int64, error) { var userRepoIDs []int64 var err error @@ -737,7 +738,7 @@ func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit return nil, fmt.Errorf("orgRepoIds: %v", err) } } else { - userRepoIDs, err = ctxUser.GetActiveAccessRepoIDs(unitType) + userRepoIDs, err = models.GetActiveAccessRepoIDs(ctxUser, unitType) if err != nil { return nil, fmt.Errorf("ctxUser.GetAccessRepoIDs: %v", err) } @@ -752,7 +753,7 @@ func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit // getActiveTeamOrOrgRepoIds gets RepoIDs for ctxUser as Organization. // Should be called if and only if ctxUser.IsOrganization == true. -func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType unit.Type) ([]int64, error) { +func getActiveTeamOrOrgRepoIds(ctxUser *user_model.User, team *models.Team, unitType unit.Type) ([]int64, error) { var orgRepoIDs []int64 var err error var env models.AccessibleReposEnvironment @@ -777,7 +778,7 @@ func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType return orgRepoIDs, nil } -func issueIDsFromSearch(ctxUser *models.User, keyword string, opts *models.IssuesOptions) ([]int64, error) { +func issueIDsFromSearch(ctxUser *user_model.User, keyword string, opts *models.IssuesOptions) ([]int64, error) { if len(keyword) == 0 { return []int64{}, nil } @@ -794,7 +795,7 @@ func issueIDsFromSearch(ctxUser *models.User, keyword string, opts *models.Issue return issueIDsFromSearch, nil } -func repoIDMap(ctxUser *models.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*models.Repository, error) { +func repoIDMap(ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*models.Repository, error) { repoByID := make(map[int64]*models.Repository, len(issueCountByRepo)) for id := range issueCountByRepo { if id <= 0 { @@ -880,9 +881,9 @@ func ShowGPGKeys(ctx *context.Context, uid int64) { // Email2User show user page via email func Email2User(ctx *context.Context) { - u, err := models.GetUserByEmail(ctx.FormString("email")) + u, err := user_model.GetUserByEmail(ctx.FormString("email")) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { ctx.NotFound("GetUserByEmail", err) } else { ctx.ServerError("GetUserByEmail", err) diff --git a/routers/web/user/oauth.go b/routers/web/user/oauth.go index 7b1854c521..d3baeaedc4 100644 --- a/routers/web/user/oauth.go +++ b/routers/web/user/oauth.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/json" @@ -170,9 +171,9 @@ func newAccessTokenResponse(grant *login.OAuth2Grant, serverKey, clientKey oauth ErrorDescription: "cannot find application", } } - user, err := models.GetUserByID(grant.UserID) + user, err := user_model.GetUserByID(grant.UserID) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { return nil, &AccessTokenError{ ErrorCode: AccessTokenErrorCodeInvalidRequest, ErrorDescription: "cannot find user", @@ -274,7 +275,7 @@ func InfoOAuth(ctx *context.Context) { // returns a list of "org" and "org:team" strings, // that the given user is a part of. -func getOAuthGroupsForUser(user *models.User) ([]string, error) { +func getOAuthGroupsForUser(user *user_model.User) ([]string, error) { orgs, err := models.GetUserOrgsList(user) if err != nil { return nil, fmt.Errorf("GetUserOrgList: %v", err) @@ -359,7 +360,7 @@ func AuthorizeOAuth(ctx *context.Context) { return } - user, err := models.GetUserByID(app.UID) + user, err := user_model.GetUserByID(app.UID) if err != nil { ctx.ServerError("GetUserByID", err) return diff --git a/routers/web/user/oauth_test.go b/routers/web/user/oauth_test.go index dfdaa9a1ed..e26a42b2fc 100644 --- a/routers/web/user/oauth_test.go +++ b/routers/web/user/oauth_test.go @@ -7,9 +7,9 @@ package user import ( "testing" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/services/auth/source/oauth2" "github.com/golang-jwt/jwt" @@ -58,7 +58,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) { assert.Empty(t, oidcToken.Email) assert.False(t, oidcToken.EmailVerified) - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User) grants, err = login.GetOAuth2GrantsByUserID(user.ID) assert.NoError(t, err) assert.Len(t, grants, 1) diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 2594ba3013..32d2bdde83 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -24,10 +24,10 @@ import ( ) // GetUserByName get user by name -func GetUserByName(ctx *context.Context, name string) *models.User { - user, err := models.GetUserByName(name) +func GetUserByName(ctx *context.Context, name string) *user_model.User { + user, err := user_model.GetUserByName(name) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { if redirectUserID, err := user_model.LookupUserRedirect(name); err == nil { context.RedirectToUser(ctx, name, redirectUserID) } else { @@ -42,7 +42,7 @@ func GetUserByName(ctx *context.Context, name string) *models.User { } // GetUserByParams returns user whose name is presented in URL paramenter. -func GetUserByParams(ctx *context.Context) *models.User { +func GetUserByParams(ctx *context.Context) *user_model.User { return GetUserByName(ctx, ctx.Params(":username")) } @@ -199,41 +199,41 @@ func Profile(ctx *context.Context) { repos []*models.Repository count int64 total int - orderBy models.SearchOrderBy + orderBy db.SearchOrderBy ) ctx.Data["SortType"] = ctx.FormString("sort") switch ctx.FormString("sort") { case "newest": - orderBy = models.SearchOrderByNewest + orderBy = db.SearchOrderByNewest case "oldest": - orderBy = models.SearchOrderByOldest + orderBy = db.SearchOrderByOldest case "recentupdate": - orderBy = models.SearchOrderByRecentUpdated + orderBy = db.SearchOrderByRecentUpdated case "leastupdate": - orderBy = models.SearchOrderByLeastUpdated + orderBy = db.SearchOrderByLeastUpdated case "reversealphabetically": - orderBy = models.SearchOrderByAlphabeticallyReverse + orderBy = db.SearchOrderByAlphabeticallyReverse case "alphabetically": - orderBy = models.SearchOrderByAlphabetically + orderBy = db.SearchOrderByAlphabetically case "moststars": - orderBy = models.SearchOrderByStarsReverse + orderBy = db.SearchOrderByStarsReverse case "feweststars": - orderBy = models.SearchOrderByStars + orderBy = db.SearchOrderByStars case "mostforks": - orderBy = models.SearchOrderByForksReverse + orderBy = db.SearchOrderByForksReverse case "fewestforks": - orderBy = models.SearchOrderByForks + orderBy = db.SearchOrderByForks default: ctx.Data["SortType"] = "recentupdate" - orderBy = models.SearchOrderByRecentUpdated + orderBy = db.SearchOrderByRecentUpdated } keyword := ctx.FormTrim("q") ctx.Data["Keyword"] = keyword switch tab { case "followers": - items, err := models.GetUserFollowers(ctxUser, db.ListOptions{ + items, err := user_model.GetUserFollowers(ctxUser, db.ListOptions{ PageSize: setting.UI.User.RepoPagingNum, Page: page, }) @@ -245,7 +245,7 @@ func Profile(ctx *context.Context) { total = ctxUser.NumFollowers case "following": - items, err := models.GetUserFollowing(ctxUser, db.ListOptions{ + items, err := user_model.GetUserFollowing(ctxUser, db.ListOptions{ PageSize: setting.UI.User.RepoPagingNum, Page: page, }) diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go index 603786697a..3b51fdb777 100644 --- a/routers/web/user/setting/account.go +++ b/routers/web/user/setting/account.go @@ -75,7 +75,7 @@ func AccountPost(ctx *context.Context) { ctx.ServerError("UpdateUser", err) return } - if err := models.UpdateUserCols(db.DefaultContext, ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil { ctx.ServerError("UpdateUser", err) return } @@ -152,14 +152,14 @@ func EmailPost(ctx *context.Context) { // Set Email Notification Preference if ctx.FormString("_method") == "NOTIFICATION" { preference := ctx.FormString("preference") - if !(preference == models.EmailNotificationsEnabled || - preference == models.EmailNotificationsOnMention || - preference == models.EmailNotificationsDisabled) { + if !(preference == user_model.EmailNotificationsEnabled || + preference == user_model.EmailNotificationsOnMention || + preference == user_model.EmailNotificationsDisabled) { log.Error("Email notifications preference change returned unrecognized option %s: %s", preference, ctx.User.Name) ctx.ServerError("SetEmailPreference", errors.New("option unrecognized")) return } - if err := models.SetEmailNotifications(ctx.User, preference); err != nil { + if err := user_model.SetEmailNotifications(ctx.User, preference); err != nil { log.Error("Set Email Notifications failed: %v", err) ctx.ServerError("SetEmailNotifications", err) return @@ -233,7 +233,7 @@ func DeleteAccount(ctx *context.Context) { ctx.Data["PageIsSettingsAccount"] = true if _, _, err := auth.UserSignIn(ctx.User.Name, ctx.FormString("password")); err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { loadAccountData(ctx) ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsAccount, nil) diff --git a/routers/web/user/setting/adopt.go b/routers/web/user/setting/adopt.go index 948cc1e936..56ab6ec999 100644 --- a/routers/web/user/setting/adopt.go +++ b/routers/web/user/setting/adopt.go @@ -8,6 +8,7 @@ import ( "path/filepath" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -27,7 +28,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) { action := ctx.FormString("action") ctxUser := ctx.User - root := models.UserPath(ctxUser.LowerName) + root := user_model.UserPath(ctxUser.LowerName) // check not a repo has, err := models.IsRepositoryExist(ctxUser, dir) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 1e515f2fd3..0475398a9a 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -49,7 +49,7 @@ func Profile(ctx *context.Context) { } // HandleUsernameChange handle username changes from user settings and admin interface -func HandleUsernameChange(ctx *context.Context, user *models.User, newName string) error { +func HandleUsernameChange(ctx *context.Context, user *user_model.User, newName string) error { // Non-local users are not allowed to change their username. if !user.IsLocal() { ctx.Flash.Error(ctx.Tr("form.username_change_not_local_user")) @@ -58,17 +58,17 @@ func HandleUsernameChange(ctx *context.Context, user *models.User, newName strin // Check if user name has been changed if user.LowerName != strings.ToLower(newName) { - if err := models.ChangeUserName(user, newName); err != nil { + if err := user_model.ChangeUserName(user, newName); err != nil { switch { - case models.IsErrUserAlreadyExist(err): + case user_model.IsErrUserAlreadyExist(err): ctx.Flash.Error(ctx.Tr("form.username_been_taken")) case user_model.IsErrEmailAlreadyUsed(err): ctx.Flash.Error(ctx.Tr("form.email_been_used")) - case models.IsErrNameReserved(err): + case db.IsErrNameReserved(err): ctx.Flash.Error(ctx.Tr("user.form.name_reserved", newName)) - case models.IsErrNamePatternNotAllowed(err): + case db.IsErrNamePatternNotAllowed(err): ctx.Flash.Error(ctx.Tr("user.form.name_pattern_not_allowed", newName)) - case models.IsErrNameCharsNotAllowed(err): + case db.IsErrNameCharsNotAllowed(err): ctx.Flash.Error(ctx.Tr("user.form.name_chars_not_allowed", newName)) default: ctx.ServerError("ChangeUserName", err) @@ -121,7 +121,7 @@ func ProfilePost(ctx *context.Context) { ctx.User.Description = form.Description ctx.User.KeepActivityPrivate = form.KeepActivityPrivate ctx.User.Visibility = form.Visibility - if err := models.UpdateUserSetting(ctx.User); err != nil { + if err := user_model.UpdateUserSetting(ctx.User); err != nil { if _, ok := err.(user_model.ErrEmailAlreadyUsed); ok { ctx.Flash.Error(ctx.Tr("form.email_been_used")) ctx.Redirect(setting.AppSubURL + "/user/settings") @@ -141,7 +141,7 @@ func ProfilePost(ctx *context.Context) { // UpdateAvatarSetting update user's avatar // FIXME: limit size. -func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *models.User) error { +func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *user_model.User) error { ctxUser.UseCustomAvatar = form.Source == forms.AvatarLocal if len(form.Gravatar) > 0 { if form.Avatar != nil { @@ -178,12 +178,12 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser * } else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" { // No avatar is uploaded but setting has been changed to enable, // generate a random one when needed. - if err := models.GenerateRandomAvatar(ctxUser); err != nil { + if err := user_model.GenerateRandomAvatar(ctxUser); err != nil { log.Error("GenerateRandomAvatar[%d]: %v", ctxUser.ID, err) } } - if err := models.UpdateUserCols(db.DefaultContext, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil { return fmt.Errorf("UpdateUser: %v", err) } @@ -273,7 +273,7 @@ func Repos(ctx *context.Context) { repoNames := make([]string, 0, setting.UI.Admin.UserPagingNum) repos := map[string]*models.Repository{} // We're going to iterate by pagesize. - root := models.UserPath(ctxUser.Name) + root := user_model.UserPath(ctxUser.Name) if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { if os.IsNotExist(err) { @@ -377,7 +377,7 @@ func UpdateUIThemePost(ctx *context.Context) { return } - if err := models.UpdateUserTheme(ctx.User, form.Theme); err != nil { + if err := user_model.UpdateUserTheme(ctx.User, form.Theme); err != nil { ctx.Flash.Error(ctx.Tr("settings.theme_update_error")) ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") return @@ -403,7 +403,7 @@ func UpdateUserLang(ctx *context.Context) { ctx.User.Language = form.Language } - if err := models.UpdateUserSetting(ctx.User); err != nil { + if err := user_model.UpdateUserSetting(ctx.User); err != nil { ctx.ServerError("UpdateUserSetting", err) return } |