|
|
@ -10,6 +10,7 @@ import ( |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/com" |
|
|
|
"github.com/go-xorm/builder" |
|
|
|
"github.com/go-xorm/builder" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
) |
|
|
|
) |
|
|
@ -224,23 +225,63 @@ func DeleteOrganization(org *User) (err error) { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = deleteBeans(sess, |
|
|
|
if err = deleteOrg(sess, org); err != nil { |
|
|
|
&Team{OrgID: org.ID}, |
|
|
|
if IsErrUserOwnRepos(err) { |
|
|
|
&OrgUser{OrgID: org.ID}, |
|
|
|
return err |
|
|
|
&TeamUser{OrgID: org.ID}, |
|
|
|
} else if err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("deleteOrg: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = sess.Commit(); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func deleteOrg(e *xorm.Session, u *User) error { |
|
|
|
|
|
|
|
if !u.IsOrganization() { |
|
|
|
|
|
|
|
return fmt.Errorf("You can't delete none organization user: %s", u.Name) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check ownership of repository.
|
|
|
|
|
|
|
|
count, err := getRepositoryCount(e, u) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("GetRepositoryCount: %v", err) |
|
|
|
|
|
|
|
} else if count > 0 { |
|
|
|
|
|
|
|
return ErrUserOwnRepos{UID: u.ID} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := deleteBeans(e, |
|
|
|
|
|
|
|
&Team{OrgID: u.ID}, |
|
|
|
|
|
|
|
&OrgUser{OrgID: u.ID}, |
|
|
|
|
|
|
|
&TeamUser{OrgID: u.ID}, |
|
|
|
); err != nil { |
|
|
|
); err != nil { |
|
|
|
return fmt.Errorf("deleteBeans: %v", err) |
|
|
|
return fmt.Errorf("deleteBeans: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = deleteUser(sess, org); err != nil { |
|
|
|
if _, err = e.Id(u.ID).Delete(new(User)); err != nil { |
|
|
|
return fmt.Errorf("deleteUser: %v", err) |
|
|
|
return fmt.Errorf("Delete: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = sess.Commit(); err != nil { |
|
|
|
// FIXME: system notice
|
|
|
|
return err |
|
|
|
// Note: There are something just cannot be roll back,
|
|
|
|
|
|
|
|
// so just keep error logs of those operations.
|
|
|
|
|
|
|
|
path := UserPath(u.Name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := os.RemoveAll(path); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("Fail to RemoveAll %s: %v", path, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
avatarPath := u.CustomAvatarPath() |
|
|
|
|
|
|
|
if com.IsExist(avatarPath) { |
|
|
|
|
|
|
|
if err := os.Remove(avatarPath); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("Fail to remove %s: %v", avatarPath, err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return RewriteAllPublicKeys() |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ________ ____ ___
|
|
|
|
// ________ ____ ___
|
|
|
|