From aa67de910af6246a6dc9ad96c56f789e282e8403 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 6 Sep 2015 08:54:08 -0400 Subject: fix #1558 --- models/org.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'models/org.go') diff --git a/models/org.go b/models/org.go index dfd720fade..ac458c78d5 100644 --- a/models/org.go +++ b/models/org.go @@ -212,7 +212,6 @@ func GetOrganizations(num, offset int) ([]*User, error) { return orgs, err } -// TODO: need some kind of mechanism to record failure. // DeleteOrganization completely and permanently deletes everything of organization. func DeleteOrganization(org *User) (err error) { if err := DeleteUser(org); err != nil { @@ -220,23 +219,23 @@ func DeleteOrganization(org *User) (err error) { } sess := x.NewSession() - defer sess.Close() + defer sessionRelease(sess) if err = sess.Begin(); err != nil { return err } - if _, err = sess.Delete(&Team{OrgID: org.Id}); err != nil { - sess.Rollback() - return err + if err = deleteBeans(sess, + &Team{OrgID: org.Id}, + &OrgUser{OrgID: org.Id}, + &TeamUser{OrgID: org.Id}, + ); err != nil { + return fmt.Errorf("deleteBeans: %v", err) } - if _, err = sess.Delete(&OrgUser{OrgID: org.Id}); err != nil { - sess.Rollback() - return err - } - if _, err = sess.Delete(&TeamUser{OrgID: org.Id}); err != nil { - sess.Rollback() - return err + + if err = deleteUser(sess, org); err != nil { + return fmt.Errorf("deleteUser: %v", err) } + return sess.Commit() } -- cgit v1.2.3