2015-04-24 09:28:50 +09:00
|
|
|
/**
|
|
|
|
* The global namespace for Comments.
|
|
|
|
* @namespace Comments
|
|
|
|
*/
|
|
|
|
Comments = new Mongo.Collection("comments");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comments schema
|
|
|
|
* @type {SimpleSchema}
|
|
|
|
*/
|
2015-04-27 09:55:29 +09:00
|
|
|
Telescope.schemas.comments = new SimpleSchema({
|
2015-04-22 07:50:26 +09:00
|
|
|
_id: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
parentCommentId: {
|
|
|
|
type: String,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:26 +09:00
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
type: Date,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
postedAt: { // for now, comments are always created and posted at the same time
|
|
|
|
type: Date,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
body: {
|
|
|
|
type: String,
|
2015-04-28 09:44:43 +09:00
|
|
|
editableBy: ["owner", "admin"],
|
|
|
|
autoform: {
|
|
|
|
rows: 5
|
|
|
|
}
|
2015-04-22 07:50:26 +09:00
|
|
|
},
|
|
|
|
htmlBody: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
baseScore: {
|
|
|
|
type: Number,
|
|
|
|
decimal: true,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
score: {
|
|
|
|
type: Number,
|
|
|
|
decimal: true,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
upvotes: {
|
|
|
|
type: Number,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
upvoters: {
|
2015-04-27 17:15:16 +09:00
|
|
|
type: [String],
|
2015-04-22 07:50:26 +09:00
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
downvotes: {
|
2015-04-27 17:15:16 +09:00
|
|
|
type: Number,
|
|
|
|
optional: true
|
2015-04-22 07:50:26 +09:00
|
|
|
},
|
|
|
|
downvoters: {
|
2015-04-27 17:15:16 +09:00
|
|
|
type: [String],
|
2015-04-22 07:50:26 +09:00
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
author: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
inactive: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
postId: {
|
2015-04-28 09:44:43 +09:00
|
|
|
type: String,
|
2015-04-27 17:15:16 +09:00
|
|
|
optional: true
|
2015-04-22 07:50:26 +09:00
|
|
|
},
|
|
|
|
userId: {
|
2015-04-28 09:44:43 +09:00
|
|
|
type: String,
|
2015-04-22 07:50:26 +09:00
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
isDeleted: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-28 09:44:43 +09:00
|
|
|
Meteor.startup(function () {
|
|
|
|
// do this on Meteor.startup to make sure Meteor.user() is defined and we're able to set permissions
|
|
|
|
Telescope.schemas.comments.internationalize().setPermissions();
|
|
|
|
Comments.attachSchema(Telescope.schemas.comments);
|
|
|
|
});
|
2015-04-25 13:03:04 +09:00
|
|
|
|
2015-04-24 09:28:50 +09:00
|
|
|
/**
|
|
|
|
* Attach schema to Posts collection
|
|
|
|
*/
|
2015-04-22 07:50:26 +09:00
|
|
|
|
|
|
|
|
2015-04-24 09:28:50 +09:00
|
|
|
// Note: is the allow/deny code still needed?
|
2015-04-22 07:50:26 +09:00
|
|
|
|
|
|
|
Comments.deny({
|
|
|
|
update: function(userId, post, fieldNames) {
|
2015-04-27 17:15:16 +09:00
|
|
|
if(Users.is.adminById(userId))
|
2015-04-22 07:50:26 +09:00
|
|
|
return false;
|
|
|
|
// deny the update if it contains something other than the following fields
|
|
|
|
return (_.without(fieldNames, 'body').length > 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Comments.allow({
|
|
|
|
update: Users.can.editById,
|
|
|
|
remove: Users.can.editById
|
|
|
|
});
|