Don't allow team admins to give owner permissions (#221)

Throw an error if a user of a team with ADMIN permission tries to change
permission to OWNER (Bug#3)

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
This commit is contained in:
Carina Wollendorfer
2022-12-20 10:45:24 -07:00
committed by GitHub
co-authored by CarinaWolli
parent 12f19ff7c0
commit 161ebacfef
+9 -2
View File
@@ -58,13 +58,20 @@ async function checkPermissions(req: NextApiRequest) {
if (isAdmin) return;
// Only the invited user can accept the invite
if ("accepted" in data && queryUserId !== userId)
throw new HttpError({ statusCode: 403, message: "Only the invited user can accept the invite" });
throw new HttpError({
statusCode: 403,
message: "Only the invited user can accept the invite",
});
// Only team OWNERS and ADMINS can modify `role`
if ("role" in data) {
const membership = await prisma.membership.findFirst({
where: { userId, teamId, role: { in: ["ADMIN", "OWNER"] } },
});
if (!membership) throw new HttpError({ statusCode: 403, message: "Forbidden" });
if (
!membership ||
(membership.role !== "OWNER" && req.body.role === "OWNER")
)
throw new HttpError({ statusCode: 403, message: "Forbidden" });
}
}