From baed01f24753afb600a2984dcb9bcda0bb8502b6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 22 Nov 2021 23:21:55 +0800 Subject: Remove unnecessary attributes of User struct (#17745) * Remove unnecessary functions of User struct * Move more database methods out of user struct * Move more database methods out of user struct * Fix template failure * Fix bug * Remove finished FIXME * remove unnecessary code --- models/access.go | 60 -------------------------------------------------------- 1 file changed, 60 deletions(-) (limited to 'models/access.go') diff --git a/models/access.go b/models/access.go index 500bcc1e19..7af88e1b4a 100644 --- a/models/access.go +++ b/models/access.go @@ -105,66 +105,6 @@ func accessLevel(e db.Engine, user *User, repo *Repository) (AccessMode, error) return a.Mode, nil } -type repoAccess struct { - Access `xorm:"extends"` - Repository `xorm:"extends"` -} - -func (repoAccess) TableName() string { - return "access" -} - -// GetRepositoryAccesses finds all repositories with their access mode where a user has access but does not own. -func (user *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) { - rows, err := db.GetEngine(db.DefaultContext). - Join("INNER", "repository", "repository.id = access.repo_id"). - Where("access.user_id = ?", user.ID). - And("repository.owner_id <> ?", user.ID). - Rows(new(repoAccess)) - if err != nil { - return nil, err - } - defer rows.Close() - - repos := make(map[*Repository]AccessMode, 10) - ownerCache := make(map[int64]*User, 10) - for rows.Next() { - var repo repoAccess - err = rows.Scan(&repo) - if err != nil { - return nil, err - } - - var ok bool - if repo.Owner, ok = ownerCache[repo.OwnerID]; !ok { - if err = repo.GetOwner(); err != nil { - return nil, err - } - ownerCache[repo.OwnerID] = repo.Owner - } - - repos[&repo.Repository] = repo.Access.Mode - } - return repos, nil -} - -// GetAccessibleRepositories finds repositories which the user has access but does not own. -// If limit is smaller than 1 means returns all found results. -func (user *User) GetAccessibleRepositories(limit int) (repos []*Repository, _ error) { - sess := db.GetEngine(db.DefaultContext). - Where("owner_id !=? ", user.ID). - Desc("updated_unix") - if limit > 0 { - sess.Limit(limit) - repos = make([]*Repository, 0, limit) - } else { - repos = make([]*Repository, 0, 10) - } - return repos, sess. - Join("INNER", "access", "access.user_id = ? AND access.repo_id = repository.id", user.ID). - Find(&repos) -} - func maxAccessMode(modes ...AccessMode) AccessMode { max := AccessModeNone for _, mode := range modes { -- cgit v1.2.3