Last active
January 19, 2017 18:43
-
-
Save jschlieber/ac6a8cd9d8456fdb429caf8db6f78568 to your computer and use it in GitHub Desktop.
Secure Meteor collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Mongo} from 'meteor/mongo'; | |
import createCollection from '../util/createCollection'; | |
export interface Beer { | |
_id: string, | |
name: string, | |
variety: string; | |
strength: number; | |
} | |
export const Beers: Mongo.Collection<Beer> = createCollection<Beer>('beers'); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Mongo} from 'meteor/mongo'; | |
import lockCollection from './lockCollection'; | |
export default function createCollection<DocInterface>(name: string): Mongo.Collection<DocInterface> { | |
let collection: Mongo.Collection<DocInterface> = new Mongo.Collection<DocInterface>(name); | |
return lockCollection<DocInterface>(collection); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Mongo} from 'meteor/mongo'; | |
const DENY_RULES: Mongo.AllowDenyOptions = { | |
insert: () => true, | |
update: () => true, | |
remove: () => true, | |
}; | |
export default function lockCollection<DocInterface>(collection: Mongo.Collection<DocInterface>): Mongo.Collection<DocInterface> { | |
collection.deny(DENY_RULES); | |
return collection; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Mongo} from 'meteor/mongo'; | |
const DENY_RULES = { | |
create: () => true, | |
update: () => true, | |
delete: () => true, | |
}; | |
export default function lockCollection(collection) { | |
collection.deny(DENY_RULES); | |
return collection; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Mongo} from 'meteor/mongo'; | |
const DENY_RULES: Mongo.AllowDenyOptions = { | |
create: () => true, | |
update: () => true, | |
delete: () => true, | |
}; | |
export default function lockCollection<DocInterface>(collection: Mongo.Collection<DocInterface>): Mongo.Collection<DocInterface> { | |
collection.deny(DENY_RULES); | |
return collection; | |
} |
Author
jschlieber
commented
Jan 19, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment