mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 13:55:42 +03:00
006291bd9c
- 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 commit219073f5c5
) (cherry picked from commit32893dbab1
) (cherry picked from commit0ef40cfb5a
) (cherry picked from commit e535409cab3c276fd8db6b402f85934ef5127491) (cherry picked from commit29059f611b
) (cherry picked from commitcd480c5b8b
) (cherry picked from commit340e657392
) (cherry picked from commit3a7a5564d0
) (cherry picked from commit1dbcaca726
) (cherry picked from commitc491c439e2
) (cherry picked from commitc8fe2140cc
) (cherry picked from commitc72564e3ee
) (cherry picked from commit2084f3fa11
) (cherry picked from commit918e65327d
)
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAdminViewUsers(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
session := loginUser(t, "user1")
|
|
req := NewRequest(t, "GET", "/admin/users")
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
session = loginUser(t, "user2")
|
|
req = NewRequest(t, "GET", "/admin/users")
|
|
session.MakeRequest(t, req, http.StatusForbidden)
|
|
}
|
|
|
|
func TestAdminViewUser(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
session := loginUser(t, "user1")
|
|
req := NewRequest(t, "GET", "/admin/users/1")
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
session = loginUser(t, "user2")
|
|
req = NewRequest(t, "GET", "/admin/users/1")
|
|
session.MakeRequest(t, req, http.StatusForbidden)
|
|
}
|
|
|
|
func TestAdminEditUser(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
testSuccessfullEdit(t, user_model.User{ID: 2, Name: "newusername", LoginName: "otherlogin", Email: "new@e-mail.gitea"})
|
|
}
|
|
|
|
func testSuccessfullEdit(t *testing.T, formData user_model.User) {
|
|
makeRequest(t, formData, http.StatusSeeOther)
|
|
}
|
|
|
|
func makeRequest(t *testing.T, formData user_model.User, headerCode int) {
|
|
session := loginUser(t, "user1")
|
|
csrf := GetCSRF(t, session, "/admin/users/"+strconv.Itoa(int(formData.ID))+"/edit")
|
|
req := NewRequestWithValues(t, "POST", "/admin/users/"+strconv.Itoa(int(formData.ID))+"/edit", map[string]string{
|
|
"_csrf": csrf,
|
|
"user_name": formData.Name,
|
|
"login_name": formData.LoginName,
|
|
"login_type": "0-0",
|
|
"email": formData.Email,
|
|
})
|
|
|
|
session.MakeRequest(t, req, headerCode)
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: formData.ID})
|
|
assert.Equal(t, formData.Name, user.Name)
|
|
assert.Equal(t, formData.LoginName, user.LoginName)
|
|
assert.Equal(t, formData.Email, user.Email)
|
|
}
|
|
|
|
func TestAdminDeleteUser(t *testing.T) {
|
|
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{
|
|
"_csrf": csrf,
|
|
"purge": "true",
|
|
})
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
|
|
|
assertUserDeleted(t, 8, true)
|
|
unittest.CheckConsistencyFor(t, &user_model.User{})
|
|
}
|