Skip to content

Commit

Permalink
fix: Add admin guard to edit resource
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelpernil2 committed Sep 24, 2021
1 parent 1631b40 commit 2ad8212
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions https-graphql-backend/src/graphql/resolvers/ResourceResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ export const ResourceResolvers: Resolvers = {

const client = await (await context.mongoDBConnection).connection;

const hasAdminAccess = await hasAdminAccessInResource(new ObjectId(context?.user?._id ?? "").toHexString() ?? "", id ?? "", db)
if (!hasAdminAccess) {
return { status: OperationResult.Error }
}


let result: UpdateResult = { status: OperationResult.Ok };

// First let's clear out all awaiting confirmation
Expand Down Expand Up @@ -358,7 +364,7 @@ export const ResourceResolvers: Resolvers = {

const hasAdminAccess = await hasAdminAccessInResource(new ObjectId(context?.user?._id ?? "").toHexString() ?? "", resourceId, db)
if (!hasAdminAccess) {
console.log("Does not have admin access", hasAdminAccess, new ObjectId(context?.user?._id ?? ""), resourceId);
// console.log("Does not have admin access", hasAdminAccess, new ObjectId(context?.user?._id ?? ""), resourceId);
return { status: OperationResult.Error }
}

Expand All @@ -370,7 +376,7 @@ export const ResourceResolvers: Resolvers = {
})

if (!deleteResult.deletedCount || !deleteNotificationResult.deletedCount) {
console.log("Has not deleted the resource or notifications");
// console.log("Has not deleted the resource or notifications");
return { status: OperationResult.Error }
}
return { status: OperationResult.Ok };
Expand Down

0 comments on commit 2ad8212

Please sign in to comment.