mirror of
https://github.com/vale981/grapher
synced 2025-03-06 01:51:38 -05:00
56 lines
No EOL
1.5 KiB
JavaScript
56 lines
No EOL
1.5 KiB
JavaScript
import createGraph from '../query/lib/createGraph.js';
|
|
import recursiveCompose from '../query/lib/recursiveCompose.js';
|
|
import recursiveFetch from '../query/lib/recursiveFetch.js';
|
|
|
|
export default class Exposure {
|
|
constructor(collection, firewall) {
|
|
this.collection = collection;
|
|
this.firewall = firewall;
|
|
this.name = `exposure_${collection._name}`;
|
|
|
|
this.initSecurity();
|
|
this.initMethod();
|
|
this.initPublication();
|
|
}
|
|
|
|
initPublication() {
|
|
const collection = this.collection;
|
|
|
|
Meteor.publishComposite(this.name, function (body) {
|
|
return recursiveCompose(
|
|
createGraph(collection, body),
|
|
this.userId
|
|
);
|
|
});
|
|
}
|
|
|
|
initMethod() {
|
|
const collection = this.collection;
|
|
|
|
Meteor.methods({
|
|
[this.name](body) {
|
|
return recursiveFetch(
|
|
createGraph(collection, body),
|
|
null,
|
|
this.userId
|
|
);
|
|
}
|
|
})
|
|
}
|
|
|
|
initSecurity() {
|
|
const collection = this.collection;
|
|
const firewall = this.firewall;
|
|
|
|
if (firewall) {
|
|
firewall.bind(collection);
|
|
collection.findSecure = (filters, options, userId) => {
|
|
if (userId !== undefined) {
|
|
firewall(filters, options, userId);
|
|
}
|
|
|
|
return collection.find(filters, options);
|
|
}
|
|
}
|
|
}
|
|
} |