From f0e3acadd321fcb99e8ea3e3ce1c69df25c4ca4d Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sun, 1 Oct 2023 18:40:58 +0200 Subject: [PATCH] [MODERATION] Purge issues on user deletion (squash) (cherry picked from commit 4f529d9596ffbfc4e754c28830ba028f6344dc5b) --- models/fixtures/issue.yml | 17 ----- models/fixtures/issue_index.yml | 2 +- models/fixtures/repository.yml | 2 +- tests/integration/admin_user_test.go | 13 +++- .../fixtures/TestAdminDeleteUser/issue.yml | 16 ++++ .../TestAdminDeleteUser/issue_index.yml | 3 + .../TestAdminDeleteUser/repository.yml | 30 ++++++++ .../fixtures/TestAdminDeleteUser/user.yml | 73 +++++++++++++++++++ 8 files changed, 134 insertions(+), 22 deletions(-) create mode 100644 tests/integration/fixtures/TestAdminDeleteUser/issue.yml create mode 100644 tests/integration/fixtures/TestAdminDeleteUser/issue_index.yml create mode 100644 tests/integration/fixtures/TestAdminDeleteUser/repository.yml create mode 100644 tests/integration/fixtures/TestAdminDeleteUser/user.yml diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index da7db94015..0c9b6ff406 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -338,20 +338,3 @@ created_unix: 978307210 updated_unix: 978307210 is_locked: false - -- - id: 21 - repo_id: 10 - index: 2 - poster_id: 8 - original_author_id: 0 - name: issue for pr - content: content - milestone_id: 0 - priority: 0 - is_closed: false - is_pull: false - num_comments: 0 - created_unix: 946684830 - updated_unix: 978307200 - is_locked: false diff --git a/models/fixtures/issue_index.yml b/models/fixtures/issue_index.yml index ceae892d99..de6e955804 100644 --- a/models/fixtures/issue_index.yml +++ b/models/fixtures/issue_index.yml @@ -9,7 +9,7 @@ max_index: 2 - group_id: 10 - max_index: 2 + max_index: 1 - group_id: 32 max_index: 2 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index c74fb716bc..a127b6bdf9 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -283,7 +283,7 @@ num_watches: 0 num_stars: 0 num_forks: 1 - num_issues: 1 + num_issues: 0 num_closed_issues: 0 num_pulls: 1 num_closed_pulls: 0 diff --git a/tests/integration/admin_user_test.go b/tests/integration/admin_user_test.go index 682d632a0f..8cdaac3c72 100644 --- a/tests/integration/admin_user_test.go +++ b/tests/integration/admin_user_test.go @@ -4,10 +4,12 @@ package integration import ( + "fmt" "net/http" "strconv" "testing" + issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/tests" @@ -68,17 +70,22 @@ func makeRequest(t *testing.T, formData user_model.User, headerCode int) { } func TestAdminDeleteUser(t *testing.T) { + defer tests.AddFixtures("tests/integration/fixtures/TestAdminDeleteUser/")() defer tests.PrepareTestEnv(t)() session := loginUser(t, "user1") - csrf := GetCSRF(t, session, "/admin/users/8/edit") - req := NewRequestWithValues(t, "POST", "/admin/users/8/delete", map[string]string{ + userID := int64(1000) + + unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{PosterID: userID}) + + csrf := GetCSRF(t, session, fmt.Sprintf("/admin/users/%d/edit", userID)) + req := NewRequestWithValues(t, "POST", fmt.Sprintf("/admin/users/%d/delete", userID), map[string]string{ "_csrf": csrf, "purge": "true", }) session.MakeRequest(t, req, http.StatusSeeOther) - assertUserDeleted(t, 8, true) + assertUserDeleted(t, userID, true) unittest.CheckConsistencyFor(t, &user_model.User{}) } diff --git a/tests/integration/fixtures/TestAdminDeleteUser/issue.yml b/tests/integration/fixtures/TestAdminDeleteUser/issue.yml new file mode 100644 index 0000000000..02ea88e2d1 --- /dev/null +++ b/tests/integration/fixtures/TestAdminDeleteUser/issue.yml @@ -0,0 +1,16 @@ +- + id: 1000 + repo_id: 1000 + index: 2 + poster_id: 1000 + original_author_id: 0 + name: NAME + content: content + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: false + num_comments: 0 + created_unix: 946684830 + updated_unix: 978307200 + is_locked: false diff --git a/tests/integration/fixtures/TestAdminDeleteUser/issue_index.yml b/tests/integration/fixtures/TestAdminDeleteUser/issue_index.yml new file mode 100644 index 0000000000..88aae4d1db --- /dev/null +++ b/tests/integration/fixtures/TestAdminDeleteUser/issue_index.yml @@ -0,0 +1,3 @@ +- + group_id: 1000 + max_index: 2 diff --git a/tests/integration/fixtures/TestAdminDeleteUser/repository.yml b/tests/integration/fixtures/TestAdminDeleteUser/repository.yml new file mode 100644 index 0000000000..2c12c7e1de --- /dev/null +++ b/tests/integration/fixtures/TestAdminDeleteUser/repository.yml @@ -0,0 +1,30 @@ +- + id: 1000 + owner_id: 1001 + owner_name: user1001 + lower_name: repo1000 + name: repo1000 + default_branch: master + num_watches: 0 + num_stars: 0 + num_forks: 0 + num_issues: 1 + num_closed_issues: 0 + num_pulls: 0 + num_closed_pulls: 0 + num_milestones: 0 + num_closed_milestones: 0 + num_projects: 0 + num_closed_projects: 0 + is_private: false + is_empty: false + is_archived: false + is_mirror: false + status: 0 + is_fork: false + fork_id: 0 + is_template: false + template_id: 0 + size: 0 + is_fsck_enabled: true + close_issues_via_commit_in_any_branch: false diff --git a/tests/integration/fixtures/TestAdminDeleteUser/user.yml b/tests/integration/fixtures/TestAdminDeleteUser/user.yml new file mode 100644 index 0000000000..9b44a859fb --- /dev/null +++ b/tests/integration/fixtures/TestAdminDeleteUser/user.yml @@ -0,0 +1,73 @@ +- + id: 1000 + lower_name: user1000 + name: user1000 + full_name: User Thousand + email: user1000@example.com + keep_email_private: false + email_notifications_preference: enabled + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy + must_change_password: false + login_source: 0 + login_name: user1000 + type: 0 + salt: ZogKvWdyEx + max_repo_creation: -1 + is_active: true + is_admin: false + is_restricted: false + allow_git_hook: false + allow_import_local: false + allow_create_organization: true + prohibit_login: false + avatar: avatar1000 + avatar_email: user1000@example.com + use_custom_avatar: false + num_followers: 1 + num_following: 1 + num_stars: 0 + num_repos: 0 + num_teams: 0 + num_members: 0 + visibility: 0 + repo_admin_change_team_access: false + theme: "" + keep_activity_private: false + +- + id: 1001 + lower_name: user1001 + name: user1001 + full_name: User 1001 + email: user1001@example.com + keep_email_private: false + email_notifications_preference: enabled + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy + must_change_password: false + login_source: 0 + login_name: user1001 + type: 0 + salt: ZogKvWdyEx + max_repo_creation: -1 + is_active: true + is_admin: false + is_restricted: false + allow_git_hook: false + allow_import_local: false + allow_create_organization: true + prohibit_login: false + avatar: avatar1001 + avatar_email: user1001@example.com + use_custom_avatar: false + num_followers: 0 + num_following: 0 + num_stars: 0 + num_repos: 1 + num_teams: 0 + num_members: 0 + visibility: 0 + repo_admin_change_team_access: false + theme: "" + keep_activity_private: false