mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 23:03:34 +01:00
f9653f036c
- Forgejo has the option to delete users, in which all data except issues and comments are removed, this makes sense in some cases where users need to be removed cleanly but without removing their existing bug reports or comments to an discussion. In the case of spammers, admins have the option to enable purging, where comments are removed. - Add issues to the list of things to be removed if purge is checked. - No unit testing, as this gigantic function doesn't have one to begin with. - Add integration test. - Resolves https://codeberg.org/forgejo/forgejo/issues/1268 (cherry picked from commit3ed381c758
) (cherry picked from commit44d00650ce
) (cherry picked from commit7f4da82779
) (cherry picked from commitd629314def
) Conflicts: models/fixtures/issue.yml https://codeberg.org/forgejo/forgejo/pulls/1508 (cherry picked from commit794dcc218f
) (cherry picked from commitc433f2ecb6
) (cherry picked from commitbb23683f4b
) (cherry picked from commit634c5604d4
) (cherry picked from commit492ff6379a
) (cherry picked from commit496b04f8e7
) (cherry picked from commit3c6e5fca84
) (cherry picked from commitb309d0b549
)
63 lines
2.2 KiB
Go
63 lines
2.2 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
|
"code.gitea.io/gitea/models/organization"
|
|
access_model "code.gitea.io/gitea/models/perm/access"
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/tests"
|
|
)
|
|
|
|
func assertUserDeleted(t *testing.T, userID int64, purged bool) {
|
|
unittest.AssertNotExistsBean(t, &user_model.User{ID: userID})
|
|
unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: userID})
|
|
unittest.AssertNotExistsBean(t, &user_model.Follow{FollowID: userID})
|
|
unittest.AssertNotExistsBean(t, &repo_model.Repository{OwnerID: userID})
|
|
unittest.AssertNotExistsBean(t, &access_model.Access{UserID: userID})
|
|
unittest.AssertNotExistsBean(t, &organization.OrgUser{UID: userID})
|
|
unittest.AssertNotExistsBean(t, &issues_model.IssueUser{UID: userID})
|
|
unittest.AssertNotExistsBean(t, &organization.TeamUser{UID: userID})
|
|
unittest.AssertNotExistsBean(t, &repo_model.Star{UID: userID})
|
|
if purged {
|
|
unittest.AssertNotExistsBean(t, &issues_model.Issue{PosterID: userID})
|
|
}
|
|
}
|
|
|
|
func TestUserDeleteAccount(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
session := loginUser(t, "user8")
|
|
csrf := GetCSRF(t, session, "/user/settings/account")
|
|
urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
|
|
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
|
|
"_csrf": csrf,
|
|
})
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
|
|
|
assertUserDeleted(t, 8, false)
|
|
unittest.CheckConsistencyFor(t, &user_model.User{})
|
|
}
|
|
|
|
func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
session := loginUser(t, "user2")
|
|
csrf := GetCSRF(t, session, "/user/settings/account")
|
|
urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
|
|
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
|
|
"_csrf": csrf,
|
|
})
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
|
|
|
// user should not have been deleted, because the user still owns repos
|
|
unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
}
|