diff --git a/.versions b/.versions index 80b94d0..8f5a8bf 100644 --- a/.versions +++ b/.versions @@ -1,5 +1,5 @@ aldeed:collection2-core@1.0.0 -aldeed:schema-deny@1.0.1 +aldeed:schema-deny@1.1.0 aldeed:simple-schema@1.5.3 babel-compiler@5.8.24_1 babel-runtime@0.1.4 @@ -24,7 +24,7 @@ html-tools@1.0.5 htmljs@1.0.5 id-map@1.0.4 jquery@1.11.4 -local-test:aldeed:schema-deny@1.0.1 +local-test:aldeed:schema-deny@1.1.0 logging@1.0.8 mdg:validation-error@0.2.0 meteor@1.1.10 diff --git a/CHANGELOG.md b/CHANGELOG.md index 646c6f6..49422ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +# 1.1.0 + +Support for SimpleSchema 2.0 + # 1.0.0 Initial release. Originally included in the aldeed:collection2 package. \ No newline at end of file diff --git a/LICENSE b/LICENSE index 9eae9af..70c792f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Eric Dobbertin +Copyright (c) 2015-2016 Eric Dobbertin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index 8c1a2ea..5209d96 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ $ meteor add aldeed:schema-deny If you set `denyUpdate: true`, any collection update that modifies the field will fail. For instance: ```js -var PostSchema = new SimpleSchema({ +const postSchema = new SimpleSchema({ title: { type: String }, @@ -31,13 +31,13 @@ var PostSchema = new SimpleSchema({ } }); -Posts = new Mongo.Collection('posts'); -Posts.attachSchema(PostSchema); +const Posts = new Mongo.Collection('posts'); +Posts.attachSchema(postSchema); -var postId = Posts.insert({title: 'Hello', content: 'World', createdAt: new Date()}); +const postId = Posts.insert({title: 'Hello', content: 'World', createdAt: new Date()}); ``` -The `denyInsert` option works the same way, but for inserts. If you set `denyInsert` to true, you will need to set `optional: true` as well. +The `denyInsert` option works the same way, but for inserts. If you set `denyInsert` to true, you will need to set `optional: true` as well. ## Contributing diff --git a/lib/deny.js b/lib/deny.js index 6de463e..773b87a 100644 --- a/lib/deny.js +++ b/lib/deny.js @@ -5,18 +5,27 @@ SimpleSchema.extendOptions({ }); // Define validation error messages -SimpleSchema.messages({ - insertNotAllowed: "[label] cannot be set during an insert", - updateNotAllowed: "[label] cannot be set during an update" -}); +if (!SimpleSchema.version || SimpleSchema.version < 2) { + SimpleSchema.messages({ + insertNotAllowed: '[label] cannot be set during an insert', + updateNotAllowed: '[label] cannot be set during an update' + }); +} Collection2.on('schema.attached', function (collection, ss) { + if (ss.version >= 2) { + ss.messageBox.messages({ + insertNotAllowed: '{{label}} cannot be set during an insert', + updateNotAllowed: '{{label}} cannot be set during an update' + }); + } + ss.addValidator(function() { if (!this.isSet) return; var def = this.definition; - if (def.denyInsert && this.isInsert) return "insertNotAllowed"; - if (def.denyUpdate && (this.isUpdate || this.isUpsert)) return "updateNotAllowed"; + if (def.denyInsert && this.isInsert) return 'insertNotAllowed'; + if (def.denyUpdate && (this.isUpdate || this.isUpsert)) return 'updateNotAllowed'; }); }); diff --git a/package.js b/package.js index 8aaaf8f..df66b77 100644 --- a/package.js +++ b/package.js @@ -1,7 +1,7 @@ Package.describe({ name: "aldeed:schema-deny", summary: "Deny inserting or updating certain properties through schema options", - version: "1.0.1", + version: "1.1.0", git: "https://github.com/aldeed/meteor-schema-deny.git" });