summaryrefslogtreecommitdiffstats
path: root/models/org.go
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2017-02-04 11:00:07 -0500
committerEthan Koenig <ethantkoenig@gmail.com>2017-02-04 11:01:21 -0500
commitf82ea42679eaa220ab39d1e4d70e2ed4cbaf0fa7 (patch)
treec8f610d2ec7850241462591b8051a02967fc92b5 /models/org.go
parent8a421b1fd702d99e8438f6ef6f4ee339f1eaa130 (diff)
downloadgitea-f82ea42679eaa220ab39d1e4d70e2ed4cbaf0fa7.tar.gz
gitea-f82ea42679eaa220ab39d1e4d70e2ed4cbaf0fa7.zip
Fix bug in removeOrgRepo
Diffstat (limited to 'models/org.go')
-rw-r--r--models/org.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/models/org.go b/models/org.go
index 40f34a4f09..f68c2b9fcb 100644
--- a/models/org.go
+++ b/models/org.go
@@ -526,10 +526,28 @@ func RemoveOrgUser(orgID, userID int64) error {
}
func removeOrgRepo(e Engine, orgID, repoID int64) error {
- _, err := e.Delete(&TeamRepo{
+ teamRepos := make([]*TeamRepo, 0, 10)
+ if err := e.Find(&teamRepos, &TeamRepo{OrgID: orgID, RepoID: repoID}); err != nil {
+ return err
+ }
+
+ if len(teamRepos) == 0 {
+ return nil
+ }
+
+ if _, err := e.Delete(&TeamRepo{
OrgID: orgID,
RepoID: repoID,
- })
+ }); err != nil {
+ return err
+ }
+
+ teamIDs := make([]int64, len(teamRepos))
+ for i, teamRepo := range teamRepos {
+ teamIDs[i] = teamRepo.ID
+ }
+
+ _, err := x.Decr("num_repos").In("id", teamIDs).Update(new(Team))
return err
}