fix #1558
This commit is contained in:
parent
24658fcbdd
commit
aa67de910a
5 changed files with 67 additions and 44 deletions
|
@ -212,7 +212,6 @@ func GetOrganizations(num, offset int) ([]*User, error) {
|
||||||
return orgs, err
|
return orgs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: need some kind of mechanism to record failure.
|
|
||||||
// DeleteOrganization completely and permanently deletes everything of organization.
|
// DeleteOrganization completely and permanently deletes everything of organization.
|
||||||
func DeleteOrganization(org *User) (err error) {
|
func DeleteOrganization(org *User) (err error) {
|
||||||
if err := DeleteUser(org); err != nil {
|
if err := DeleteUser(org); err != nil {
|
||||||
|
@ -220,23 +219,23 @@ func DeleteOrganization(org *User) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
defer sess.Close()
|
defer sessionRelease(sess)
|
||||||
if err = sess.Begin(); err != nil {
|
if err = sess.Begin(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = sess.Delete(&Team{OrgID: org.Id}); err != nil {
|
if err = deleteBeans(sess,
|
||||||
sess.Rollback()
|
&Team{OrgID: org.Id},
|
||||||
return err
|
&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()
|
if err = deleteUser(sess, org); err != nil {
|
||||||
return err
|
return fmt.Errorf("deleteUser: %v", err)
|
||||||
}
|
|
||||||
if _, err = sess.Delete(&TeamUser{OrgID: org.Id}); err != nil {
|
|
||||||
sess.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sess.Commit()
|
return sess.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1190,9 +1190,13 @@ func GetRecentUpdatedRepositories(page int) (repos []*Repository, err error) {
|
||||||
Where("is_private=?", false).Limit(setting.ExplorePagingNum).Desc("updated").Find(&repos)
|
Where("is_private=?", false).Limit(setting.ExplorePagingNum).Desc("updated").Find(&repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getRepositoryCount(e Engine, u *User) (int64, error) {
|
||||||
|
return x.Count(&Repository{OwnerID: u.Id})
|
||||||
|
}
|
||||||
|
|
||||||
// GetRepositoryCount returns the total number of repositories of user.
|
// GetRepositoryCount returns the total number of repositories of user.
|
||||||
func GetRepositoryCount(u *User) (int64, error) {
|
func GetRepositoryCount(u *User) (int64, error) {
|
||||||
return x.Count(&Repository{OwnerID: u.Id})
|
return getRepositoryCount(x, u)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SearchOption struct {
|
type SearchOption struct {
|
||||||
|
|
|
@ -284,9 +284,13 @@ func (u *User) IsPublicMember(orgId int64) bool {
|
||||||
return IsPublicMembership(orgId, u.Id)
|
return IsPublicMembership(orgId, u.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *User) getOrganizationCount(e Engine) (int64, error) {
|
||||||
|
return e.Where("uid=?", u.Id).Count(new(OrgUser))
|
||||||
|
}
|
||||||
|
|
||||||
// GetOrganizationCount returns count of membership of organization of user.
|
// GetOrganizationCount returns count of membership of organization of user.
|
||||||
func (u *User) GetOrganizationCount() (int64, error) {
|
func (u *User) GetOrganizationCount() (int64, error) {
|
||||||
return x.Where("uid=?", u.Id).Count(new(OrgUser))
|
return u.getOrganizationCount(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRepositories returns all repositories that user owns, including private repositories.
|
// GetRepositories returns all repositories that user owns, including private repositories.
|
||||||
|
@ -525,8 +529,8 @@ func UpdateUser(u *User) error {
|
||||||
return updateUser(x, u)
|
return updateUser(x, u)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteBeans deletes all given beans, beans should contain delete conditions.
|
// deleteBeans deletes all given beans, beans should contain delete conditions.
|
||||||
func DeleteBeans(e Engine, beans ...interface{}) (err error) {
|
func deleteBeans(e Engine, beans ...interface{}) (err error) {
|
||||||
for i := range beans {
|
for i := range beans {
|
||||||
if _, err = e.Delete(beans[i]); err != nil {
|
if _, err = e.Delete(beans[i]); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -536,14 +540,12 @@ func DeleteBeans(e Engine, beans ...interface{}) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: need some kind of mechanism to record failure. HINT: system notice
|
// FIXME: need some kind of mechanism to record failure. HINT: system notice
|
||||||
// DeleteUser completely and permanently deletes everything of a user,
|
func deleteUser(e *xorm.Session, u *User) error {
|
||||||
// but issues/comments/pulls will be kept and shown as someone has been deleted.
|
|
||||||
func DeleteUser(u *User) error {
|
|
||||||
// Note: A user owns any repository or belongs to any organization
|
// Note: A user owns any repository or belongs to any organization
|
||||||
// cannot perform delete operation.
|
// cannot perform delete operation.
|
||||||
|
|
||||||
// Check ownership of repository.
|
// Check ownership of repository.
|
||||||
count, err := GetRepositoryCount(u)
|
count, err := getRepositoryCount(e, u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetRepositoryCount: %v", err)
|
return fmt.Errorf("GetRepositoryCount: %v", err)
|
||||||
} else if count > 0 {
|
} else if count > 0 {
|
||||||
|
@ -551,26 +553,20 @@ func DeleteUser(u *User) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check membership of organization.
|
// Check membership of organization.
|
||||||
count, err = u.GetOrganizationCount()
|
count, err = u.getOrganizationCount(e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetOrganizationCount: %v", err)
|
return fmt.Errorf("GetOrganizationCount: %v", err)
|
||||||
} else if count > 0 {
|
} else if count > 0 {
|
||||||
return ErrUserHasOrgs{UID: u.Id}
|
return ErrUserHasOrgs{UID: u.Id}
|
||||||
}
|
}
|
||||||
|
|
||||||
sess := x.NewSession()
|
|
||||||
defer sessionRelease(sess)
|
|
||||||
if err = sess.Begin(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ***** START: Watch *****
|
// ***** START: Watch *****
|
||||||
watches := make([]*Watch, 0, 10)
|
watches := make([]*Watch, 0, 10)
|
||||||
if err = x.Find(&watches, &Watch{UserID: u.Id}); err != nil {
|
if err = e.Find(&watches, &Watch{UserID: u.Id}); err != nil {
|
||||||
return fmt.Errorf("get all watches: %v", err)
|
return fmt.Errorf("get all watches: %v", err)
|
||||||
}
|
}
|
||||||
for i := range watches {
|
for i := range watches {
|
||||||
if _, err = sess.Exec("UPDATE `repository` SET num_watches=num_watches-1 WHERE id=?", watches[i].RepoID); err != nil {
|
if _, err = e.Exec("UPDATE `repository` SET num_watches=num_watches-1 WHERE id=?", watches[i].RepoID); err != nil {
|
||||||
return fmt.Errorf("decrease repository watch number[%d]: %v", watches[i].RepoID, err)
|
return fmt.Errorf("decrease repository watch number[%d]: %v", watches[i].RepoID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -578,11 +574,11 @@ func DeleteUser(u *User) error {
|
||||||
|
|
||||||
// ***** START: Star *****
|
// ***** START: Star *****
|
||||||
stars := make([]*Star, 0, 10)
|
stars := make([]*Star, 0, 10)
|
||||||
if err = x.Find(&stars, &Star{UID: u.Id}); err != nil {
|
if err = e.Find(&stars, &Star{UID: u.Id}); err != nil {
|
||||||
return fmt.Errorf("get all stars: %v", err)
|
return fmt.Errorf("get all stars: %v", err)
|
||||||
}
|
}
|
||||||
for i := range stars {
|
for i := range stars {
|
||||||
if _, err = sess.Exec("UPDATE `repository` SET num_stars=num_stars-1 WHERE id=?", stars[i].RepoID); err != nil {
|
if _, err = e.Exec("UPDATE `repository` SET num_stars=num_stars-1 WHERE id=?", stars[i].RepoID); err != nil {
|
||||||
return fmt.Errorf("decrease repository star number[%d]: %v", stars[i].RepoID, err)
|
return fmt.Errorf("decrease repository star number[%d]: %v", stars[i].RepoID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -590,17 +586,17 @@ func DeleteUser(u *User) error {
|
||||||
|
|
||||||
// ***** START: Follow *****
|
// ***** START: Follow *****
|
||||||
followers := make([]*Follow, 0, 10)
|
followers := make([]*Follow, 0, 10)
|
||||||
if err = x.Find(&followers, &Follow{UserID: u.Id}); err != nil {
|
if err = e.Find(&followers, &Follow{UserID: u.Id}); err != nil {
|
||||||
return fmt.Errorf("get all followers: %v", err)
|
return fmt.Errorf("get all followers: %v", err)
|
||||||
}
|
}
|
||||||
for i := range followers {
|
for i := range followers {
|
||||||
if _, err = sess.Exec("UPDATE `user` SET num_followers=num_followers-1 WHERE id=?", followers[i].UserID); err != nil {
|
if _, err = e.Exec("UPDATE `user` SET num_followers=num_followers-1 WHERE id=?", followers[i].UserID); err != nil {
|
||||||
return fmt.Errorf("decrease user follower number[%d]: %v", followers[i].UserID, err)
|
return fmt.Errorf("decrease user follower number[%d]: %v", followers[i].UserID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ***** END: Follow *****
|
// ***** END: Follow *****
|
||||||
|
|
||||||
if err = DeleteBeans(sess,
|
if err = deleteBeans(e,
|
||||||
&Oauth2{Uid: u.Id},
|
&Oauth2{Uid: u.Id},
|
||||||
&AccessToken{UID: u.Id},
|
&AccessToken{UID: u.Id},
|
||||||
&Collaboration{UserID: u.Id},
|
&Collaboration{UserID: u.Id},
|
||||||
|
@ -612,34 +608,30 @@ func DeleteUser(u *User) error {
|
||||||
&IssueUser{UID: u.Id},
|
&IssueUser{UID: u.Id},
|
||||||
&EmailAddress{Uid: u.Id},
|
&EmailAddress{Uid: u.Id},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return fmt.Errorf("DeleteBeans: %v", err)
|
return fmt.Errorf("deleteUser: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***** START: PublicKey *****
|
// ***** START: PublicKey *****
|
||||||
keys := make([]*PublicKey, 0, 10)
|
keys := make([]*PublicKey, 0, 10)
|
||||||
if err = sess.Find(&keys, &PublicKey{OwnerID: u.Id}); err != nil {
|
if err = e.Find(&keys, &PublicKey{OwnerID: u.Id}); err != nil {
|
||||||
return fmt.Errorf("get all public keys: %v", err)
|
return fmt.Errorf("get all public keys: %v", err)
|
||||||
}
|
}
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if err = deletePublicKey(sess, key.ID); err != nil {
|
if err = deletePublicKey(e, key.ID); err != nil {
|
||||||
return fmt.Errorf("deletePublicKey: %v", err)
|
return fmt.Errorf("deletePublicKey: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ***** END: PublicKey *****
|
// ***** END: PublicKey *****
|
||||||
|
|
||||||
// Clear assignee.
|
// Clear assignee.
|
||||||
if _, err = sess.Exec("UPDATE `issue` SET assignee_id=0 WHERE assignee_id=?", u.Id); err != nil {
|
if _, err = e.Exec("UPDATE `issue` SET assignee_id=0 WHERE assignee_id=?", u.Id); err != nil {
|
||||||
return fmt.Errorf("clear assignee: %v", err)
|
return fmt.Errorf("clear assignee: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = sess.Id(u.Id).Delete(new(User)); err != nil {
|
if _, err = e.Id(u.Id).Delete(new(User)); err != nil {
|
||||||
return fmt.Errorf("Delete: %v", err)
|
return fmt.Errorf("Delete: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = sess.Commit(); err != nil {
|
|
||||||
return fmt.Errorf("Commit: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: system notice
|
// FIXME: system notice
|
||||||
// Note: There are something just cannot be roll back,
|
// Note: There are something just cannot be roll back,
|
||||||
// so just keep error logs of those operations.
|
// so just keep error logs of those operations.
|
||||||
|
@ -651,6 +643,22 @@ func DeleteUser(u *User) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteUser completely and permanently deletes everything of a user,
|
||||||
|
// but issues/comments/pulls will be kept and shown as someone has been deleted.
|
||||||
|
func DeleteUser(u *User) (err error) {
|
||||||
|
sess := x.NewSession()
|
||||||
|
defer sessionRelease(sess)
|
||||||
|
if err = sess.Begin(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = deleteUser(sess, u); err != nil {
|
||||||
|
return fmt.Errorf("deleteUser: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return sess.Commit()
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteInactivateUsers deletes all inactivate users and email addresses.
|
// DeleteInactivateUsers deletes all inactivate users and email addresses.
|
||||||
func DeleteInactivateUsers() (err error) {
|
func DeleteInactivateUsers() (err error) {
|
||||||
users := make([]*User, 0, 10)
|
users := make([]*User, 0, 10)
|
||||||
|
|
|
@ -670,6 +670,17 @@
|
||||||
"outputStyle": 1,
|
"outputStyle": 1,
|
||||||
"syntaxCheckerStyle": 1
|
"syntaxCheckerStyle": 1
|
||||||
},
|
},
|
||||||
|
"\/ng\/js\/min\/gogs-min.js": {
|
||||||
|
"fileType": 64,
|
||||||
|
"ignore": 1,
|
||||||
|
"ignoreWasSetByUser": 0,
|
||||||
|
"inputAbbreviatedPath": "\/ng\/js\/min\/gogs-min.js",
|
||||||
|
"outputAbbreviatedPath": "\/ng\/js\/min\/min\/gogs-min-min.js",
|
||||||
|
"outputPathIsOutsideProject": 0,
|
||||||
|
"outputPathIsSetByUser": 0,
|
||||||
|
"outputStyle": 1,
|
||||||
|
"syntaxCheckerStyle": 1
|
||||||
|
},
|
||||||
"\/ng\/js\/utils\/preview.js": {
|
"\/ng\/js\/utils\/preview.js": {
|
||||||
"fileType": 64,
|
"fileType": 64,
|
||||||
"ignore": 1,
|
"ignore": 1,
|
||||||
|
|
|
@ -198,7 +198,8 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(err.Error(), "Authentication failed") ||
|
if strings.Contains(err.Error(), "Authentication failed") ||
|
||||||
strings.Contains(err.Error(), " not found") {
|
strings.Contains(err.Error(), " not found") ||
|
||||||
|
strings.Contains(err.Error(), "could not read Username") {
|
||||||
ctx.Data["Err_Auth"] = true
|
ctx.Data["Err_Auth"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("form.auth_failed", strings.Replace(err.Error(), ":"+form.AuthPassword+"@", ":<password>@", 1)), MIGRATE, &form)
|
ctx.RenderWithErr(ctx.Tr("form.auth_failed", strings.Replace(err.Error(), ":"+form.AuthPassword+"@", ":<password>@", 1)), MIGRATE, &form)
|
||||||
return
|
return
|
||||||
|
|
Reference in a new issue