aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository
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 /services/repository
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 'services/repository')
-rw-r--r--services/repository/adopt.go13
-rw-r--r--services/repository/branch.go9
-rw-r--r--services/repository/check.go3
-rw-r--r--services/repository/files/commit.go3
-rw-r--r--services/repository/files/delete.go3
-rw-r--r--services/repository/files/file.go7
-rw-r--r--services/repository/files/temp_repo.go7
-rw-r--r--services/repository/files/update.go5
-rw-r--r--services/repository/files/upload.go9
-rw-r--r--services/repository/fork.go3
-rw-r--r--services/repository/fork_test.go3
-rw-r--r--services/repository/generate.go3
-rw-r--r--services/repository/push.go15
-rw-r--r--services/repository/repository.go7
-rw-r--r--services/repository/transfer.go7
-rw-r--r--services/repository/transfer_test.go15
16 files changed, 66 insertions, 46 deletions
diff --git a/services/repository/adopt.go b/services/repository/adopt.go
index d48411fbb4..3f4045a778 100644
--- a/services/repository/adopt.go
+++ b/services/repository/adopt.go
@@ -13,6 +13,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/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
@@ -24,7 +25,7 @@ import (
)
// AdoptRepository adopts pre-existing repository files for the user/organization.
-func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*models.Repository, error) {
+func AdoptRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) {
if !doer.IsAdmin && !u.CanCreateRepo() {
return nil, models.ErrReachLimitOfRepo{
Limit: u.MaxRepoCreation,
@@ -98,7 +99,7 @@ func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mode
return repo, nil
}
-func adoptRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
+func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
isExist, err := util.IsExist(repoPath)
if err != nil {
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
@@ -185,7 +186,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *models.User, repo
}
// DeleteUnadoptedRepository deletes unadopted repository files from the filesystem
-func DeleteUnadoptedRepository(doer, u *models.User, repoName string) error {
+func DeleteUnadoptedRepository(doer, u *user_model.User, repoName string) error {
if err := models.IsUsableRepoName(repoName); err != nil {
return err
}
@@ -240,7 +241,7 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
repoNamesToCheck := make([]string, 0, opts.PageSize)
repoNames := make([]string, 0, opts.PageSize)
- var ctxUser *models.User
+ var ctxUser *user_model.User
count := 0
@@ -293,9 +294,9 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
return filepath.SkipDir
}
- ctxUser, err = models.GetUserByName(info.Name())
+ ctxUser, err = user_model.GetUserByName(info.Name())
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
log.Debug("Missing user: %s", info.Name())
return filepath.SkipDir
}
diff --git a/services/repository/branch.go b/services/repository/branch.go
index f94a9afcb6..92e662f3d6 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -9,6 +9,7 @@ import (
"fmt"
"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"
"code.gitea.io/gitea/modules/notification"
@@ -17,7 +18,7 @@ import (
)
// CreateNewBranch creates a new repository branch
-func CreateNewBranch(doer *models.User, repo *models.Repository, oldBranchName, branchName string) (err error) {
+func CreateNewBranch(doer *user_model.User, repo *models.Repository, oldBranchName, branchName string) (err error) {
// Check if branch name can be used
if err := checkBranchName(repo, branchName); err != nil {
return err
@@ -99,7 +100,7 @@ func checkBranchName(repo *models.Repository, name string) error {
}
// CreateNewBranchFromCommit creates a new repository branch
-func CreateNewBranchFromCommit(doer *models.User, repo *models.Repository, commit, branchName string) (err error) {
+func CreateNewBranchFromCommit(doer *user_model.User, repo *models.Repository, commit, branchName string) (err error) {
// Check if branch name can be used
if err := checkBranchName(repo, branchName); err != nil {
return err
@@ -120,7 +121,7 @@ func CreateNewBranchFromCommit(doer *models.User, repo *models.Repository, commi
}
// RenameBranch rename a branch
-func RenameBranch(repo *models.Repository, doer *models.User, gitRepo *git.Repository, from, to string) (string, error) {
+func RenameBranch(repo *models.Repository, doer *user_model.User, gitRepo *git.Repository, from, to string) (string, error) {
if from == to {
return "target_exist", nil
}
@@ -164,7 +165,7 @@ var (
)
// DeleteBranch delete branch
-func DeleteBranch(doer *models.User, repo *models.Repository, gitRepo *git.Repository, branchName string) error {
+func DeleteBranch(doer *user_model.User, repo *models.Repository, gitRepo *git.Repository, branchName string) error {
if branchName == repo.DefaultBranch {
return ErrBranchIsDefault
}
diff --git a/services/repository/check.go b/services/repository/check.go
index 36bd4e2e0d..ab7539e555 100644
--- a/services/repository/check.go
+++ b/services/repository/check.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models"
admin_model "code.gitea.io/gitea/models/admin"
"code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
@@ -149,7 +150,7 @@ func gatherMissingRepoRecords(ctx context.Context) ([]*models.Repository, error)
}
// DeleteMissingRepositories deletes all repository records that lost Git files.
-func DeleteMissingRepositories(ctx context.Context, doer *models.User) error {
+func DeleteMissingRepositories(ctx context.Context, doer *user_model.User) error {
repos, err := gatherMissingRepoRecords(ctx)
if err != nil {
return err
diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go
index ebae097112..8f14ed8926 100644
--- a/services/repository/files/commit.go
+++ b/services/repository/files/commit.go
@@ -8,6 +8,7 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/structs"
)
@@ -15,7 +16,7 @@ import (
// CreateCommitStatus creates a new CommitStatus given a bunch of parameters
// NOTE: All text-values will be trimmed from whitespaces.
// Requires: Repo, Creator, SHA
-func CreateCommitStatus(repo *models.Repository, creator *models.User, sha string, status *models.CommitStatus) error {
+func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error {
repoPath := repo.RepoPath()
// confirm that commit is exist
diff --git a/services/repository/files/delete.go b/services/repository/files/delete.go
index f8d7f62c14..f7b342db3f 100644
--- a/services/repository/files/delete.go
+++ b/services/repository/files/delete.go
@@ -9,6 +9,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs"
repo_service "code.gitea.io/gitea/services/repository"
@@ -29,7 +30,7 @@ type DeleteRepoFileOptions struct {
}
// DeleteRepoFile deletes a file in the given repository
-func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepoFileOptions) (*api.FileResponse, error) {
+func DeleteRepoFile(repo *models.Repository, doer *user_model.User, opts *DeleteRepoFileOptions) (*api.FileResponse, error) {
// If no branch name is set, assume the repo's default branch
if opts.OldBranch == "" {
opts.OldBranch = repo.DefaultBranch
diff --git a/services/repository/files/file.go b/services/repository/files/file.go
index ad445bb4ae..8de60c4cb8 100644
--- a/services/repository/files/file.go
+++ b/services/repository/files/file.go
@@ -12,6 +12,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs"
)
@@ -81,7 +82,7 @@ func GetFileCommitResponse(repo *models.Repository, commit *git.Commit) (*api.Fi
}
// GetAuthorAndCommitterUsers Gets the author and committer user objects from the IdentityOptions
-func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *models.User) (authorUser, committerUser *models.User) {
+func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *user_model.User) (authorUser, committerUser *user_model.User) {
// Committer and author are optional. If they are not the doer (not same email address)
// then we use bogus User objects for them to store their FullName and Email.
// If only one of the two are provided, we set both of them to it.
@@ -93,7 +94,7 @@ func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *models
committerUser.FullName = committer.Name
}
} else {
- committerUser = &models.User{
+ committerUser = &user_model.User{
FullName: committer.Name,
Email: committer.Email,
}
@@ -106,7 +107,7 @@ func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *models
authorUser.FullName = author.Name
}
} else {
- authorUser = &models.User{
+ authorUser = &user_model.User{
FullName: author.Name,
Email: author.Email,
}
diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go
index 2a6d6c3ab6..0b6bea6379 100644
--- a/services/repository/files/temp_repo.go
+++ b/services/repository/files/temp_repo.go
@@ -15,6 +15,7 @@ import (
"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"
"code.gitea.io/gitea/modules/setting"
@@ -185,12 +186,12 @@ func (t *TemporaryUploadRepository) GetLastCommitByRef(ref string) (string, erro
}
// CommitTree creates a commit from a given tree for the user with provided message
-func (t *TemporaryUploadRepository) CommitTree(author, committer *models.User, treeHash string, message string, signoff bool) (string, error) {
+func (t *TemporaryUploadRepository) CommitTree(author, committer *user_model.User, treeHash string, message string, signoff bool) (string, error) {
return t.CommitTreeWithDate(author, committer, treeHash, message, signoff, time.Now(), time.Now())
}
// CommitTreeWithDate creates a commit from a given tree for the user with provided message
-func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models.User, treeHash string, message string, signoff bool, authorDate, committerDate time.Time) (string, error) {
+func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *user_model.User, treeHash string, message string, signoff bool, authorDate, committerDate time.Time) (string, error) {
authorSig := author.NewGitSig()
committerSig := committer.NewGitSig()
@@ -260,7 +261,7 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models
}
// Push the provided commitHash to the repository branch by the provided user
-func (t *TemporaryUploadRepository) Push(doer *models.User, commitHash string, branch string) error {
+func (t *TemporaryUploadRepository) Push(doer *user_model.User, commitHash string, branch string) error {
// Because calls hooks we need to pass in the environment
env := models.PushingEnvironment(doer, t.repo)
if err := git.Push(t.basePath, git.PushOptions{
diff --git a/services/repository/files/update.go b/services/repository/files/update.go
index 5d6c3da670..eeb98f3630 100644
--- a/services/repository/files/update.go
+++ b/services/repository/files/update.go
@@ -12,6 +12,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs"
@@ -122,7 +123,7 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string
}
// CreateOrUpdateRepoFile adds or updates a file in the given repository
-func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *UpdateRepoFileOptions) (*structs.FileResponse, error) {
+func CreateOrUpdateRepoFile(repo *models.Repository, doer *user_model.User, opts *UpdateRepoFileOptions) (*structs.FileResponse, error) {
// If no branch name is set, assume default branch
if opts.OldBranch == "" {
opts.OldBranch = repo.DefaultBranch
@@ -439,7 +440,7 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up
}
// VerifyBranchProtection verify the branch protection for modifying the given treePath on the given branch
-func VerifyBranchProtection(repo *models.Repository, doer *models.User, branchName string, treePath string) error {
+func VerifyBranchProtection(repo *models.Repository, doer *user_model.User, branchName string, treePath string) error {
protectedBranch, err := repo.GetBranchProtection(branchName)
if err != nil {
return err
diff --git a/services/repository/files/upload.go b/services/repository/files/upload.go
index 98d01506d5..7a0ea31085 100644
--- a/services/repository/files/upload.go
+++ b/services/repository/files/upload.go
@@ -11,6 +11,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
@@ -47,7 +48,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig
}
// UploadRepoFiles uploads files to the given repository
-func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRepoFileOptions) error {
+func UploadRepoFiles(repo *models.Repository, doer *user_model.User, opts *UploadRepoFileOptions) error {
if len(opts.Files) == 0 {
return nil
}
@@ -67,7 +68,11 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
return err
}
if lfsLock != nil && lfsLock.OwnerID != doer.ID {
- return models.ErrLFSFileLocked{RepoID: repo.ID, Path: filepath, UserName: lfsLock.Owner.Name}
+ u, err := user_model.GetUserByID(lfsLock.OwnerID)
+ if err != nil {
+ return err
+ }
+ return models.ErrLFSFileLocked{RepoID: repo.ID, Path: filepath, UserName: u.Name}
}
names[i] = upload.Name
diff --git a/services/repository/fork.go b/services/repository/fork.go
index f052d18a75..3fc08b4986 100644
--- a/services/repository/fork.go
+++ b/services/repository/fork.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/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
@@ -21,7 +22,7 @@ import (
)
// ForkRepository forks a repository
-func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *models.Repository, err error) {
+func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) (_ *models.Repository, err error) {
forkedRepo, err := opts.BaseRepo.GetUserFork(owner.ID)
if err != nil {
return nil, err
diff --git a/services/repository/fork_test.go b/services/repository/fork_test.go
index 1280a3d84d..befb606135 100644
--- a/services/repository/fork_test.go
+++ b/services/repository/fork_test.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
"github.com/stretchr/testify/assert"
)
@@ -17,7 +18,7 @@ func TestForkRepository(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
// user 13 has already forked repo10
- user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 13}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13}).(*user_model.User)
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
fork, err := ForkRepository(user, user, models.ForkRepoOptions{
diff --git a/services/repository/generate.go b/services/repository/generate.go
index fe38723dea..031648666d 100644
--- a/services/repository/generate.go
+++ b/services/repository/generate.go
@@ -9,13 +9,14 @@ 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/log"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository"
)
// GenerateRepository generates a repository from a template
-func GenerateRepository(doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
+func GenerateRepository(doer, owner *user_model.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
if !doer.IsAdmin && !owner.CanCreateRepo() {
return nil, models.ErrReachLimitOfRepo{
Limit: owner.MaxRepoCreation,
diff --git a/services/repository/push.go b/services/repository/push.go
index 97554c6490..7b439a41f4 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -13,6 +13,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/cache"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
@@ -93,7 +94,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
addTags := make([]string, 0, len(optsList))
delTags := make([]string, 0, len(optsList))
- var pusher *models.User
+ var pusher *user_model.User
for _, opts := range optsList {
if opts.IsNewRef() && opts.IsDelRef() {
@@ -102,7 +103,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
if opts.IsTag() { // If is tag reference
if pusher == nil || pusher.ID != opts.PusherID {
var err error
- if pusher, err = models.GetUserByID(opts.PusherID); err != nil {
+ if pusher, err = user_model.GetUserByID(opts.PusherID); err != nil {
return err
}
}
@@ -133,7 +134,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
} else if opts.IsBranch() { // If is branch reference
if pusher == nil || pusher.ID != opts.PusherID {
var err error
- if pusher, err = models.GetUserByID(opts.PusherID); err != nil {
+ if pusher, err = user_model.GetUserByID(opts.PusherID); err != nil {
return err
}
}
@@ -276,7 +277,7 @@ func pushUpdateAddTags(ctx context.Context, repo *models.Repository, gitRepo *gi
newReleases := make([]*models.Release, 0, len(lowerTags)-len(relMap))
- emailToUser := make(map[string]*models.User)
+ emailToUser := make(map[string]*user_model.User)
for i, lowerTag := range lowerTags {
tag, err := gitRepo.GetTag(tags[i])
@@ -295,15 +296,15 @@ func pushUpdateAddTags(ctx context.Context, repo *models.Repository, gitRepo *gi
if sig == nil {
sig = commit.Committer
}
- var author *models.User
+ var author *user_model.User
var createdAt = time.Unix(1, 0)
if sig != nil {
var ok bool
author, ok = emailToUser[sig.Email]
if !ok {
- author, err = models.GetUserByEmailContext(ctx, sig.Email)
- if err != nil && !models.IsErrUserNotExist(err) {
+ author, err = user_model.GetUserByEmailContext(ctx, sig.Email)
+ if err != nil && !user_model.IsErrUserNotExist(err) {
return fmt.Errorf("GetUserByEmail: %v", err)
}
if author != nil {
diff --git a/services/repository/repository.go b/services/repository/repository.go
index 1d390247f1..4929f9f446 100644
--- a/services/repository/repository.go
+++ b/services/repository/repository.go
@@ -8,6 +8,7 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -16,7 +17,7 @@ import (
)
// CreateRepository creates a repository for the user/organization.
-func CreateRepository(doer, owner *models.User, opts models.CreateRepoOptions) (*models.Repository, error) {
+func CreateRepository(doer, owner *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) {
repo, err := repo_module.CreateRepository(doer, owner, opts)
if err != nil {
// No need to rollback here we should do this in CreateRepository...
@@ -29,7 +30,7 @@ func CreateRepository(doer, owner *models.User, opts models.CreateRepoOptions) (
}
// DeleteRepository deletes a repository for a user or organization.
-func DeleteRepository(doer *models.User, repo *models.Repository) error {
+func DeleteRepository(doer *user_model.User, repo *models.Repository) error {
if err := pull_service.CloseRepoBranchesPulls(doer, repo); err != nil {
log.Error("CloseRepoBranchesPulls failed: %v", err)
}
@@ -42,7 +43,7 @@ func DeleteRepository(doer *models.User, repo *models.Repository) error {
}
// PushCreateRepo creates a repository when a new repository is pushed to an appropriate namespace
-func PushCreateRepo(authUser, owner *models.User, repoName string) (*models.Repository, error) {
+func PushCreateRepo(authUser, owner *user_model.User, repoName string) (*models.Repository, error) {
if !authUser.IsAdmin {
if owner.IsOrganization() {
if ok, err := models.CanCreateOrgRepo(owner.ID, authUser.ID); err != nil {
diff --git a/services/repository/transfer.go b/services/repository/transfer.go
index bb323c1c0a..e6b73fc9e0 100644
--- a/services/repository/transfer.go
+++ b/services/repository/transfer.go
@@ -8,6 +8,7 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/sync"
)
@@ -16,7 +17,7 @@ import (
var repoWorkingPool = sync.NewExclusivePool()
// TransferOwnership transfers all corresponding setting from old user to new one.
-func TransferOwnership(doer, newOwner *models.User, repo *models.Repository, teams []*models.Team) error {
+func TransferOwnership(doer, newOwner *user_model.User, repo *models.Repository, teams []*models.Team) error {
if err := repo.GetOwner(); err != nil {
return err
}
@@ -52,7 +53,7 @@ func TransferOwnership(doer, newOwner *models.User, repo *models.Repository, tea
}
// ChangeRepositoryName changes all corresponding setting from old repository name to new one.
-func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoName string) error {
+func ChangeRepositoryName(doer *user_model.User, repo *models.Repository, newRepoName string) error {
oldRepoName := repo.Name
// Change repository directory name. We must lock the local copy of the
@@ -73,7 +74,7 @@ func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoNam
// StartRepositoryTransfer transfer a repo from one owner to a new one.
// it make repository into pending transfer state, if doer can not create repo for new owner.
-func StartRepositoryTransfer(doer, newOwner *models.User, repo *models.Repository, teams []*models.Team) error {
+func StartRepositoryTransfer(doer, newOwner *user_model.User, repo *models.Repository, teams []*models.Team) error {
if err := models.TestRepositoryReadyForTransfer(repo.Status); err != nil {
return err
}
diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go
index 09c9829216..866e49c866 100644
--- a/services/repository/transfer_test.go
+++ b/services/repository/transfer_test.go
@@ -10,6 +10,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/notification"
"code.gitea.io/gitea/modules/notification/action"
"code.gitea.io/gitea/modules/util"
@@ -30,9 +31,9 @@ func TestTransferOwnership(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
- repo.Owner = unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
assert.NoError(t, TransferOwnership(doer, doer, repo, nil))
transferredRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
@@ -51,16 +52,16 @@ func TestTransferOwnership(t *testing.T) {
Content: "user3/repo3",
})
- unittest.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
+ unittest.CheckConsistencyFor(t, &models.Repository{}, &user_model.User{}, &models.Team{})
}
func TestStartRepositoryTransferSetPermission(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
- recipient := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+ doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
+ recipient := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
- repo.Owner = unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
hasAccess, err := models.HasAccess(recipient.ID, repo)
assert.NoError(t, err)
@@ -72,5 +73,5 @@ func TestStartRepositoryTransferSetPermission(t *testing.T) {
assert.NoError(t, err)
assert.True(t, hasAccess)
- unittest.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
+ unittest.CheckConsistencyFor(t, &models.Repository{}, &user_model.User{}, &models.Team{})
}