mirror of
https://github.com/hanzoai/calendar.git
synced 2026-09-24 22:42:24 +00:00
* lock users on signup if their email is in blacklist * add to turbo env list * prevent locked user or blocked email domain from using API * Refactored to only run 1 query to find the user * Fixing tests * WIP * WIP * WIP * Discard changes to turbo.json * Fixed tests * Update isLockedOrBlocked.test.ts * Update isAdmin.integration-test.ts * Update tsconfig.json * chore: rename to watchlist Signed-off-by: Omar López <[email protected]> --------- Signed-off-by: Omar López <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Keith Williams <[email protected]> Co-authored-by: sean-brydon <[email protected]>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import type { NextApiRequest } from "next";
|
|
|
|
import prisma from "@calcom/prisma";
|
|
import { UserPermissionRole, MembershipRole } from "@calcom/prisma/enums";
|
|
|
|
import { ScopeOfAdmin } from "./scopeOfAdmin";
|
|
|
|
export const isAdminGuard = async (req: NextApiRequest) => {
|
|
const { user, userId } = req;
|
|
if (!user) return { isAdmin: false, scope: null };
|
|
|
|
const { role: userRole } = user;
|
|
if (userRole === UserPermissionRole.ADMIN) return { isAdmin: true, scope: ScopeOfAdmin.SystemWide };
|
|
|
|
const orgOwnerOrAdminMemberships = await prisma.membership.findMany({
|
|
where: {
|
|
userId: userId,
|
|
accepted: true,
|
|
team: {
|
|
isOrganization: true,
|
|
organizationSettings: {
|
|
isAdminAPIEnabled: true,
|
|
},
|
|
},
|
|
OR: [{ role: MembershipRole.OWNER }, { role: MembershipRole.ADMIN }],
|
|
},
|
|
select: {
|
|
team: {
|
|
select: {
|
|
id: true,
|
|
isOrganization: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
if (orgOwnerOrAdminMemberships.length > 0) return { isAdmin: true, scope: ScopeOfAdmin.OrgOwnerOrAdmin };
|
|
|
|
return { isAdmin: false, scope: null };
|
|
};
|