* 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 <zomars@me.com> --------- Signed-off-by: Omar López <zomars@me.com> Co-authored-by: sean-brydon <sean@cal.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
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 };
|
|
};
|