mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-26 06:46:40 +00:00
show owner in users table, list roles query in invite form, and more
This commit is contained in:
@@ -199,12 +199,12 @@ authenticated.delete(
|
||||
// verifyUserHasAction(ActionsEnum.createRole),
|
||||
// role.createRole
|
||||
// );
|
||||
// authenticated.get(
|
||||
// "/org/:orgId/roles",
|
||||
// verifyOrgAccess,
|
||||
// verifyUserHasAction(ActionsEnum.listRoles),
|
||||
// role.listRoles
|
||||
// );
|
||||
authenticated.get(
|
||||
"/org/:orgId/roles",
|
||||
verifyOrgAccess,
|
||||
verifyUserHasAction(ActionsEnum.listRoles),
|
||||
role.listRoles
|
||||
);
|
||||
// authenticated.get(
|
||||
// "/role/:roleId",
|
||||
// verifyRoleAccess,
|
||||
|
||||
@@ -99,6 +99,7 @@ export async function createOrg(
|
||||
userId: req.user!.userId,
|
||||
orgId: newOrg[0].orgId,
|
||||
roleId: roleId,
|
||||
isOwner: true,
|
||||
})
|
||||
.execute();
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import createHttpError from "http-errors";
|
||||
import { sql, eq } from "drizzle-orm";
|
||||
import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
import stoi from "@server/utils/stoi";
|
||||
|
||||
const listRolesParamsSchema = z.object({
|
||||
orgId: z.string(),
|
||||
@@ -17,20 +18,43 @@ const listRolesSchema = z.object({
|
||||
limit: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("1000")
|
||||
.transform(Number)
|
||||
.pipe(z.number().int().positive().default(10)),
|
||||
.pipe(z.number().int().nonnegative()),
|
||||
offset: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("0")
|
||||
.transform(Number)
|
||||
.pipe(z.number().int().nonnegative().default(0)),
|
||||
orgId: z
|
||||
.string()
|
||||
.optional()
|
||||
.transform(Number)
|
||||
.pipe(z.number().int().positive()),
|
||||
.pipe(z.number().int().nonnegative()),
|
||||
});
|
||||
|
||||
async function queryRoles(orgId: string, limit: number, offset: number) {
|
||||
return await db
|
||||
.select({
|
||||
roleId: roles.roleId,
|
||||
orgId: roles.orgId,
|
||||
isAdmin: roles.isAdmin,
|
||||
name: roles.name,
|
||||
description: roles.description,
|
||||
orgName: orgs.name,
|
||||
})
|
||||
.from(roles)
|
||||
.leftJoin(orgs, eq(roles.orgId, orgs.orgId))
|
||||
.where(eq(roles.orgId, orgId))
|
||||
.limit(limit)
|
||||
.offset(offset);
|
||||
}
|
||||
|
||||
export type ListRolesResponse = {
|
||||
roles: NonNullable<Awaited<ReturnType<typeof queryRoles>>>;
|
||||
pagination: {
|
||||
total: number;
|
||||
limit: number;
|
||||
offset: number;
|
||||
};
|
||||
};
|
||||
|
||||
export async function listRoles(
|
||||
req: Request,
|
||||
res: Response,
|
||||
@@ -61,25 +85,12 @@ export async function listRoles(
|
||||
|
||||
const { orgId } = parsedParams.data;
|
||||
|
||||
let baseQuery: any = db
|
||||
.select({
|
||||
roleId: roles.roleId,
|
||||
orgId: roles.orgId,
|
||||
isAdmin: roles.isAdmin,
|
||||
name: roles.name,
|
||||
description: roles.description,
|
||||
orgName: orgs.name,
|
||||
})
|
||||
.from(roles)
|
||||
.leftJoin(orgs, eq(roles.orgId, orgs.orgId))
|
||||
.where(eq(roles.orgId, orgId));
|
||||
|
||||
let countQuery: any = db
|
||||
.select({ count: sql<number>`cast(count(*) as integer)` })
|
||||
.from(roles)
|
||||
.where(eq(roles.orgId, orgId));
|
||||
|
||||
const rolesList = await baseQuery.limit(limit).offset(offset);
|
||||
const rolesList = await queryRoles(orgId, limit, offset);
|
||||
const totalCountResult = await countQuery;
|
||||
const totalCount = totalCountResult[0].count;
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ export async function inviteUser(
|
||||
email,
|
||||
inviteLink,
|
||||
expiresInDays: (validHours / 24).toString(),
|
||||
orgName: orgId,
|
||||
orgName: org[0].name || orgId,
|
||||
inviterName: req.user?.email,
|
||||
}),
|
||||
{
|
||||
|
||||
@@ -37,6 +37,7 @@ async function queryUsers(orgId: string, limit: number, offset: number) {
|
||||
orgId: userOrgs.orgId,
|
||||
roleId: userOrgs.roleId,
|
||||
roleName: roles.name,
|
||||
isOwner: userOrgs.isOwner,
|
||||
})
|
||||
.from(users)
|
||||
.leftJoin(userOrgs, sql`${users.userId} = ${userOrgs.userId}`)
|
||||
|
||||
Reference in New Issue
Block a user