summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-24 17:49:20 +0800
committerGitHub <noreply@github.com>2021-11-24 17:49:20 +0800
commita666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch)
tree9ab1434b759a8a2cb275a83149903a823851e309 /cmd
parent4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff)
downloadgitea-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 'cmd')
-rw-r--r--cmd/admin.go21
-rw-r--r--cmd/migrate_storage.go3
2 files changed, 13 insertions, 11 deletions
diff --git a/cmd/admin.go b/cmd/admin.go
index b4fc7f5706..d11b824fa1 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/login"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
@@ -358,7 +359,7 @@ func runChangePassword(c *cli.Context) error {
return errors.New("The password you chose is on a list of stolen passwords previously exposed in public data breaches. Please try again with a different password.\nFor more details, see https://haveibeenpwned.com/Passwords")
}
uname := c.String("username")
- user, err := models.GetUserByName(uname)
+ user, err := user_model.GetUserByName(uname)
if err != nil {
return err
}
@@ -366,7 +367,7 @@ func runChangePassword(c *cli.Context) error {
return err
}
- if err = models.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
+ if err = user_model.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
return err
}
@@ -424,7 +425,7 @@ func runCreateUser(c *cli.Context) error {
// If this is the first user being created.
// Take it as the admin and don't force a password update.
- if n := models.CountUsers(); n == 0 {
+ if n := user_model.CountUsers(); n == 0 {
changePassword = false
}
@@ -432,7 +433,7 @@ func runCreateUser(c *cli.Context) error {
changePassword = c.Bool("must-change-password")
}
- u := &models.User{
+ u := &user_model.User{
Name: username,
Email: c.String("email"),
Passwd: password,
@@ -442,7 +443,7 @@ func runCreateUser(c *cli.Context) error {
Theme: setting.UI.DefaultTheme,
}
- if err := models.CreateUser(u); err != nil {
+ if err := user_model.CreateUser(u); err != nil {
return fmt.Errorf("CreateUser: %v", err)
}
@@ -471,7 +472,7 @@ func runListUsers(c *cli.Context) error {
return err
}
- users, err := models.GetAllUsers()
+ users, err := user_model.GetAllUsers()
if err != nil {
return err
@@ -516,13 +517,13 @@ func runDeleteUser(c *cli.Context) error {
}
var err error
- var user *models.User
+ var user *user_model.User
if c.IsSet("email") {
- user, err = models.GetUserByEmail(c.String("email"))
+ user, err = user_model.GetUserByEmail(c.String("email"))
} else if c.IsSet("username") {
- user, err = models.GetUserByName(c.String("username"))
+ user, err = user_model.GetUserByName(c.String("username"))
} else {
- user, err = models.GetUserByID(c.Int64("id"))
+ user, err = user_model.GetUserByID(c.Int64("id"))
}
if err != nil {
return err
diff --git a/cmd/migrate_storage.go b/cmd/migrate_storage.go
index 9f1d9057f9..afb0fc02a3 100644
--- a/cmd/migrate_storage.go
+++ b/cmd/migrate_storage.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/migrations"
repo_model "code.gitea.io/gitea/models/repo"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
@@ -94,7 +95,7 @@ func migrateLFS(dstStorage storage.ObjectStorage) error {
}
func migrateAvatars(dstStorage storage.ObjectStorage) error {
- return models.IterateUser(func(user *models.User) error {
+ return user_model.IterateUser(func(user *user_model.User) error {
_, err := storage.Copy(dstStorage, user.CustomAvatarRelativePath(), storage.Avatars, user.CustomAvatarRelativePath())
return err
})