0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

refactor!: remove hideAdminUser param in user search

This commit is contained in:
Gao Sun 2023-02-11 16:27:30 +08:00
parent 0481a450be
commit 10825ee3ab
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
4 changed files with 5 additions and 23 deletions

View file

@ -35,7 +35,6 @@ const SourceUsersBox = ({ roleId, selectedUsers, onChange }: Props) => {
const url = buildUrl('api/users', {
excludeRoleId: roleId,
hideAdminUser: String(true),
page: String(page),
page_size: String(pageSize),
...conditional(keyword && { search: formatSearchKeyword(keyword) }),

View file

@ -39,7 +39,6 @@ const Users = () => {
});
const url = buildUrl('api/users', {
hideAdminUser: String(true),
page: String(page),
page_size: String(pageSize),
...conditional(keyword && { search: formatSearchKeyword(keyword) }),

View file

@ -1,10 +1,9 @@
import { emailRegEx, passwordRegEx, phoneRegEx, usernameRegEx } from '@logto/core-kit';
import { arbitraryObjectGuard, userInfoSelectFields, UserRole } from '@logto/schemas';
import { arbitraryObjectGuard, userInfoSelectFields } from '@logto/schemas';
import { tryThat } from '@logto/shared';
import { conditional, deduplicate, has, pick } from '@silverhand/essentials';
import { conditional, has, pick } from '@silverhand/essentials';
import { boolean, literal, object, string } from 'zod';
import { isTrue } from '#src/env-set/parameters.js';
import RequestError from '#src/errors/RequestError/index.js';
import { encryptUserPassword } from '#src/libraries/user.js';
import koaGuard from '#src/middleware/koa-guard.js';
@ -43,13 +42,9 @@ export default function adminUserRoutes<T extends AuthedRouter>(
return tryThat(
async () => {
const search = parseSearchParamsForSearch(searchParams);
const hideAdminUser = isTrue(searchParams.get('hideAdminUser'));
const excludeRoleId = searchParams.get('excludeRoleId');
const excludeUsersRoles = excludeRoleId ? await findUsersRolesByRoleId(excludeRoleId) : [];
const excludeUserIdsByRole = excludeUsersRoles.map(({ userId }) => userId);
const adminUsers = hideAdminUser ? await findUsersByRoleName(UserRole.Admin) : [];
const excludeUserIdsByAdmin = adminUsers.map(({ id }) => id);
const excludeUserIds = deduplicate([...excludeUserIdsByRole, ...excludeUserIdsByAdmin]);
const excludeUserIds = excludeUsersRoles.map(({ userId }) => userId);
const [{ count }, users] = await Promise.all([
countUsers(search, excludeUserIds),

View file

@ -90,16 +90,6 @@ describe('admin console user search params', () => {
json.length === 10 && json.every((user) => user.username?.startsWith('search_'))
).toBeTruthy();
});
it('should be able to hide admin users', async () => {
const { headers, json } = await getUsers<User[]>([
['search', '%search_tom%'],
['hideAdminUser', 'true'],
]);
expect(headers['total-number']).toEqual('2');
expect(json.length === 2 && json.every((user) => user.name === 'Tom Scott')).toBeTruthy();
});
});
it('should be able to perform case sensitive exact search', async () => {
@ -145,12 +135,11 @@ describe('admin console user search params', () => {
['search.username', 'search_tom%'],
['mode.username', 'similar_to'],
['isCaseSensitive', 'true'],
['hideAdminUser', 'true'],
]);
expect(headers['total-number']).toEqual('2');
expect(headers['total-number']).toEqual('5');
expect(
json.length === 2 && json.every((user) => user.username?.startsWith('search_'))
json.length === 5 && json.every((user) => user.username?.startsWith('search_'))
).toBeTruthy();
});