Skip to content

Commit

Permalink
Merge pull request #8 from Allotr/HotFIx-RaceConditions
Browse files Browse the repository at this point in the history
fix: Add admin guard to edit resource
  • Loading branch information
rafaelpernil2 authored Sep 24, 2021
2 parents 3a7b835 + 2ad8212 commit 731ecda
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 731ecda

Please sign in to comment.