|
|
@ -460,21 +460,21 @@ func removeOrgUser(sess *xorm.Session, orgID, userID int64) error { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
org, err := GetUserByID(orgID) |
|
|
|
org, err := getUserByID(sess, orgID) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("GetUserByID [%d]: %v", orgID, err) |
|
|
|
return fmt.Errorf("GetUserByID [%d]: %v", orgID, err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if the user to delete is the last member in owner team.
|
|
|
|
// 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 |
|
|
|
return err |
|
|
|
} else if isOwner { |
|
|
|
} else if isOwner { |
|
|
|
t, err := org.GetOwnerTeam() |
|
|
|
t, err := org.getOwnerTeam(sess) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if t.NumMembers == 1 { |
|
|
|
if t.NumMembers == 1 { |
|
|
|
if err := t.GetMembers(); err != nil { |
|
|
|
if err := t.getMembers(sess); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if t.Members[0].ID == userID { |
|
|
|
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.
|
|
|
|
// Delete all repository accesses and unwatch them.
|
|
|
|
env, err := org.AccessibleReposEnv(userID) |
|
|
|
env, err := org.accessibleReposEnv(sess, userID) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("AccessibleReposEnv: %v", err) |
|
|
|
return fmt.Errorf("AccessibleReposEnv: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -618,16 +618,26 @@ type accessibleReposEnv struct { |
|
|
|
org *User |
|
|
|
org *User |
|
|
|
userID int64 |
|
|
|
userID int64 |
|
|
|
teamIDs []int64 |
|
|
|
teamIDs []int64 |
|
|
|
|
|
|
|
e Engine |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// AccessibleReposEnv an AccessibleReposEnvironment for the repositories in `org`
|
|
|
|
// AccessibleReposEnv an AccessibleReposEnvironment for the repositories in `org`
|
|
|
|
// that are accessible to the specified user.
|
|
|
|
// that are accessible to the specified user.
|
|
|
|
func (org *User) AccessibleReposEnv(userID int64) (AccessibleReposEnvironment, error) { |
|
|
|
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 { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
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 { |
|
|
|
func (env *accessibleReposEnv) cond() builder.Cond { |
|
|
@ -642,7 +652,7 @@ func (env *accessibleReposEnv) cond() builder.Cond { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (env *accessibleReposEnv) CountRepos() (int64, error) { |
|
|
|
func (env *accessibleReposEnv) CountRepos() (int64, error) { |
|
|
|
repoCount, err := x. |
|
|
|
repoCount, err := env.e. |
|
|
|
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id"). |
|
|
|
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id"). |
|
|
|
Where(env.cond()). |
|
|
|
Where(env.cond()). |
|
|
|
Distinct("`repository`.id"). |
|
|
|
Distinct("`repository`.id"). |
|
|
@ -659,7 +669,7 @@ func (env *accessibleReposEnv) RepoIDs(page, pageSize int) ([]int64, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
repoIDs := make([]int64, 0, pageSize) |
|
|
|
repoIDs := make([]int64, 0, pageSize) |
|
|
|
return repoIDs, x. |
|
|
|
return repoIDs, env.e. |
|
|
|
Table("repository"). |
|
|
|
Table("repository"). |
|
|
|
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id"). |
|
|
|
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id"). |
|
|
|
Where(env.cond()). |
|
|
|
Where(env.cond()). |
|
|
@ -681,14 +691,14 @@ func (env *accessibleReposEnv) Repos(page, pageSize int) ([]*Repository, error) |
|
|
|
return repos, nil |
|
|
|
return repos, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return repos, x. |
|
|
|
return repos, env.e. |
|
|
|
In("`repository`.id", repoIDs). |
|
|
|
In("`repository`.id", repoIDs). |
|
|
|
Find(&repos) |
|
|
|
Find(&repos) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) { |
|
|
|
func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) { |
|
|
|
repoIDs := make([]int64, 0, 10) |
|
|
|
repoIDs := make([]int64, 0, 10) |
|
|
|
return repoIDs, x. |
|
|
|
return repoIDs, env.e. |
|
|
|
Table("repository"). |
|
|
|
Table("repository"). |
|
|
|
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?", true). |
|
|
|
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?", true). |
|
|
|
Where(env.cond()). |
|
|
|
Where(env.cond()). |
|
|
@ -709,7 +719,7 @@ func (env *accessibleReposEnv) MirrorRepos() ([]*Repository, error) { |
|
|
|
return repos, nil |
|
|
|
return repos, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return repos, x. |
|
|
|
return repos, env.e. |
|
|
|
In("`repository`.id", repoIDs). |
|
|
|
In("`repository`.id", repoIDs). |
|
|
|
Find(&repos) |
|
|
|
Find(&repos) |
|
|
|
} |
|
|
|
} |
|
|
|