Browse Source

Verify list len before use it with IN

pull/3421/head
Thibault Meyer 9 years ago
parent
commit
0158cd2a6c
No known key found for this signature in database
GPG Key ID: C52D76D2CCF24933
  1. 9
      models/org.go

9
models/org.go

@ -369,21 +369,25 @@ func RemoveOrgUser(orgID, userID int64) error {
} }
user, err := GetUserByID(userID) user, err := GetUserByID(userID)
if err != nil { if err != nil {
return fmt.Errorf("GetUserByID [%d]: %v", userID, err) return fmt.Errorf("GetUserByID [%d]: %v", userID, err)
} }
org, err := GetUserByID(orgID) org, err := GetUserByID(orgID)
if err != nil { if err != nil {
return fmt.Errorf("GetUserByID [%d]: %v", orgID, err) return fmt.Errorf("GetUserByID [%d]: %v", orgID, err)
} }
// FIXME: only need to get IDs here, not all fields of repository. // FIXME: only need to get IDs here, not all fields of repository.
repos, _, err := org.GetUserRepositories(user.ID, 1, org.NumRepos) repos, _, err := org.GetUserRepositories(user.ID, 1, org.NumRepos)
if err != nil { if err != nil {
return fmt.Errorf("GetUserRepositories [%d]: %v", user.ID, err) return fmt.Errorf("GetUserRepositories [%d]: %v", user.ID, 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 IsOrganizationOwner(orgID, userID) { if IsOrganizationOwner(orgID, userID) {
t, err := org.GetOwnerTeam() t, err := org.GetOwnerTeam()
if err != nil { if err != nil {
@ -408,21 +412,26 @@ func RemoveOrgUser(orgID, userID int64) error {
// Delete all repository accesses and unwatch them. // Delete all repository accesses and unwatch them.
repoIDs := make([]int64, len(repos)) repoIDs := make([]int64, len(repos))
for i := range repos { for i := range repos {
repoIDs = append(repoIDs, repos[i].ID) repoIDs = append(repoIDs, repos[i].ID)
if err = watchRepo(sess, user.ID, repos[i].ID, false); err != nil { if err = watchRepo(sess, user.ID, repos[i].ID, false); err != nil {
return err return err
} }
} }
if len(repoIDs) > 0 {
if _, err = sess.Where("user_id = ?", user.ID).In("repo_id", repoIDs).Delete(new(Access)); err != nil { if _, err = sess.Where("user_id = ?", user.ID).In("repo_id", repoIDs).Delete(new(Access)); err != nil {
return err return err
} }
}
// Delete member in his/her teams. // Delete member in his/her teams.
teams, err := getUserTeams(sess, org.ID, user.ID) teams, err := getUserTeams(sess, org.ID, user.ID)
if err != nil { if err != nil {
return err return err
} }
for _, t := range teams { for _, t := range teams {
if err = removeTeamMember(sess, org.ID, t.ID, user.ID); err != nil { if err = removeTeamMember(sess, org.ID, t.ID, user.ID); err != nil {
return err return err

Loading…
Cancel
Save