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,
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
editable: true,
|
|
|
|
omit: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
autoform: {
|
|
|
|
editable: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
type: [String], // XXX
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
downvotes: {
|
|
|
|
type: Number,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
downvoters: {
|
|
|
|
type: [String], // XXX
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
author: {
|
|
|
|
type: String,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
inactive: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
postId: {
|
|
|
|
type: String, // XXX
|
|
|
|
optional: true,
|
|
|
|
autoform: {
|
|
|
|
editable: true,
|
|
|
|
omit: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
userId: {
|
|
|
|
type: String, // XXX
|
|
|
|
optional: true
|
|
|
|
},
|
|
|
|
isDeleted: {
|
|
|
|
type: Boolean,
|
|
|
|
optional: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-27 09:55:29 +09:00
|
|
|
i18n.internationalizeSchema(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-27 09:55:29 +09:00
|
|
|
Comments.attachSchema(Telescope.schemas.comments);
|
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) {
|
|
|
|
if(Users.isAdminById(userId))
|
|
|
|
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
|
|
|
|
});
|