aboutsummaryrefslogtreecommitdiffstats
path: root/models/access.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-22 23:21:55 +0800
committerGitHub <noreply@github.com>2021-11-22 23:21:55 +0800
commitbaed01f24753afb600a2984dcb9bcda0bb8502b6 (patch)
tree5621ef980b6b0067a21c86be7e4808d83c0538ab /models/access.go
parentc2ab19888f92fbdec4276a16d224e8de80d1d1dd (diff)
downloadgitea-baed01f24753afb600a2984dcb9bcda0bb8502b6.tar.gz
gitea-baed01f24753afb600a2984dcb9bcda0bb8502b6.zip
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
Diffstat (limited to 'models/access.go')
-rw-r--r--models/access.go60
1 files changed, 0 insertions, 60 deletions
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 {