diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2018-10-30 02:10:51 +0800 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2018-10-29 14:10:50 -0400 |
commit | 7022957b153707e81f5d9f864189bb11410f4230 (patch) | |
tree | 1a306af5ec5e74fbac4e9bdc425a21e890b14dd0 /models | |
parent | e7128e8c416924f467620a5e10943eed2888c11e (diff) | |
download | gitea-7022957b153707e81f5d9f864189bb11410f4230.tar.gz gitea-7022957b153707e81f5d9f864189bb11410f4230.zip |
fix sqlite and mssql lock (#5214) (#5218)
Diffstat (limited to 'models')
-rw-r--r-- | models/org.go | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/models/org.go b/models/org.go index 1cc25231e6..0f6bcef7fa 100644 --- a/models/org.go +++ b/models/org.go @@ -460,21 +460,21 @@ func removeOrgUser(sess *xorm.Session, orgID, userID int64) error { return nil } - org, err := GetUserByID(orgID) + org, err := getUserByID(sess, orgID) if err != nil { return fmt.Errorf("GetUserByID [%d]: %v", orgID, err) } // Check if the user to delete is the last member in owner team. - if isOwner, err := IsOrganizationOwner(orgID, userID); err != nil { + if isOwner, err := isOrganizationOwner(sess, orgID, userID); err != nil { return err } else if isOwner { - t, err := org.GetOwnerTeam() + t, err := org.getOwnerTeam(sess) if err != nil { return err } if t.NumMembers == 1 { - if err := t.GetMembers(); err != nil { + if err := t.getMembers(sess); err != nil { return err } if t.Members[0].ID == userID { @@ -490,7 +490,7 @@ func removeOrgUser(sess *xorm.Session, orgID, userID int64) error { } // Delete all repository accesses and unwatch them. - env, err := org.AccessibleReposEnv(userID) + env, err := org.accessibleReposEnv(sess, userID) if err != nil { return fmt.Errorf("AccessibleReposEnv: %v", err) } @@ -618,16 +618,26 @@ type accessibleReposEnv struct { org *User userID int64 teamIDs []int64 + e Engine } // AccessibleReposEnv an AccessibleReposEnvironment for the repositories in `org` // that are accessible to the specified user. func (org *User) AccessibleReposEnv(userID int64) (AccessibleReposEnvironment, error) { - teamIDs, err := org.GetUserTeamIDs(userID) + return org.accessibleReposEnv(x, userID) +} + +func (org *User) accessibleReposEnv(e Engine, userID int64) (AccessibleReposEnvironment, error) { + teamIDs, err := org.getUserTeamIDs(e, userID) if err != nil { return nil, err } - return &accessibleReposEnv{org: org, userID: userID, teamIDs: teamIDs}, nil + return &accessibleReposEnv{ + org: org, + userID: userID, + teamIDs: teamIDs, + e: e, + }, nil } func (env *accessibleReposEnv) cond() builder.Cond { @@ -642,7 +652,7 @@ func (env *accessibleReposEnv) cond() builder.Cond { } func (env *accessibleReposEnv) CountRepos() (int64, error) { - repoCount, err := x. + repoCount, err := env.e. Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id"). Where(env.cond()). Distinct("`repository`.id"). @@ -659,7 +669,7 @@ func (env *accessibleReposEnv) RepoIDs(page, pageSize int) ([]int64, error) { } repoIDs := make([]int64, 0, pageSize) - return repoIDs, x. + return repoIDs, env.e. Table("repository"). Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id"). Where(env.cond()). @@ -681,14 +691,14 @@ func (env *accessibleReposEnv) Repos(page, pageSize int) ([]*Repository, error) return repos, nil } - return repos, x. + return repos, env.e. In("`repository`.id", repoIDs). Find(&repos) } func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) { repoIDs := make([]int64, 0, 10) - return repoIDs, x. + return repoIDs, env.e. Table("repository"). Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?", true). Where(env.cond()). @@ -709,7 +719,7 @@ func (env *accessibleReposEnv) MirrorRepos() ([]*Repository, error) { return repos, nil } - return repos, x. + return repos, env.e. In("`repository`.id", repoIDs). Find(&repos) } |