Skip to content

Commit

Permalink
Update for SimpleSchema 2.0 and publish 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aldeed committed Aug 23, 2016
1 parent c757bf4 commit 279ebf3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aldeed:[email protected]
aldeed:schema-deny@1.0.1
aldeed:schema-deny@1.1.0
aldeed:[email protected]
[email protected]_1
[email protected]
Expand All @@ -24,7 +24,7 @@ [email protected]
[email protected]
[email protected]
[email protected]
local-test:aldeed:schema-deny@1.0.1
local-test:aldeed:schema-deny@1.1.0
[email protected]
mdg:[email protected]
[email protected]
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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

Expand Down
21 changes: 15 additions & 6 deletions lib/deny.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
});
});
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -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"
});

Expand Down

0 comments on commit 279ebf3

Please sign in to comment.