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/admin | |
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/admin')
-rw-r--r-- | routers/web/admin/orgs.go | 6 | ||||
-rw-r--r-- | routers/web/admin/repos.go | 5 | ||||
-rw-r--r-- | routers/web/admin/users.go | 32 | ||||
-rw-r--r-- | routers/web/admin/users_test.go | 30 |
4 files changed, 37 insertions, 36 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) |