Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let idFilters = {};
if (access.id || access.id_in) {
const accessControlIdsAllowed = unique([].concat(access.id, access.id_in).filter(id => id));
idFilters.id_in = intersection(accessControlIdsAllowed, uniqueIds);
} else {
idFilters.id_in = uniqueIds;
}
if (access.id_not || access.id_not_in) {
const accessControlIdsDisallowed = unique(
[].concat(access.id_not, access.id_not_in).filter(id => id)
);
idFilters.id_not_in = intersection(accessControlIdsDisallowed, uniqueIds);
}
// It's odd, but conceivable the access control specifies a single id
// the user has access to. So we have to do a check here to see if the
// ID they're requesting matches that ID.
// Nice side-effect: We can throw without having to ever query the DB.
if (
// Only some ids are allowed, and none of them have been passed in
(idFilters.id_in && idFilters.id_in.length === 0) ||
// All the passed in ids have been explicitly disallowed
(idFilters.id_not_in && idFilters.id_not_in.length === uniqueIds.length)
) {
// NOTE: We don't throw an error for multi-actions, only return an empty
// array because there's no mechanism in GraphQL to return more than one
// error for a list result.
return [];
return [];
}
const uniqueIds = unique(ids);
// Early out - the user has full access to operate on this list
if (access === true) {
return await this._itemsQuery({ where: { id_in: uniqueIds } }, { context, info });
}
let idFilters = {};
if (access.id || access.id_in) {
const accessControlIdsAllowed = unique([].concat(access.id, access.id_in).filter(id => id));
idFilters.id_in = intersection(accessControlIdsAllowed, uniqueIds);
} else {
idFilters.id_in = uniqueIds;
}
if (access.id_not || access.id_not_in) {
const accessControlIdsDisallowed = unique(
[].concat(access.id_not, access.id_not_in).filter(id => id)
);
idFilters.id_not_in = intersection(accessControlIdsDisallowed, uniqueIds);
}
// It's odd, but conceivable the access control specifies a single id
// the user has access to. So we have to do a check here to see if the
// ID they're requesting matches that ID.
// Nice side-effect: We can throw without having to ever query the DB.