fix: isAdmin from req, no isAdminGuard everywhere
This commit is contained in:
@@ -3,7 +3,6 @@ import type { NextApiRequest } from "next";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaQueryUserId } from "@lib/validations/shared/queryUserId";
|
||||
|
||||
/**
|
||||
@@ -31,9 +30,8 @@ import { schemaQueryUserId } from "@lib/validations/shared/queryUserId";
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
export async function deleteHandler(req: NextApiRequest) {
|
||||
const { prisma } = req;
|
||||
const { prisma, isAdmin } = req;
|
||||
const query = schemaQueryUserId.parse(req.query);
|
||||
const isAdmin = await isAdminGuard(req);
|
||||
// Here we only check for ownership of the user if the user is not admin, otherwise we let ADMIN's edit any user
|
||||
if (!isAdmin && query.userId !== req.userId)
|
||||
throw new HttpError({ statusCode: 401, message: "Unauthorized" });
|
||||
|
||||
@@ -3,7 +3,6 @@ import type { NextApiRequest } from "next";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaQueryUserId } from "@lib/validations/shared/queryUserId";
|
||||
import { schemaUserReadPublic } from "@lib/validations/user";
|
||||
|
||||
@@ -32,10 +31,9 @@ import { schemaUserReadPublic } from "@lib/validations/user";
|
||||
* description: User was not found
|
||||
*/
|
||||
export async function getHandler(req: NextApiRequest) {
|
||||
const { prisma } = req;
|
||||
const { prisma, isAdmin } = req;
|
||||
|
||||
const query = schemaQueryUserId.parse(req.query);
|
||||
const isAdmin = await isAdminGuard(req);
|
||||
// Here we only check for ownership of the user if the user is not admin, otherwise we let ADMIN's edit any user
|
||||
if (!isAdmin && query.userId !== req.userId)
|
||||
throw new HttpError({ statusCode: 401, message: "Unauthorized" });
|
||||
|
||||
@@ -3,7 +3,6 @@ import type { NextApiRequest } from "next";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaQueryUserId } from "@lib/validations/shared/queryUserId";
|
||||
import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations/user";
|
||||
|
||||
@@ -53,9 +52,8 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
export async function patchHandler(req: NextApiRequest) {
|
||||
const { prisma } = req;
|
||||
const { prisma, isAdmin } = req;
|
||||
const query = schemaQueryUserId.parse(req.query);
|
||||
const isAdmin = await isAdminGuard(req);
|
||||
// Here we only check for ownership of the user if the user is not admin, otherwise we let ADMIN's edit any user
|
||||
if (!isAdmin && query.userId !== req.userId)
|
||||
throw new HttpError({ statusCode: 401, message: "Unauthorized" });
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { NextApiRequest } from "next";
|
||||
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaUsersReadPublic } from "@lib/validations/user";
|
||||
|
||||
import { Prisma } from ".prisma/client";
|
||||
@@ -24,8 +23,7 @@ import { Prisma } from ".prisma/client";
|
||||
* description: No users were found
|
||||
*/
|
||||
async function getHandler(req: NextApiRequest) {
|
||||
const { userId, prisma } = req;
|
||||
const isAdmin = await isAdminGuard(req);
|
||||
const { userId, prisma, isAdmin } = req;
|
||||
const where: Prisma.UserWhereInput = {};
|
||||
// If user is not ADMIN, return only his data.
|
||||
if (!isAdmin) where.id = userId;
|
||||
|
||||
@@ -3,12 +3,10 @@ import type { NextApiRequest } from "next";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaUserCreateBodyParams } from "@lib/validations/user";
|
||||
|
||||
async function postHandler(req: NextApiRequest) {
|
||||
const { prisma } = req;
|
||||
const isAdmin = await isAdminGuard(req);
|
||||
const { prisma, isAdmin } = req;
|
||||
// If user is not ADMIN, return unauthorized.
|
||||
if (!isAdmin) throw new HttpError({ statusCode: 401, message: "You are not authorized" });
|
||||
const data = schemaUserCreateBodyParams.parse(req.body);
|
||||
|
||||
Reference in New Issue
Block a user