From a666829a37be6f9fd98f9e7dd1767c420f7f3b32 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 24 Nov 2021 17:49:20 +0800 Subject: 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 --- models/org_team.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'models/org_team.go') diff --git a/models/org_team.go b/models/org_team.go index 1bdffe2cb1..510a0dcfaa 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -14,6 +14,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/log" "code.gitea.io/gitea/modules/setting" @@ -30,8 +31,8 @@ type Team struct { Name string Description string Authorize AccessMode - Repos []*Repository `xorm:"-"` - Members []*User `xorm:"-"` + Repos []*Repository `xorm:"-"` + Members []*user_model.User `xorm:"-"` NumRepos int NumMembers int Units []*TeamUnit `xorm:"-"` @@ -456,7 +457,7 @@ func (t *Team) unitEnabled(e db.Engine, tp unit.Type) bool { func IsUsableTeamName(name string) error { switch name { case "new": - return ErrNameReserved{name} + return db.ErrNameReserved{Name: name} default: return nil } @@ -473,7 +474,7 @@ func NewTeam(t *Team) (err error) { return err } - has, err := db.GetEngine(db.DefaultContext).ID(t.OrgID).Get(new(User)) + has, err := db.GetEngine(db.DefaultContext).ID(t.OrgID).Get(new(user_model.User)) if err != nil { return err } @@ -760,14 +761,14 @@ func getTeamUsersByTeamID(e db.Engine, teamID int64) ([]*TeamUser, error) { Find(&teamUsers) } -func getTeamMembers(e db.Engine, teamID int64) (_ []*User, err error) { +func getTeamMembers(e db.Engine, teamID int64) (_ []*user_model.User, err error) { teamUsers, err := getTeamUsersByTeamID(e, teamID) if err != nil { return nil, fmt.Errorf("get team-users: %v", err) } - members := make([]*User, len(teamUsers)) + members := make([]*user_model.User, len(teamUsers)) for i, teamUser := range teamUsers { - member, err := getUserByID(e, teamUser.UID) + member, err := user_model.GetUserByIDEngine(e, teamUser.UID) if err != nil { return nil, fmt.Errorf("get user '%d': %v", teamUser.UID, err) } @@ -780,7 +781,7 @@ func getTeamMembers(e db.Engine, teamID int64) (_ []*User, err error) { } // GetTeamMembers returns all members in given team of organization. -func GetTeamMembers(teamID int64) ([]*User, error) { +func GetTeamMembers(teamID int64) ([]*user_model.User, error) { return getTeamMembers(db.GetEngine(db.DefaultContext), teamID) } -- cgit v1.2.3