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 /services/migrations | |
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 'services/migrations')
-rw-r--r-- | services/migrations/dump.go | 4 | ||||
-rw-r--r-- | services/migrations/gitea_uploader.go | 7 | ||||
-rw-r--r-- | services/migrations/gitea_uploader_test.go | 3 | ||||
-rw-r--r-- | services/migrations/migrate.go | 5 | ||||
-rw-r--r-- | services/migrations/migrate_test.go | 6 |
5 files changed, 14 insertions, 11 deletions
diff --git a/services/migrations/dump.go b/services/migrations/dump.go index 6e3596230f..afff49a059 100644 --- a/services/migrations/dump.go +++ b/services/migrations/dump.go @@ -17,7 +17,7 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" base "code.gitea.io/gitea/modules/migration" @@ -607,7 +607,7 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) { // RestoreRepository restore a repository from the disk directory func RestoreRepository(ctx context.Context, baseDir string, ownerName, repoName string, units []string) error { - doer, err := models.GetAdminUser() + doer, err := user_model.GetAdminUser() if err != nil { return err } diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index d28c83a64f..3bc8992c3a 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -18,6 +18,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" base "code.gitea.io/gitea/modules/migration" @@ -39,7 +40,7 @@ var ( // GiteaLocalUploader implements an Uploader to gitea sites type GiteaLocalUploader struct { ctx context.Context - doer *models.User + doer *user_model.User repoOwner string repoName string repo *models.Repository @@ -54,7 +55,7 @@ type GiteaLocalUploader struct { } // NewGiteaLocalUploader creates an gitea Uploader via gitea API v1 -func NewGiteaLocalUploader(ctx context.Context, doer *models.User, repoOwner, repoName string) *GiteaLocalUploader { +func NewGiteaLocalUploader(ctx context.Context, doer *user_model.User, repoOwner, repoName string) *GiteaLocalUploader { return &GiteaLocalUploader{ ctx: ctx, doer: doer, @@ -87,7 +88,7 @@ func (g *GiteaLocalUploader) MaxBatchInsertSize(tp string) int { // CreateRepo creates a repository func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.MigrateOptions) error { - owner, err := models.GetUserByName(g.repoOwner) + owner, err := user_model.GetUserByName(g.repoOwner) if err != nil { return err } diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go index 9b04004cd7..45876dd960 100644 --- a/services/migrations/gitea_uploader_test.go +++ b/services/migrations/gitea_uploader_test.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/graceful" base "code.gitea.io/gitea/modules/migration" "code.gitea.io/gitea/modules/structs" @@ -27,7 +28,7 @@ func TestGiteaUploadRepo(t *testing.T) { unittest.PrepareTestEnv(t) - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User) var ( downloader = NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", "", "go-xorm", "builder") diff --git a/services/migrations/migrate.go b/services/migrations/migrate.go index 3e805f0b71..02b167b27c 100644 --- a/services/migrations/migrate.go +++ b/services/migrations/migrate.go @@ -15,6 +15,7 @@ import ( "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/hostmatcher" "code.gitea.io/gitea/modules/log" base "code.gitea.io/gitea/modules/migration" @@ -38,7 +39,7 @@ func RegisterDownloaderFactory(factory base.DownloaderFactory) { } // IsMigrateURLAllowed checks if an URL is allowed to be migrated from -func IsMigrateURLAllowed(remoteURL string, doer *models.User) error { +func IsMigrateURLAllowed(remoteURL string, doer *user_model.User) error { // Remote address can be HTTP/HTTPS/Git URL or local path. u, err := url.Parse(remoteURL) if err != nil { @@ -105,7 +106,7 @@ func IsMigrateURLAllowed(remoteURL string, doer *models.User) error { } // MigrateRepository migrate repository according MigrateOptions -func MigrateRepository(ctx context.Context, doer *models.User, ownerName string, opts base.MigrateOptions, messenger base.Messenger) (*models.Repository, error) { +func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName string, opts base.MigrateOptions, messenger base.Messenger) (*models.Repository, error) { err := IsMigrateURLAllowed(opts.CloneAddr, doer) if err != nil { return nil, err diff --git a/services/migrations/migrate_test.go b/services/migrations/migrate_test.go index e2363242a2..d09c184d91 100644 --- a/services/migrations/migrate_test.go +++ b/services/migrations/migrate_test.go @@ -8,8 +8,8 @@ import ( "path/filepath" "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" "github.com/stretchr/testify/assert" @@ -18,8 +18,8 @@ import ( func TestMigrateWhiteBlocklist(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - adminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User) - nonAdminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User) + adminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user1"}).(*user_model.User) + nonAdminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user2"}).(*user_model.User) setting.Migrations.AllowedDomains = "github.com" setting.Migrations.AllowLocalNetworks = false |