diff options
Diffstat (limited to 'models/access.go')
-rw-r--r-- | models/access.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/models/access.go b/models/access.go index 5d0b0b06cf..e230629040 100644 --- a/models/access.go +++ b/models/access.go @@ -8,6 +8,7 @@ package models import ( "fmt" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/log" ) @@ -71,7 +72,11 @@ type Access struct { Mode AccessMode } -func accessLevel(e Engine, user *User, repo *Repository) (AccessMode, error) { +func init() { + db.RegisterModel(new(Access)) +} + +func accessLevel(e db.Engine, user *User, repo *Repository) (AccessMode, error) { mode := AccessModeNone var userID int64 restricted := false @@ -111,7 +116,7 @@ func (repoAccess) TableName() string { // 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 := x. + rows, err := db.DefaultContext().Engine(). Join("INNER", "repository", "repository.id = access.repo_id"). Where("access.user_id = ?", user.ID). And("repository.owner_id <> ?", user.ID). @@ -146,7 +151,7 @@ func (user *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) { // 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 := x. + sess := db.DefaultContext().Engine(). Where("owner_id !=? ", user.ID). Desc("updated_unix") if limit > 0 { @@ -185,7 +190,7 @@ func updateUserAccess(accessMap map[int64]*userAccess, user *User, mode AccessMo } // FIXME: do cross-comparison so reduce deletions and additions to the minimum? -func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]*userAccess) (err error) { +func (repo *Repository) refreshAccesses(e db.Engine, accessMap map[int64]*userAccess) (err error) { minMode := AccessModeRead if !repo.IsPrivate { minMode = AccessModeWrite @@ -219,7 +224,7 @@ func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]*userAcces } // refreshCollaboratorAccesses retrieves repository collaborations with their access modes. -func (repo *Repository) refreshCollaboratorAccesses(e Engine, accessMap map[int64]*userAccess) error { +func (repo *Repository) refreshCollaboratorAccesses(e db.Engine, accessMap map[int64]*userAccess) error { collaborators, err := repo.getCollaborators(e, ListOptions{}) if err != nil { return fmt.Errorf("getCollaborations: %v", err) @@ -233,7 +238,7 @@ func (repo *Repository) refreshCollaboratorAccesses(e Engine, accessMap map[int6 // recalculateTeamAccesses recalculates new accesses for teams of an organization // except the team whose ID is given. It is used to assign a team ID when // remove repository from that team. -func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err error) { +func (repo *Repository) recalculateTeamAccesses(e db.Engine, ignTeamID int64) (err error) { accessMap := make(map[int64]*userAccess, 20) if err = repo.getOwner(e); err != nil { @@ -276,7 +281,7 @@ func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err // recalculateUserAccess recalculates new access for a single user // Usable if we know access only affected one user -func (repo *Repository) recalculateUserAccess(e Engine, uid int64) (err error) { +func (repo *Repository) recalculateUserAccess(e db.Engine, uid int64) (err error) { minMode := AccessModeRead if !repo.IsPrivate { minMode = AccessModeWrite @@ -323,7 +328,7 @@ func (repo *Repository) recalculateUserAccess(e Engine, uid int64) (err error) { return nil } -func (repo *Repository) recalculateAccesses(e Engine) error { +func (repo *Repository) recalculateAccesses(e db.Engine) error { if repo.Owner.IsOrganization() { return repo.recalculateTeamAccesses(e, 0) } @@ -337,5 +342,5 @@ func (repo *Repository) recalculateAccesses(e Engine) error { // RecalculateAccesses recalculates all accesses for repository. func (repo *Repository) RecalculateAccesses() error { - return repo.recalculateAccesses(x) + return repo.recalculateAccesses(db.DefaultContext().Engine()) } |