mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-17 02:16:38 +00:00
show owner in users table, list roles query in invite form, and more
This commit is contained in:
@@ -37,7 +37,7 @@ export const SendInviteLink = ({
|
||||
<Body className="font-sans">
|
||||
<Container className="bg-white border border-solid border-gray-200 p-6 max-w-lg mx-auto my-8">
|
||||
<Heading className="text-2xl font-semibold text-gray-800 text-center">
|
||||
You're invite to join a Fossorial organization
|
||||
You're invited to join a Fossorial organization
|
||||
</Heading>
|
||||
<Text className="text-base text-gray-700 mt-4">
|
||||
Hi {email || "there"},
|
||||
@@ -45,12 +45,15 @@ export const SendInviteLink = ({
|
||||
<Text className="text-base text-gray-700 mt-2">
|
||||
You’ve been invited to join the organization{" "}
|
||||
{orgName}
|
||||
{inviterName ? ` by ${inviterName}.` : ""}. Please
|
||||
{inviterName ? ` by ${inviterName}.` : "."} Please
|
||||
access the link below to accept the invite.
|
||||
</Text>
|
||||
<Text className="text-base text-gray-700 mt-2">
|
||||
This invite will expire in{" "}
|
||||
<b>{expiresInDays} days.</b>
|
||||
<b>
|
||||
{expiresInDays}{" "}
|
||||
{expiresInDays === "1" ? "day" : "days"}.
|
||||
</b>
|
||||
</Text>
|
||||
<Section className="text-center my-6">
|
||||
<Button
|
||||
|
||||
@@ -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