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
This commit is contained in:
Lunny Xiao 2021-11-24 17:49:20 +08:00 committed by GitHub
parent 4e7ca946da
commit a666829a37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
345 changed files with 4230 additions and 3813 deletions

View file

@ -9,6 +9,7 @@ import (
"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/setting"
"code.gitea.io/gitea/modules/timeutil"
)
@ -166,18 +167,18 @@ func getRepoWatchersIDs(e db.Engine, repoID int64) ([]int64, error) {
}
// GetWatchers returns range of users watching given repository.
func (repo *Repository) GetWatchers(opts db.ListOptions) ([]*User, error) {
func (repo *Repository) GetWatchers(opts db.ListOptions) ([]*user_model.User, error) {
sess := db.GetEngine(db.DefaultContext).Where("watch.repo_id=?", repo.ID).
Join("LEFT", "watch", "`user`.id=`watch`.user_id").
And("`watch`.mode<>?", RepoWatchModeDont)
if opts.Page > 0 {
sess = db.SetSessionPagination(sess, &opts)
users := make([]*User, 0, opts.PageSize)
users := make([]*user_model.User, 0, opts.PageSize)
return users, sess.Find(&users)
}
users := make([]*User, 0, 8)
users := make([]*user_model.User, 0, 8)
return users, sess.Find(&users)
}
@ -232,7 +233,7 @@ func notifyWatchers(e db.Engine, actions ...*Action) error {
permIssue = make([]bool, len(watchers))
permPR = make([]bool, len(watchers))
for i, watcher := range watchers {
user, err := getUserByID(e, watcher.UserID)
user, err := user_model.GetUserByIDEngine(e, watcher.UserID)
if err != nil {
permCode[i] = false
permIssue[i] = false