Merge pull request #1853 from justinr1234/check-on-count

Respect checkAccess for total resolver
This commit is contained in:
Sacha Greif 2018-01-29 10:02:16 +09:00 committed by GitHub
commit cf05aedddc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -135,10 +135,16 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
const { selector } = await collection.getParameters(terms, {}, context);
return collection.find(selector).count();
},
const docs = collection.find(selector);
}
// if collection has a checkAccess function defined, remove any documents that doesn't pass the check
if (collection.checkAccess) {
const { currentUser } = context;
return docs.fetch().filter(doc => collection.checkAccess(currentUser, doc)).length;
}
return docs.count();
},
}
};