mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-02 13:44:16 +09:00
fix: list bot users in gitea admin user list and admin users API (#40060)
Fixes https://github.com/go-gitea/gitea/issues/40056 Signed-off-by: Soujas K <kudchadkarsoujas@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
5 files changed
+28
-19
No files matched your search
@@ -22,6 +22,8 @@ import (
|
||||
"gitea.dev/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func TestAPIAdminListPackages(t *testing.T) {
|
||||
@@ -55,20 +57,21 @@ func TestAPIAdminAccessAndSSHKeys(t *testing.T) {
|
||||
t.Run("ListUsers", func(t *testing.T) {
|
||||
adminUsername := "user1"
|
||||
token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeReadAdmin)
|
||||
bot := &user_model.User{Name: "list-bot", Email: "list-bot@example.com", Type: user_model.UserTypeBot}
|
||||
require.NoError(t, user_model.CreateUser(t.Context(), bot, &user_model.Meta{}))
|
||||
|
||||
req := NewRequest(t, "GET", "/api/v1/admin/users").
|
||||
req := NewRequest(t, "GET", "/api/v1/admin/users?limit=50").
|
||||
AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
users := DecodeJSON(t, resp, []api.User{})
|
||||
|
||||
found := false
|
||||
userTypes := map[string]api.UserTypeString{}
|
||||
for _, user := range users {
|
||||
if user.UserName == adminUsername {
|
||||
found = true
|
||||
}
|
||||
userTypes[user.UserName] = user.Type
|
||||
}
|
||||
assert.True(t, found)
|
||||
numberOfUsers := unittest.GetCount(t, &user_model.User{}, "type = 0")
|
||||
assert.Equal(t, api.UserTypeStringUser, userTypes[adminUsername])
|
||||
assert.Equal(t, api.UserTypeStringBot, userTypes[bot.Name])
|
||||
numberOfUsers := unittest.GetCount(t, &user_model.User{}, builder.In("type", user_model.AdminListedUserTypes))
|
||||
assert.Len(t, users, numberOfUsers)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user