mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-11 02:29:09 +00:00
feat: adds pagination in users table
This commit is contained in:
@@ -172,7 +172,10 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
||||
email: true,
|
||||
id: true,
|
||||
superAdmin: true
|
||||
}).array()
|
||||
}).array(),
|
||||
meta: z.object({
|
||||
total: z.number()
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
@@ -186,8 +189,16 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
||||
...req.query
|
||||
});
|
||||
|
||||
const count = await server.services.superAdmin.countUsers({
|
||||
searchTerm: req.query.searchTerm,
|
||||
adminsOnly: req.query.adminsOnly
|
||||
});
|
||||
|
||||
return {
|
||||
users
|
||||
users,
|
||||
meta: {
|
||||
total: count
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -247,7 +258,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
||||
...req.query
|
||||
});
|
||||
const count = await server.services.superAdmin.countOrganizations({
|
||||
...req.query
|
||||
searchTerm: req.query.searchTerm
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -364,7 +375,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
||||
});
|
||||
|
||||
const count = await server.services.superAdmin.countIdentities({
|
||||
...req.query
|
||||
searchTerm: req.query.searchTerm
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -57,6 +57,7 @@ import {
|
||||
TAdminSignUpDTO,
|
||||
TCountIdentitiesDTO,
|
||||
TCountOrganizationsDTO,
|
||||
TCountUsersDTO,
|
||||
TCreateOrganizationDTO,
|
||||
TGetOrganizationsDTO,
|
||||
TResendOrgInviteDTO
|
||||
@@ -670,6 +671,15 @@ export const superAdminServiceFactory = ({
|
||||
});
|
||||
};
|
||||
|
||||
const countUsers = async ({ searchTerm, adminsOnly }: TCountUsersDTO) => {
|
||||
const count = await userDAL.countUsersByFilter({
|
||||
searchTerm,
|
||||
adminsOnly
|
||||
});
|
||||
|
||||
return count;
|
||||
};
|
||||
|
||||
const deleteUser = async (userId: string) => {
|
||||
const superAdmins = await userDAL.find({
|
||||
superAdmin: true
|
||||
@@ -1151,6 +1161,7 @@ export const superAdminServiceFactory = ({
|
||||
adminSignUp,
|
||||
bootstrapInstance,
|
||||
getUsers,
|
||||
countUsers,
|
||||
deleteUser,
|
||||
getIdentities,
|
||||
countIdentities,
|
||||
|
||||
@@ -42,6 +42,11 @@ export type TCountIdentitiesDTO = {
|
||||
searchTerm: string;
|
||||
};
|
||||
|
||||
export type TCountUsersDTO = {
|
||||
searchTerm: string;
|
||||
adminsOnly: boolean;
|
||||
};
|
||||
|
||||
export type TCreateOrganizationDTO = {
|
||||
name: string;
|
||||
inviteAdminEmails: string[];
|
||||
|
||||
@@ -70,6 +70,35 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
}
|
||||
};
|
||||
|
||||
const countUsersByFilter = async ({ searchTerm, adminsOnly }: { searchTerm: string; adminsOnly: boolean }) => {
|
||||
interface CountResult {
|
||||
count: string;
|
||||
}
|
||||
try {
|
||||
const count = await db
|
||||
.replicaNode()(TableName.Users)
|
||||
.where("isGhost", "=", false)
|
||||
.where((qb) => {
|
||||
if (searchTerm) {
|
||||
void qb
|
||||
.whereILike("email", `%${searchTerm}%`)
|
||||
.orWhereILike("firstName", `%${searchTerm}%`)
|
||||
.orWhereILike("lastName", `%${searchTerm}%`)
|
||||
.orWhereRaw('lower("username") like ?', `%${searchTerm}%`);
|
||||
}
|
||||
if (adminsOnly) {
|
||||
void qb.where("superAdmin", true);
|
||||
}
|
||||
})
|
||||
.count("*")
|
||||
.first();
|
||||
|
||||
return parseInt((count as unknown as CountResult).count || "0", 10);
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Count Users by filter" });
|
||||
}
|
||||
};
|
||||
|
||||
// USER ENCRYPTION FUNCTIONS
|
||||
// -------------------------
|
||||
const findUserEncKeyByUsername = async ({ username }: { username: string }) => {
|
||||
@@ -243,6 +272,7 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
findOneUserAction,
|
||||
createUserAction,
|
||||
getUsersByFilter,
|
||||
countUsersByFilter,
|
||||
findAllMyAccounts,
|
||||
findUserByEmail
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user